Managed attributes

Managed attributes define a special "flag" attribute that distinguishes used and unused elements: the removal of an element only flags this element unused in constant time.

Note

There is no resizeattr! on managed attributes, because there is no canonical used state for resizing.

Note

Managed attributes provide the iused state for handles h . However, this is not checked (e.g., by an assertion) on attribute access like attrs(ma, :name)[h]!

Provide an assetion in upstream code using ma!

Cached state

Note that managed attributes "cache" part of their state for efficiency (e.g., the number of used elements). Consequently, manages attributes are realized as data structures (i.e., as mutable struct). The particular implementation is left to the user. This library defines a simple interface and a default implementation that makes assumptions of the managed attribute type.

Cloning

The clone and Base.similar methods create an identical copy (using clone on attributes) or an empty set of attributes of same type (and enabled & initial value state).

These methods also copy or initialize the cached state and should be provided by the user.

Example

The data structure VAttr contains managed attributes attrs and the cached state n_used, which counts the number of used elements and which is updated on setused! or setunused!.

abstract type AbstractVAttr <: ManagedAttributes{VHnd}; end

mutable struct VAttr{P} <: AbstractVAttr
    attrs::P
    n_used::Int
    VAttr{P}(attrs::P, n = 0) where {P} = new(attrs, n)
end

Base.similar(va::VAttr{P}) where {P} =
    VAttr{P}(createattributes(attrspecs(attrs(va)); htyp=VHnd))

clone(va::VAttr{P}) where {P} = Vattr{P}(clone(va.attrs), va.n_used)