Struct rustfst::SymbolTable

source ·
pub struct SymbolTable<H: BuildHasher = RandomState> { /* private fields */ }
Expand description

A symbol table stores a bidirectional mapping between transition labels and “symbols” (strings).

Implementations§

source§

impl SymbolTable

source

pub fn new() -> Self

Creates a SymbolTable with a single element in it: the pair (EPS_LABEL, EPS_SYMBOL).

§Examples
let mut symt = SymbolTable::new();
source

pub fn empty() -> Self

source

pub fn from_text_string(symt_string: &str) -> Result<Self>

source

pub fn read_text<P: AsRef<Path>>(path_text_symt: P) -> Result<Self>

source

pub fn read<P: AsRef<Path>>(path_bin_symt: P) -> Result<Self>

source§

impl<H: BuildHasher> SymbolTable<H>

source

pub fn with_hasher(hasher_builder: H) -> Self

source

pub fn is_empty(&self) -> bool

source

pub fn add_symbol(&mut self, sym: impl Into<String>) -> Label

Adds a symbol to the symbol table. The corresponding label is returned.

§Examples
let mut symt = symt!["a", "b"];

// Elements in the table : `<eps>`, `a`, `b`
assert_eq!(symt.len(), 3);

// Add a single symbol
symt.add_symbol("c");

// Elements in the table : `<eps>`, `a`, `b`, `c`
assert_eq!(symt.len(), 4);
source

pub fn add_symbols<S: Into<String>, P: IntoIterator<Item = S>>( &mut self, symbols: P )

source

pub fn len(&self) -> usize

Returns the number of symbols stored in the symbol table.

§Examples
let mut symt = symt!["a", "b"];
assert_eq!(symt.len(), 3);
source

pub fn get_label(&self, sym: impl AsRef<str>) -> Option<Label>

Given a symbol, returns the label corresponding. If the symbol is not stored in the table then None is returned.

§Examples
let mut symt = symt!["a", "b"];
let label = symt.add_symbol("c");
assert_eq!(symt.get_label("c"), Some(label));
assert_eq!(symt.get_label("d"), None);
source

pub fn get_symbol(&self, label: Label) -> Option<&str>

Given a label, returns the symbol corresponding. If no there is no symbol with this label in the table then None is returned.

§Examples
let mut symt = symt!["a", "b"];
let label = symt.add_symbol("c");
assert_eq!(symt.get_symbol(label), Some("c"));
assert_eq!(symt.get_symbol(label + 1), None);
source

pub fn contains_symbol(&self, sym: impl AsRef<str>) -> bool

Given a symbol, returns whether it is present in the table.

§Examples
let symt = symt!["a", "b"];
assert!(symt.contains_symbol("a"));
source

pub fn contains_label(&self, label: Label) -> bool

Given a label, returns whether it is present in the table.

§Examples
let mut symt = symt!["a", "b"];
let label = symt.add_symbol("c");
assert!(symt.contains_label(label));
assert!(!symt.contains_label(label+1));
source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted in the SymbolTable. The collection may reserve more space to avoid frequent reallocations.

source

pub fn labels(&self) -> impl Iterator<Item = Label>

An iterator on all the labels stored in the SymbolTable. The iterator element is &'a Label.

§Examples
let symt = symt!["a", "b"];
let mut iterator = symt.labels();
source

pub fn symbols(&self) -> impl Iterator<Item = &str>

An iterator on all the symbols stored in the SymbolTable. The iterator element is &'a Symbol.

§Examples
let symt = symt!["a", "b"];
let mut iterator = symt.symbols();

for symbol in symt.symbols() {
    println!("Symbol : {:?}", symbol);
}
source

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

An iterator on all the labels stored in the SymbolTable. The iterator element is (&'a Label, &'a Symbol).

source

pub fn add_table(&mut self, other: &SymbolTable)

Adds another SymbolTable to this table.

source

pub fn write_text<P: AsRef<Path>>(&self, path_output: P) -> Result<()>

source

pub fn write<P: AsRef<Path>>(&self, path_bin_symt: P) -> Result<()>

source

pub fn text(&self) -> Result<String>

Writes the text_fst representation of the symbol table into a String.

Trait Implementations§

source§

impl<H: Clone + BuildHasher> Clone for SymbolTable<H>

source§

fn clone(&self) -> SymbolTable<H>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<H: Debug + BuildHasher> Debug for SymbolTable<H>

source§

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

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

impl Default for SymbolTable

source§

fn default() -> Self

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

impl<H: BuildHasher> Display for SymbolTable<H>

source§

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

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

impl<H: BuildHasher> PartialEq for SymbolTable<H>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<H> Freeze for SymbolTable<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for SymbolTable<H>
where H: RefUnwindSafe,

§

impl<H> Send for SymbolTable<H>
where H: Send,

§

impl<H> Sync for SymbolTable<H>
where H: Sync,

§

impl<H> Unpin for SymbolTable<H>
where H: Unpin,

§

impl<H> UnwindSafe for SymbolTable<H>
where H: UnwindSafe,

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V