Skip to main content

Module nib_trie

Module nib_trie 

Source
Expand description

Nib Trie — a fixed-fanout radix trie indexed by 2-bit words (nibs).

Each node has 4 child slots (one per 2-bit value 0–3), addressed by direct indexing. This trades space for simplicity and lookup speed compared to a binary trie, while using less space per node than a 16-way nibble trie.

§No Stacking

Unlike NibbleTrie, NibTrie does not support vnode stacking. Each physical node holds exactly one logical trie node. The occupancy and leaf_mask fields are u8 (4 bits used) rather than u16 (16 bits).

§Terminal Nodes

Keys that are prefixes of other keys are represented by a terminal flag on the node where the key ends, rather than a null-byte leaf child. This eliminates null terminators, allows 0x00 bytes in keys, and makes get() accept plain &[u8].

§Key Index Encoding

Real keys start at index 1 (index 0 is the dummy entry). The sentinel PTR::max_value() marks empty slots in children[].

§Nib Addressing

Each byte contains 4 nib positions:

  • nib 0: bits 7–6 of byte 0
  • nib 1: bits 5–4 of byte 0
  • nib 2: bits 3–2 of byte 0
  • nib 3: bits 1–0 of byte 0
  • nib 4: bits 7–6 of byte 1
  • etc.

Total nib count for a key of length L is L * 4.

Structs§

Cursor
CursorMut
Mutable counterpart to Cursor: a tree-walk iterator that lends out &mut T borrows over the stored values, in sorted (DFS) key order.
NibTrie