Struct elsa::index_set::FrozenIndexSet
source · pub struct FrozenIndexSet<T, S = RandomState> { /* private fields */ }
Expand description
Append-only version of indexmap::IndexSet
where
insertion does not require mutable access
Implementations§
source§impl<T: Eq + Hash + StableDeref, S: BuildHasher> FrozenIndexSet<T, S>
impl<T: Eq + Hash + StableDeref, S: BuildHasher> FrozenIndexSet<T, S>
sourcepub fn insert(&self, value: T) -> &T::Target
pub fn insert(&self, value: T) -> &T::Target
If the value exists in the set, returns a reference to the corresponding value, otherwise inserts a new entry in the set for that value and returns a reference to it.
Existing values are never overwritten.
Example
use elsa::index_set::FrozenIndexSet;
let set = FrozenIndexSet::new();
let a_ref = set.insert(Box::new("a"));
let aa = "a";
let other_a_ref = unsafe { aa.as_ptr() as *const &str};
let other_a = Box::new(aa);
assert!(!std::ptr::eq(a_ref, other_a_ref));
assert!(std::ptr::eq(a_ref, set.insert(other_a)));
sourcepub fn insert_full(&self, value: T) -> (usize, &T::Target)
pub fn insert_full(&self, value: T) -> (usize, &T::Target)
If the key exists in the set, returns a reference to the corresponding value and its index, otherwise inserts a new entry in the set for that value and returns a reference to it and its index.
Existing values are never overwritten.
Example
use elsa::index_set::FrozenIndexSet;
let map = FrozenIndexSet::new();
assert_eq!(map.insert_full(Box::new("a")), (0, &"a"));
assert_eq!(map.insert_full(Box::new("b")), (1, &"b"));
sourcepub fn get<Q>(&self, k: &Q) -> Option<&T::Target>where
T: Borrow<Q>,
Q: Hash + Eq + ?Sized,
pub fn get<Q>(&self, k: &Q) -> Option<&T::Target>where T: Borrow<Q>, Q: Hash + Eq + ?Sized,
Returns a reference to the value passed as argument if present in the set.
Examples
use elsa::index_set::FrozenIndexSet;
let set = FrozenIndexSet::new();
set.insert(Box::new("a"));
assert_eq!(set.get(&Box::new("a")), Some(&"a"));
assert_eq!(set.get(&Box::new("b")), None);
sourcepub fn get_full<Q>(&self, k: &Q) -> Option<(usize, &T::Target)>where
T: Borrow<Q>,
Q: Hash + Eq + ?Sized,
pub fn get_full<Q>(&self, k: &Q) -> Option<(usize, &T::Target)>where T: Borrow<Q>, Q: Hash + Eq + ?Sized,
Returns a reference to the value passed as argument if present in the set, along with its index
Examples
use elsa::index_set::FrozenIndexSet;
let set = FrozenIndexSet::new();
set.insert(Box::new("a"));
assert_eq!(set.get_full(&Box::new("a")), Some((0, &"a")));
assert_eq!(set.get_full(&Box::new("b")), None);
sourcepub fn get_index(&self, index: usize) -> Option<&T::Target>
pub fn get_index(&self, index: usize) -> Option<&T::Target>
Returns a reference to value at the index passed as argument, if present in the set.
Examples
use elsa::index_set::FrozenIndexSet;
let set = FrozenIndexSet::new();
set.insert(Box::new("a"));
assert_eq!(set.get_index(0), Some(&"a"));
assert_eq!(set.get_index(1), None);