struct

Pf::UPath32

Inherits Enumerable / Struct / Value / Object

An immutable vector of UInt32s (here called indices) with tree path- specific optimizations.

path = Pf::UPath32[100, 20]
path.append(3) # => UPath32[100, 20, 3]
path.append(7) # => UPath32[100, 20, 7]
path           # => UPath32[100, 20]

Constructors

[]

Constructs an empty path.

Source
[](*ns : UInt32) : UPath32
Source
end

Returns the sentinel End path.

Source

Instance methods

==(other : UPath32) : Bool
Source
[](index : Int) : UInt32

See Indexable#[](index : Int).

Source
[]?(index : Int) : UInt32 | Nil

See Indexable#[]?(index : Int).

Source
append(step : UInt32) : UPath32

Inserts step at the back of this path. Returns the modified copy.

Source
dense?

Returns true if the underlying representation of this path is dense.

As an optimization, we store small paths inline, packing them in 57 bits plus 4-bit size.

The shape of the "path gamut" for this representation is currently 14-9-8-6-4-4-4-4. Paths that are outside of this "gamut" are transferred to (or constructed on) the GC heap (sparse?).

  • The first index receives a larger number of bits, because indices near the root are usually large.
  • Successive indices receive a smaller number of bits, because nodes closer to the root are expected to be large, but smaller than their predecessor.
Source
each

Yields each index in this path in front-to-back order.

Source
end?

Returns true if this path is the sentinel End path.

Sentinel End marker useful in traversals that must distinguish entering the root from reentering it at the end of traversal.

Source
hash(hasher)

See Object#hash(hasher)

Source
index?

Returns true if the underlying representation of this path is an index.

Index optimizes singleton UPath32's, which can be encountered when one uses UPath32 as an index, or when it happens to be used as one (e.g. skipping over root terms during DFS or BFS).

Source
inspect(io)
Source
last

Returns the last index in this path. Raises IndexError if this path is empty.

Source
last?

Returns the last index in this path, or nil if this path is empty.

Source
prior

Returns the part of this path before the last index. If this path is empty, returns an empty path.

Source
size

Returns the number of indices in this path as an index within zero or positive Int32 bounds.

Source
sparse?

Returns true if the underlying representation of this path is sparse.

Sparse paths are stored on the GC heap.

Source
usize

Returns the number of indices in this path as an index within UInt32 bounds.

Source