pub struct VarNameMap { /* private fields */ }
Expand description
Bi-directional mapping between variables and names, intended for the
implementation of a Manager
.
The map requires variable names to be unique, but allows unnamed variables (represented by empty strings).
Implementations§
Source§impl VarNameMap
impl VarNameMap
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true
if and only if self.len()
is 0
Sourcepub fn reserve(&mut self, additional: VarNo)
pub fn reserve(&mut self, additional: VarNo)
Reserve space for additional
entries
Adding the next additional
entries will not cause an allocation in the
underlying vector and map.
Sourcepub fn named_count(&self) -> VarNo
pub fn named_count(&self) -> VarNo
Get the number of named variables
Sourcepub fn add_unnamed(&mut self, additional: VarNo)
pub fn add_unnamed(&mut self, additional: VarNo)
Add additional
unnamed variables
Panics if self.len()
plus additional
is greater than
to VarNo::MAX
.
Sourcepub fn add_named<T: IntoIterator<Item = S>, S: Into<String>>(
&mut self,
names: T,
) -> Result<Range<VarNo>, DuplicateVarName>
pub fn add_named<T: IntoIterator<Item = S>, S: Into<String>>( &mut self, names: T, ) -> Result<Range<VarNo>, DuplicateVarName>
Add fresh variables with names from names
Returns Ok(range)
on success, where range
contains the new variable
numbers. If names
is too long (there would be more than VarNo::MAX
variables), the remaining elements are not consumed.
If a variable name is not unique, this method returns a
DuplicateVarName
error.
Sourcepub fn get_or_add(&mut self, name: impl Into<String>) -> (VarNo, bool)
pub fn get_or_add(&mut self, name: impl Into<String>) -> (VarNo, bool)
Get the variable number for the given name if present, or add a new variable
Returns a pair (var_no, found)
. If the provided variable name is
empty, this method will always create a fresh variable.
If a variable with the given name is not present yet, and there is no
variable free in range 0..VarNo::MAX
, then the variable is not added.
Still, the return value is VarNo::MAX
.
Sourcepub fn name_to_var(&self, name: impl AsRef<str>) -> Option<VarNo>
pub fn name_to_var(&self, name: impl AsRef<str>) -> Option<VarNo>
Get the variable number for the given name, if present
self.name_to_var("")
always returns None
.
Sourcepub fn var_name(&self, var: VarNo) -> &str
pub fn var_name(&self, var: VarNo) -> &str
Get var
’s name
For unnamed vars, this will return the empty string.
Panics if var
is greater or equal to self.len()
.
Sourcepub fn set_var_name(
&mut self,
var: VarNo,
name: impl Into<String>,
) -> Result<(), DuplicateVarName>
pub fn set_var_name( &mut self, var: VarNo, name: impl Into<String>, ) -> Result<(), DuplicateVarName>
Label var
as name
An empty name means that the variable will become unnamed, and cannot be
retrieved via Self::name_to_var()
anymore.
Returns Err((name, other_var))
if name
is not unique (and not ""
).
Panics if var
is greater or equal to the number of variables in this
map.
Sourcepub fn into_names_iter(self) -> IntoNamesIter ⓘ
pub fn into_names_iter(self) -> IntoNamesIter ⓘ
Iterate over the variable names (including all unnamed variables)
Trait Implementations§
Source§impl Clone for VarNameMap
impl Clone for VarNameMap
Source§fn clone(&self) -> VarNameMap
fn clone(&self) -> VarNameMap
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more