Skip to main content

Keys

Struct Keys 

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

The names one collection has interned, and the ids it gave them.

§Why nothing is ever removed

An id is the row index the name sits at, which costs the table nothing at all: no second array from id to row, no free list, no generation counter. It holds only while the rows do not move, and Elements moves its last row into the hole when something is taken out, so a removal here would silently repoint every document that used the moved name.

Never removing is the right answer rather than a limitation being tolerated. A field name that no document uses any more costs its bytes once and two bytes of nothing in the row array, and the alternative is either an indirection on every lookup forever or a scan of the whole collection to find out whether a name is still wanted. The table is capped at KEYS_MAX names, so the worst case is bounded and small.

Implementations§

Source§

impl Keys

Source

pub fn new() -> Keys

An empty table that has not allocated anything yet.

Source

pub fn with_capacity(n: usize) -> Keys

An empty table with room for n names already taken.

Source

pub fn intern(&mut self, name: &[u8]) -> Option<u16>

The id of name, giving it one if it does not have one yet.

None means the table is full or the name is longer than a name may be, and in both cases the caller writes the document with its keys as bytes instead. That is always safe, because the interned flag is per container and not per collection, so a collection can hold both kinds at once and everything already written stays readable.

Source

pub fn id(&self, name: &[u8]) -> Option<u16>

The id name already has, without giving it one.

This is the read path: a lookup by name against an interned document resolves the name here once and then searches the document by id.

Source

pub fn name(&self, id: u16) -> Option<&[u8]>

The name behind an id.

Source

pub fn len(&self) -> usize

How many names are interned.

Source

pub fn is_empty(&self) -> bool

Whether nothing has been interned yet.

Source

pub fn is_full(&self) -> bool

Whether the next new name would be refused.

Source

pub fn iter(&self) -> impl Iterator<Item = (&[u8], u16)>

Every name and its id, in id order.

Source

pub fn memory_bytes(&self) -> usize

What the table costs.

Trait Implementations§

Source§

impl Clone for Keys

Source§

fn clone(&self) -> Keys

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 Keys

Source§

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

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

impl Default for Keys

Source§

fn default() -> Keys

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

Auto Trait Implementations§

§

impl Freeze for Keys

§

impl RefUnwindSafe for Keys

§

impl Send for Keys

§

impl Sync for Keys

§

impl Unpin for Keys

§

impl UnsafeUnpin for Keys

§

impl UnwindSafe for Keys

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.