class Pf::Core::Node(T)

Overview

Represents a trie node.

Instances of T are stored inline. Meaning if T is a large struct lots and lots of bytes are going to be copied, mostly unnecessarily. Clients will probably want to catch large value Ts and wrap them in a pointer. The notion of "large" depends on the client. It could be an interface or could be a sizeof threshold.

Defined in:

permafrost/core/node.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(items : Pf::Core::Sparse32(T) = Sparse32(T).new, children : Pf::Core::Sparse32(Pf::Core::Node(T)) = Sparse32(Node(T)).new, itemsof : UInt32 = AUTHOR_NONE, childrenof : UInt32 = AUTHOR_NONE) #

[View source]

Instance Method Detail

def add(probe : IProbeAdd(T)) : Tuple(Bool, Node(T)) #

Updates or inserts the stored value accepted by probe.

Returns a tuple where the first element is a boolean indicating whether the amount of elements in the trie increased by one, and the second element is the modified version of self.

If probe wishes mutation, the second element is exactly self (and the first element still indicates whether the size increased).

If no changes were made (the stored value is the same as that of probe) the second element is also exactly self (and the first element is false).


[View source]
def delete(probe : IProbeDelete(T)) : Tuple(Bool, Node(T)) #

Removes the stored value accepted by probe. Returns a tuple where the first element is a boolean indicating whether the amount of elements in the trie decreased by one, and the second element is the modified version of self.

If probe wishes mutation, the second element is exactly self. If no changes were made (nothing was removed), the second element is also exactly self.


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

Yields each item from this node and from all child nodes.


[View source]
def empty? : Bool #

Returns true if this node holds no items and points to no children.


[View source]
def fetch?(probe : IProbeFetch(T)) : Tuple(T) | Nil #

Retrieves the stored value that is accepted by probe. Returns the first stored value accepted by probe, or nil if probe accepted no values.

The returned value is wrapped in a tuple to differentiate between nil as value and nil as absence.


[View source]