struct Pf::UPath32

Overview

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]

Included Modules

Defined in:

permafrost/upath32.cr

Constructors

Instance Method Summary

Instance methods inherited from module Enumerable(UInt32)

to_pf_bidi to_pf_bidi, to_pf_map(& : T -> Tuple(K, V)) : Pf::Map(K, V) forall K, V
to_pf_map
to_pf_map
, to_pf_set : Pf::Set(T) to_pf_set, to_pf_uset32 : Pf::USet32 to_pf_uset32

Constructor Detail

def self.[] : UPath32 #

Constructs an empty path.


[View source]
def self.[](*ns : UInt32) : UPath32 #

[View source]
def self.end : UPath32 #

Returns the sentinel End path.


[View source]

Instance Method Detail

def ==(other : UPath32) : Bool #

[View source]
def [](index : Int) : UInt32 #

See Indexable#[](index : Int).


[View source]
def []?(index : Int) : UInt32 | Nil #

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


[View source]
def append(step : UInt32) : UPath32 #

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


[View source]
def dense? : Bool #

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.

[View source]
def each(& : UInt32 -> ) #

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


[View source]
def end? : Bool #

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.


[View source]
def hash(hasher) #
Description copied from struct Struct

See Object#hash(hasher)


[View source]
def index? : Bool #

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).


[View source]
def inspect(io) #

[View source]
def last : UInt32 #

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


[View source]
def last? : UInt32 | Nil #

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


[View source]
def prior : UPath32 #

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


[View source]
def size : Int32 #

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


[View source]
def sparse? : Bool #

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

Sparse paths are stored on the GC heap.


[View source]
def usize : UInt32 #

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


[View source]