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.compactapplyMethod
manew, 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!.

Note

Here, plan comes from compactplanforward such that the rearrangement in manew is stable.

Note

For copying there is no benefit from an unstable arrangement by compactplanbackward or compactplan with policy :stable.

See also compactapply!, compactplanforward, compactplan

source
PMeshAttributes.compactinverseFunction
ridx = 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).

Note

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!

source
PMeshAttributes.compactplanFunction
plan = 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), and
  • CompactFast() 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

source
PMeshAttributes.compactplanbackwardMethod
n, 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

source
PMeshAttributes.compactplanforwardMethod
n, 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

source