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
impl Keys
Sourcepub fn with_capacity(n: usize) -> Keys
pub fn with_capacity(n: usize) -> Keys
An empty table with room for n names already taken.
Sourcepub fn intern(&mut self, name: &[u8]) -> Option<u16>
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.
Sourcepub fn id(&self, name: &[u8]) -> Option<u16>
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.
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
What the table costs.