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
impl SymbolTable
sourcepub fn new() -> Self
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();
pub fn empty() -> Self
pub fn from_text_string(symt_string: &str) -> Result<Self>
pub fn read_text<P: AsRef<Path>>(path_text_symt: P) -> Result<Self>
pub fn read<P: AsRef<Path>>(path_bin_symt: P) -> Result<Self>
source§impl<H: BuildHasher> SymbolTable<H>
impl<H: BuildHasher> SymbolTable<H>
pub fn with_hasher(hasher_builder: H) -> Self
pub fn is_empty(&self) -> bool
sourcepub fn add_symbol(&mut self, sym: impl Into<String>) -> Label
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);
pub fn add_symbols<S: Into<String>, P: IntoIterator<Item = S>>( &mut self, symbols: P )
sourcepub fn len(&self) -> usize
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);
sourcepub fn get_label(&self, sym: impl AsRef<str>) -> Option<Label>
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);
sourcepub fn get_symbol(&self, label: Label) -> Option<&str>
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);
sourcepub fn contains_symbol(&self, sym: impl AsRef<str>) -> bool
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"));
sourcepub fn contains_label(&self, label: Label) -> bool
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));
sourcepub fn reserve(&mut self, additional: usize)
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.
sourcepub fn labels(&self) -> impl Iterator<Item = Label>
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();
sourcepub fn symbols(&self) -> impl Iterator<Item = &str>
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);
}
sourcepub fn iter(&self) -> impl Iterator<Item = (Label, &str)>
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)
.
sourcepub fn add_table(&mut self, other: &SymbolTable)
pub fn add_table(&mut self, other: &SymbolTable)
Adds another SymbolTable to this table.
pub fn write_text<P: AsRef<Path>>(&self, path_output: P) -> Result<()>
pub fn write<P: AsRef<Path>>(&self, path_bin_symt: P) -> Result<()>
Trait Implementations§
source§impl<H: Clone + BuildHasher> Clone for SymbolTable<H>
impl<H: Clone + BuildHasher> Clone for SymbolTable<H>
source§fn clone(&self) -> SymbolTable<H>
fn clone(&self) -> SymbolTable<H>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<H: Debug + BuildHasher> Debug for SymbolTable<H>
impl<H: Debug + BuildHasher> Debug for SymbolTable<H>
source§impl Default for SymbolTable
impl Default for SymbolTable
source§impl<H: BuildHasher> Display for SymbolTable<H>
impl<H: BuildHasher> Display for SymbolTable<H>
source§impl<H: BuildHasher> PartialEq for SymbolTable<H>
impl<H: BuildHasher> PartialEq for SymbolTable<H>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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