Skip to main content

Strings

Struct Strings 

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

The string table.

Implementations§

Source§

impl Strings

Source

pub fn new(order: StringOrder) -> Self

An empty table with the given order.

Source

pub fn order(&self) -> StringOrder

The order strings compare in.

Source

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.

Source

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.

Source

pub fn is_sealed(&self) -> bool

Whether this table refuses every name absent from its current domain.

Source

pub fn lookup(&self, text: &str) -> Option<u32>

The id of text if the table already holds it, never assigning one.

Source

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

Source

pub fn text(&self, id: u32) -> Option<Arc<str>>

The text of an id.

Source

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

Source

pub fn cmp(&self, a: u32, b: u32) -> Ordering

Compares two ids in the table’s order: by text, or by token.

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

The number of strings.

Source

pub fn is_empty(&self) -> bool

Whether the table is empty.

Source

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.

Trait Implementations§

Source§

impl Debug for Strings

Source§

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

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

impl Default for Strings

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