pub struct Strings { /* private fields */ }Expand description
The string table.
Implementations§
Source§impl Strings
impl Strings
Sourcepub fn new(order: StringOrder) -> Self
pub fn new(order: StringOrder) -> Self
An empty table with the given order.
Sourcepub fn order(&self) -> StringOrder
pub fn order(&self) -> StringOrder
The order strings compare in.
Sourcepub fn preload<'a>(
&self,
texts: impl IntoIterator<Item = &'a str>,
) -> Result<(), Error>
pub fn preload<'a>( &self, texts: impl IntoIterator<Item = &'a str>, ) -> Result<(), Error>
Interns texts in the given order, so that under
StringOrder::Token they compare in that order. Call it before
anything else is interned: TLC’s tokens are assigned in its startup
encounter order (configuration, built-ins, lexer tokens, semantic
names), and dive-model’s binder records that order.
§Errors
texts repeats a string, or the table already holds strings that are
not a prefix of texts, so the tokens would not be TLC’s; or more
than u32::MAX strings.
Sourcepub fn seal(&self)
pub fn seal(&self)
Refuses every later new string: under StringOrder::Token a string
TLC first meets during the search gets a token that depends on what
TLC evaluated before it, so after Strings::preload the run seals
the table rather than guess the order.
Sourcepub fn is_sealed(&self) -> bool
pub fn is_sealed(&self) -> bool
Whether this table refuses every name absent from its current domain.
Sourcepub fn lookup(&self, text: &str) -> Option<u32>
pub fn lookup(&self, text: &str) -> Option<u32>
The id of text if the table already holds it, never assigning one.
Sourcepub fn intern(&self, text: &str) -> Result<u32, Error>
pub fn intern(&self, text: &str) -> Result<u32, Error>
The id of text, assigning one if it is new.
§Errors
More than u32::MAX strings; a new string after Strings::seal
(unsupported).
Sourcepub fn texts_from(&self, start: usize) -> Vec<Arc<str>>
pub fn texts_from(&self, start: usize) -> Vec<Arc<str>>
The texts of the ids from start on, in id order, under one read
lock: a worker’s heap copies them once instead of locking the table
on every comparison (crate::heap::Heap::cmp).
Sourcepub fn cmp(&self, a: u32, b: u32) -> Ordering
pub fn cmp(&self, a: u32, b: u32) -> Ordering
Compares two ids in the table’s order: by text, or by token.
Sourcepub fn ranks(&self) -> Arc<[u32]> ⓘ
pub fn ranks(&self) -> Arc<[u32]> ⓘ
The dense rank of each id in the table’s order, for the ids below
the result’s length: comparing two ranks compares the two strings
as Strings::cmp does.
Ranks are rebuilt here, not on every intern, so the ids interned since the last rebuild may lie past the result; the caller compares those by text. Interning shifts ranks but never reorders two ids that were ranked together, so an earlier result still orders every pair it covers.
Sourcepub fn longest_text_bytes(&self) -> usize
pub fn longest_text_bytes(&self) -> usize
The UTF-8 length of the longest text in the table so far. The table is append-only, so every id it has issued names a text at most this long: it bounds the work of one scan over any one current string.
Sourcepub fn memory_usage(&self) -> StringsMemory
pub fn memory_usage(&self) -> StringsMemory
Measures known dynamic storage without counting shared text twice. The index’s opaque bucket allocation is reported as logical capacity, rather than inventing a physical byte count from that capacity.