Compact storage
In order to maintain a storage-efficient representation of managed attributes, their data can be compactly rearranged such that there are no "gaps" with unused elements. This rearrangement can be performed in-place reusing the vectors or out-of-place by copying vectors. Two in-place algorithms are provided: a stable algorithm that preserves the relative order of elements and a generally faster non-stable algorithm
The rearrangement consists of two phases: first, the "analysis" stage compactplan
generates a plan that is then executed by compactapply!
. In the following, plan
refers to a data structure that represents the rearrangement.
PMeshAttributes.compactapply!
— Functionidx = compactapply!(ma::ManagedAttributes, plan) :: Vector{Int}
Execute plan
from compactplan
to make ma
contiguous, i.e., to remove unused entries ("garbage collection").
The returned array idx
maps "new" indices/ handles in ma
to "old" ones: iold = idx[inew]
. The inverse map is obtained from compactinverse
.
See also compactplan
, compactinverse
PMeshAttributes.compactapply
— Methodmanew, idx = compactapply(ma::ManagedAttributes, plan)
Apply plan
to copy ma
and create contiguous manew
. The returned array idx
maps "new" indices/ handles to "old" ons as for compactapply!
.
Here, plan
comes from compactplanforward
such that the rearrangement in manew
is stable.
For copying there is no benefit from an unstable arrangement by compactplanbackward
or compactplan
with policy :stable
.
See also compactapply!
, compactplanforward
, compactplan
PMeshAttributes.compactinverse
— Functionridx = compactinverse(idx[, nmax]
Compute inverse map of idx
from compactapply!
: inew = ridx[iold]
.
The optional nmax
argument determines the length of ridx
. It should be either n_total
before compactapply!
or the largest index in idx
. The latter is the default choice nmax = maximum(idx)
.
The inverse ridx
is a partial map, it provides valid indices inew
only for previously valid iold
!
If iold
was not valid, it is is either out of bounds for ridx
or ridx[iold] == 0
.
See also compactapply!
PMeshAttributes.compactplan
— Functionplan = compactplan(ma[, CompactStable()]) # default choice: stable
plan = compactplan(ma, CompactFast())
Compute plan
for moving used items in ma
such that the sequence becomes contiguous`.
There are two options for generating the plan
CompactStable()
maintains the relative order of elements (and their new indices/ handles) but is slower (requires more moves), andCompactFast()
is not stable, i.e., moves elements into any free slots, but is generally faster (requires less moves)
The plan
is executed by compactapply!
.
See also compactapply!
, iscontiguous
PMeshAttributes.compactplanbackward
— Methodn, plan = compactplanbackward(ma::ManagedAttributes)
Compute plan idx
for moving the n
used items in ma
such that the sequence becomes contiguous`.
The plan processes from both ends of the sequence and "fills" each unused slot from the front by moving a used item from the back.
- This process is not stable, i.e., the order of elements (or their indices/handles) will change.
- This plan generally moves less elements than the one from
compactplanforward
.
The plan is executed by compactapply!
.
See also compactapply!
, compactplanforward
, iscontiguous
PMeshAttributes.compactplanforward
— Methodn, plan = compactplanforward(ma::ManagedAttributes)
Compute plan
for moving the n
used items in ma
such that the sequence becomes contiguous`.
The plan
processes from front to back and "fills" each unused slot by moving the next used item there.
- This process is stable, i.e., the order of elements (or their indices/handles) does not change.
- This plan generally moves more elements than the one from
compactplanbackward
.
The plan
is executed by compactapply!
.
See also compactapply!
, compactplanbackward
, iscontiguous
PMeshAttributes.CompactPlanBackward
— TypePlan for non-stable rearrangement of attributes.
See also compactplanbackward
, compactplan
,
PMeshAttributes.CompactPlanForward
— TypePlan for stable rearrangement of attributes.
See also compactplanforward
, compactplan
,