pub struct Unit(/* private fields */);Expand description
An unit represents an element in a double-array.
Implementations§
Source§impl Unit
Unit represents one node of a double array trie. The bit width of each node is 32-bits.
impl Unit
Unit represents one node of a double array trie. The bit width of each node is 32-bits.
The bit layout of a non-leaf node:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +—————+-+-+—————————————–+-+ | LABEL |H|E| OFFSET |I| +—————+-+-+—————————————–+-+
LABEL 8-bits value that represents a label of the double array node. HAS_LEAF (H) 1-bit flag that indicates whether the node has leaf nodes or not. EXTEND_OFFSET (E) 1-bit flag that indicates whether the offset should be extended or not. OFFSET 21-bits value that represents an offset of the double array node. IS_LEAF (I) 1-bit flag that indicates whether the node is a leaf node or not. This flag is always 0 in this case.
The bit layout of a leaf node:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +———————————————————––+-+ | VALUE |I| +———————————————————––+-+
VALUE 31-bits value that represents a value of the double array node. IS_LEAF (I) 1-bit flag that indicates whether the node is a leaf node or not. This flag is always 1 in this case.
Sourcepub fn has_leaf(&self) -> bool
pub fn has_leaf(&self) -> bool
Returns true if the unit have a leaf as a child unit. Otherwise, returns false.
Sourcepub fn is_leaf(&self) -> bool
pub fn is_leaf(&self) -> bool
Returns true if the unit is a leaf which have a value. Otherwise, return false.
Sourcepub fn label(&self) -> u32
pub fn label(&self) -> u32
Returns a label (<= 255) if the unit is not a leaf. Otherwise, returns an integer value greater than 255.
Sourcepub fn offset(&self) -> u32
pub fn offset(&self) -> u32
Returns an offset value within the unit. If the offset extension flag is true, returns the offset multiplied by 256.
Sourcepub fn set_offset(&mut self, offset: u32)
pub fn set_offset(&mut self, offset: u32)
Sets an offset to the unit. offset should be a value less than or equal to 29 bits. If the
offset is greater than 21 bits, sets the offset extension flag and the offset without
lower 8 bits (then, lower 8 bits of the given offset should be 0).
Sourcepub fn set_has_leaf(&mut self, has_leaf: bool)
pub fn set_has_leaf(&mut self, has_leaf: bool)
Sets a has_leaf flag to the unit.