pub struct SetList<K, V, S> { /* private fields */ }Expand description
A list containg unique key-value pairs.
This is a list, but all items are laid on a single sequential memory block.
Therefore, we can expect more speed in terms of iteration than standard
linked list, LinkedList, but it requires
more memory footprint.
§NOTE
Current implementation doesn’t concern about ZST.
Implementations§
Source§impl<K, V, S> SetList<K, V, S>where
S: BuildHasher + Default,
impl<K, V, S> SetList<K, V, S>where
S: BuildHasher + Default,
Source§impl<K, V, S> SetList<K, V, S>
impl<K, V, S> SetList<K, V, S>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns number of items.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert_eq!(list.len(), 1);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the list is empty.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<char, &'static str, RandomState>::default();
assert!(list.is_empty());Sourcepub fn front(&self) -> Option<&V>
pub fn front(&self) -> Option<&V>
Returns a shared reference to the front item.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
assert_eq!(list.front(), Some(&"alpha"));Sourcepub fn front_mut(&mut self) -> Option<&mut V>
pub fn front_mut(&mut self) -> Option<&mut V>
Returns a mutable reference to the front item.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
assert_eq!(list.front_mut(), Some(&mut "alpha"));Sourcepub fn back(&self) -> Option<&V>
pub fn back(&self) -> Option<&V>
Returns a shared reference to the last item.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
assert_eq!(list.back(), Some(&"beta"));Sourcepub fn back_mut(&mut self) -> Option<&mut V>
pub fn back_mut(&mut self) -> Option<&mut V>
Returns a mutable reference to the last item.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
assert_eq!(list.back_mut(), Some(&mut "beta"));Sourcepub fn values(&self) -> Values<'_, V, S> ⓘ
pub fn values(&self) -> Values<'_, V, S> ⓘ
Returns an iterator visiting all values in order.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
for v in list.values() {
println!("{v}"); // Prints out "alpha" and "beta".
}Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, V, S> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, V, S> ⓘ
Returns a mutable iterator visiting all values in order.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha".to_owned());
list.push_back('b', "beta".to_owned());
for v in list.values_mut() {
v.push('*');
println!("{v}"); // Prints out "alpha*" and "beta*".
}Sourcepub fn values_from(&self, cur: ListPos) -> Values<'_, V, S> ⓘ
pub fn values_from(&self, cur: ListPos) -> Values<'_, V, S> ⓘ
Returns an iterator visiting values from the given position.
§Panics
Panics if the position is not valid one for the list.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
list.push_back('g', "gamma");
let pos = list.get_position(&'b').unwrap();
for v in list.values_from(pos) {
println!("{v}"); // Prints out "beta" and "gamma".
}Sourcepub fn values_mut_from(&mut self, cur: ListPos) -> ValuesMut<'_, V, S> ⓘ
pub fn values_mut_from(&mut self, cur: ListPos) -> ValuesMut<'_, V, S> ⓘ
Returns a mutable iterator visiting values from the given position.
§Panics
Panics if the position is not valid one for the list.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha".to_owned());
list.push_back('b', "beta".to_owned());
list.push_back('g', "gamma".to_owned());
let pos = list.get_position(&'b').unwrap();
for v in list.values_mut_from(pos) {
v.push('*');
println!("{v}"); // Prints out "beta*" and "gamma*".
}Sourcepub fn into_values(self) -> IntoValues<V, S> ⓘ
pub fn into_values(self) -> IntoValues<V, S> ⓘ
Creates an iterator visiting all values in order by consuming the list.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
for v in list.into_values() {
println!("{v}");
}Sourcepub fn into_values_from(self, cur: ListPos) -> IntoValues<V, S> ⓘ
pub fn into_values_from(self, cur: ListPos) -> IntoValues<V, S> ⓘ
Creates an iterator visiting values from the given position by consuming the list.
§Panics
Panics if the position is not valid one for the list.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
list.push_back('g', "gamma");
let pos = list.get_position(&'b').unwrap();
for v in list.into_values_from(pos) {
println!("{v}"); // Prints out "beta" and "gamma".
}Sourcepub fn iter_next(&self, cur: ListPos) -> Option<(ListPos, &V)>
pub fn iter_next(&self, cur: ListPos) -> Option<(ListPos, &V)>
Returns a shared reference to a value at the given position with the next position.
If the given position is not valid one for the list, returns None.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
let pos = list.get_position(&'b').unwrap();
let (_, v) = list.iter_next(pos).unwrap();
assert_eq!(v, &"beta");Sourcepub fn iter_next_mut(&mut self, cur: ListPos) -> Option<(ListPos, &mut V)>
pub fn iter_next_mut(&mut self, cur: ListPos) -> Option<(ListPos, &mut V)>
Returns a mutable reference to a value at the given position with the next position.
If the given position is not valid one for the list, returns None.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
let pos = list.get_position(&'b').unwrap();
let (_, v) = list.iter_next_mut(pos).unwrap();
assert_eq!(v, &mut "beta");Sourcepub fn first_position(&self) -> ListPos
pub fn first_position(&self) -> ListPos
Returns the first position of the list.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
let pos = list.first_position();
let (_, v) = list.iter_next(pos).unwrap();
assert_eq!(v, &"alpha");Source§impl<K, V, S> SetList<K, V, S>
impl<K, V, S> SetList<K, V, S>
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the vector contains the given key.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert!(list.contains_key(&'a'));Sourcepub fn get_position<Q>(&self, key: &Q) -> Option<ListPos>
pub fn get_position<Q>(&self, key: &Q) -> Option<ListPos>
Retrieves a position of a value corresponding to the given key.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
let pos = list.get_position(&'a').unwrap();Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Retrieves a shared reference to a value corresponding to the given key.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert_eq!(list.get(&'a'), Some(&"alpha"));Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Retrieves a mutable reference to a value corresponding to the given key.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert_eq!(list.get_mut(&'a'), Some(&mut "alpha"));Sourcepub fn push_back(&mut self, key: K, value: V) -> bool
pub fn push_back(&mut self, key: K, value: V) -> bool
Appends the given key-value pair to the end of the list.
However, if the list already contains the key, nothing takes place and returns false.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert!(!list.push_back('a', "beta"));
assert_eq!(list.back(), Some(&"alpha"));Sourcepub fn push_front(&mut self, key: K, value: V) -> bool
pub fn push_front(&mut self, key: K, value: V) -> bool
Inserts the given key-value pair to the beginning of the list.
However, if the list already contains the key, nothing takes place and returns false.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_front('a', "alpha");
assert!(!list.push_front('a', "beta"));
assert_eq!(list.front(), Some(&"alpha"));Sourcepub fn insert<Q>(&mut self, key: K, value: V, after: &Q) -> bool
pub fn insert<Q>(&mut self, key: K, value: V, after: &Q) -> bool
Inserts the given key-value pair after a node corresponding to
after.
However, if the list already contains the key or doesn’t contain
after, nothing takes place and returns false.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('g', "gamma");
list.insert('b', "beta", &'a');Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Removes an item corresponding to the given key.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert_eq!(list.remove(&'a'), Some("alpha"));Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Removes an item corresponding to the given key then resturns key-value pair.
§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;
let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert_eq!(list.remove_entry(&'a'), Some(('a', "alpha")));Source§impl<K, V, S> SetList<K, V, S>where
V: Clone,
S: BuildHasher,
impl<K, V, S> SetList<K, V, S>where
V: Clone,
S: BuildHasher,
Sourcepub fn values_as_vec(&self) -> Vec<V>
pub fn values_as_vec(&self) -> Vec<V>
Creates Vec from this list.
Trait Implementations§
Source§impl<K, V, S> IntoIterator for SetList<K, V, S>where
S: BuildHasher,
impl<K, V, S> IntoIterator for SetList<K, V, S>where
S: BuildHasher,
impl<K, V, S> Resource for SetList<K, V, S>
Auto Trait Implementations§
impl<K, V, S> Freeze for SetList<K, V, S>where
S: Freeze,
impl<K, V, S> RefUnwindSafe for SetList<K, V, S>
impl<K, V, S> Send for SetList<K, V, S>
impl<K, V, S> Sync for SetList<K, V, S>
impl<K, V, S> Unpin for SetList<K, V, S>
impl<K, V, S> UnwindSafe for SetList<K, V, S>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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