pub enum KeyRep {
Default(Vec<Vec<u8>>),
Compact {
buf: Vec<u8>,
slot_width: usize,
lengths: Vec<u16>,
},
}Expand description
T-2: node-level key array — INKeyRep.{Default,MaxKeySize} (INKeyRep.java).
The per-slot key that used to live in BinEntry/InEntry as a Vec<u8>
(24-byte header + a separate heap allocation per key) is hoisted here as a
node-level rep. When every (post-prefix) key in the node is <=
TREE_COMPACT_MAX_KEY_LENGTH (default 16) the keys pack into ONE
fixed-width byte buffer (MaxKeySize): slot_width bytes per slot, with a
parallel lengths vector tracking the actual length of each key. A key
longer than the threshold inflates the whole node to the Default rep
(one Vec<u8> per slot), matching JE’s Default.compact /
MaxKeySize.expandToDefaultRep.
As in JE, this stores the UNPREFIXED suffix (key prefixing strips the common prefix first), so the compact rep is the smaller post-prefix bytes.
Variants§
Default(Vec<Vec<u8>>)
INKeyRep.Default — one owned key per slot (any length).
Compact
INKeyRep.MaxKeySize — all keys packed into one fixed-width buffer.
buf.len() == slot_width * lengths.len(); slot i occupies
buf[i*slot_width .. i*slot_width + lengths[i]].
Implementations§
Source§impl KeyRep
impl KeyRep
Sourcepub fn from_keys(keys: Vec<Vec<u8>>) -> Self
pub fn from_keys(keys: Vec<Vec<u8>>) -> Self
Build a Default rep from owned keys (callers may later compact).
pub fn is_empty(&self) -> bool
Sourcepub fn get(&self, idx: usize) -> &[u8] ⓘ
pub fn get(&self, idx: usize) -> &[u8] ⓘ
INKeyRep.get(idx) / getKey — borrow the (post-prefix) key at slot
idx without allocating.
Sourcepub fn set(&mut self, idx: usize, key: Vec<u8>)
pub fn set(&mut self, idx: usize, key: Vec<u8>)
Set the key at slot idx. A key longer than a Compact rep’s
slot_width inflates the rep to Default first
(MaxKeySize.expandToDefaultRep).
Sourcepub fn insert(&mut self, idx: usize, key: Vec<u8>)
pub fn insert(&mut self, idx: usize, key: Vec<u8>)
Insert a key at slot idx, shifting later slots up (mirrors
Vec::insert + INArrayRep.copy).
Sourcepub fn remove(&mut self, idx: usize) -> Vec<u8> ⓘ
pub fn remove(&mut self, idx: usize) -> Vec<u8> ⓘ
Remove the key at slot idx, shifting later slots down.
Sourcepub fn compact(&mut self, compact_max_key_length: i32)
pub fn compact(&mut self, compact_max_key_length: i32)
INKeyRep.Default.compact(parent) (INKeyRep.java) — if every key in a
Default rep fits compact_max_key_length, pack them into a
MaxKeySize (Compact) rep. compact_max_key_length <= 0 disables
compaction. No-op when already Compact.
Sourcepub fn is_compact(&self) -> bool
pub fn is_compact(&self) -> bool
True when key-byte memory is accounted for inside this rep (Compact),
vs per-slot Vec allocations (Default).
INKeyRep.accountsForKeyByteMemUsage.
Sourcepub fn memory_size(&self) -> usize
pub fn memory_size(&self) -> usize
Heap bytes of the rep itself (INKeyRep.calculateMemorySize +
key-byte accounting). For Default this is the Vec<Vec<u8>> header
plus each key’s heap allocation; for Compact it is the single buffer
plus the lengths vector.