Skip to main content

KeyRep

Enum KeyRep 

Source
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]].

Fields

§buf: Vec<u8>
§slot_width: usize
§lengths: Vec<u16>

Implementations§

Source§

impl KeyRep

Source

pub fn new() -> Self

An empty Default rep.

Source

pub fn from_keys(keys: Vec<Vec<u8>>) -> Self

Build a Default rep from owned keys (callers may later compact).

Source

pub fn len(&self) -> usize

Number of slots.

Source

pub fn is_empty(&self) -> bool

Source

pub fn get(&self, idx: usize) -> &[u8]

INKeyRep.get(idx) / getKey — borrow the (post-prefix) key at slot idx without allocating.

Source

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

Source

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

Source

pub fn remove(&mut self, idx: usize) -> Vec<u8>

Remove the key at slot idx, shifting later slots down.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for KeyRep

Source§

fn clone(&self) -> KeyRep

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyRep

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for KeyRep

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.