Skip to main content

Interner

Struct Interner 

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

A structure’s identifier dictionary.

Interning is idempotent: the same string always yields the same identifier within one interner, and identifiers are issued in first-seen order, so two runs over the same file produce the same numbering.

Implementations§

Source§

impl Interner

Source

pub const DEFAULT_LIMIT: u32 = 1_000_000

The largest number of local identifiers one structure may issue.

This is a guard, not a design target. Reaching it means input-generated identifiers rather than naming things.

Source

pub fn retained_bytes(&self) -> usize

Bytes retained by local arena, extent and lookup-table capacities.

Source

pub fn new() -> Self

Creates an empty dictionary over the canonical one.

Runs in O(1) time and creates no local-string allocation.

Source

pub fn with_capacity(identifiers: usize) -> Self

Creates a dictionary with room reserved for identifiers local strings.

The extent vector and hash table reserve capacity up front. The arena is left empty because the total byte length cannot be inferred from the number of identifiers.

Uses O(identifiers) reserved memory.

Source

pub const fn with_limit(self, limit: u32) -> Self

Sets the limit on local identifiers.

Runs in O(1) time and allocates no memory.

Source

pub fn intern(&mut self, text: &str) -> Result<SymbolId, DictionaryFull>

Returns the identifier for text, interning it if it is new.

Existing strings require no allocation. A new local string is copied exactly once into the arena and adds one extent and one table entry.

Expected running time is O(L), where L is text.len(). Insertion is amortized over hash-table and arena growth.

§Errors

Returns DictionaryFull when the local dictionary has reached its limit and text is not already in it.

Source

pub fn get(&self, text: &str) -> Option<SymbolId>

Returns the identifier for text if it is already known, without interning it.

This is what a selection uses: a name that no structure contains should resolve to nothing rather than growing the dictionary.

Expected running time is O(L), where L is text.len(). The operation performs no allocation and does not mutate the dictionary.

Source

pub fn resolve(&self, id: SymbolId) -> Option<&str>

Returns the string an identifier names.

Runs in O(1) time and allocates no memory. The returned slice borrows either static canonical storage or this interner’s arena.

Source

pub fn len(&self) -> usize

The number of local identifiers issued.

Runs in O(1) time and allocates no memory.

Source

pub fn is_empty(&self) -> bool

Returns true when no local identifier has been issued.

Runs in O(1) time and allocates no memory.

Source

pub fn arena_len(&self) -> usize

The bytes the local strings occupy.

Runs in O(1) time and allocates no memory.

Source

pub fn iter(&self) -> impl Iterator<Item = (SymbolId, &str)>

Walks canonical and structure-local identifiers in stable id order.

This is the dictionary-side half of compiling glob predicates: pattern work is proportional to distinct identifiers and the atom loop remains integer membership. Iteration allocates nothing.

Trait Implementations§

Source§

impl Clone for Interner

Source§

fn clone(&self) -> Self

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 Interner

Source§

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

Formats the interner’s local-count and arena-size metadata.

Runs in O(1) time and does not traverse or copy interned strings.

Source§

impl Default for Interner

Source§

fn default() -> Self

Creates an empty interner with Interner::DEFAULT_LIMIT.

Runs in O(1) time and creates no local-string allocation.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.