LexicographicKey

Struct LexicographicKey 

Source
pub struct LexicographicKey { /* private fields */ }
Expand description

A vector of bytes representing a lexicographically sortable set of keys. Each key is separated by a byte 0x00 to allow partial index searches.

If I have an index (id: u8, created_at: u8, name: String ) and i want to filter by { id = 0, created_at = gt(1) && lt(99) }

I need to sort by 00000000100000000..0000000063000000. But i need to include all keys that are longer than the provided slice. e.g. 0000000050000000a3eb398e should be included.

To achieve this we need a separator that is a fixed value that we can use for comparison. If we choose this byte as 0x00, then we can suffix the upper bound of our sort queries with 0x01 to include all longer keys.

To visualize this better consider the following hex example:

We want values between 0001 and 00ff. We also want all longer hex values. We compute our bounds:

lower: 0001 upper: 00ff01

Now the value 00ee00aabbcc sorts within this range

This strategy adds ~1 byte of overhead per field (0 bytes for indices with 1 field).

Implementations§

Source§

impl LexicographicKey

Source

pub fn append_key_slice(&mut self, slice: &[u8])

Append a slice representing a lexicographically sortable key.

Source

pub fn append_upper_inclusive_byte(&mut self)

Append a 0x01 byte that will sort all longer keys before this key.

Source

pub fn append_separator(&mut self)

Source

pub fn is_empty(&self) -> bool

Source

pub fn take(&mut self) -> Vec<u8>

Source

pub fn as_slice(&self) -> &[u8]

Source

pub fn to_vec(&self) -> Vec<u8>

Trait Implementations§

Source§

impl Clone for LexicographicKey

Source§

fn clone(&self) -> LexicographicKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for LexicographicKey

Source§

fn default() -> LexicographicKey

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.