[−][src]Struct slabmap::SlabMap
A fast HashMap-like collection that automatically determines the key.
Implementations
impl<T> SlabMap<T>
[src]
pub fn new() -> Self
[src]
Constructs a new, empty SlabMap
pub fn with_capacity(capacity: usize) -> Self
[src]
Constructs a new, empty SlabMap
pub fn capacity(&self) -> usize
[src]
Returns the number of elements the SlabMap can hold without reallocating.
pub fn reserve(&mut self, additional: usize)
[src]
Reserves capacity for at least additional more elements to be inserted in the given SlabMap
Panics
Panics if the new capacity overflows usize.
pub fn reserve_exact(&mut self, additional: usize)
[src]
Reserves the minimum capacity for exactly additional more elements to be inserted in the given SlabMap
Panics
Panics if the new capacity overflows usize.
pub fn len(&self) -> usize
[src]
Returns the number of elements in the SlabMap.
Examples
use slabmap::SlabMap; let mut s = SlabMap::new(); assert_eq!(s.len(), 0); let key1 = s.insert(10); let key2 = s.insert(15); assert_eq!(s.len(), 2); s.remove(key1); assert_eq!(s.len(), 1); s.remove(key2); assert_eq!(s.len(), 0);
pub fn is_empty(&self) -> bool
[src]
Returns true if the SlabMap contains no elements.
pub fn get(&self, key: usize) -> Option<&T>
[src]
Returns a reference to the value corresponding to the key.
pub fn get_mut(&mut self, key: usize) -> Option<&mut T>
[src]
Returns a mutable reference to the value corresponding to the key.
pub fn contains_key(&self, key: usize) -> bool
[src]
Returns true if the SlabMap contains a value for the specified key.
pub fn insert(&mut self, value: T) -> usize
[src]
Inserts a value into the SlabMap.
Returns the key associated with the value.
Examples
use slabmap::SlabMap; let mut s = SlabMap::new(); let key_abc = s.insert("abc"); let key_xyz = s.insert("xyz"); assert_eq!(s[key_abc], "abc"); assert_eq!(s[key_xyz], "xyz");
pub fn insert_with_key(&mut self, f: impl FnOnce(usize) -> T) -> usize
[src]
Inserts a value given by f
into the SlabMap. The key to be associated with the value is passed to f
.
Returns the key associated with the value.
Examples
use slabmap::SlabMap; let mut s = SlabMap::new(); let key = s.insert_with_key(|key| format!("my key is {}", key)); assert_eq!(s[key], format!("my key is {}", key));
pub fn remove(&mut self, key: usize) -> Option<T>
[src]
Removes a key from the SlabMap, returning the value at the key if the key was previously in the SlabMap.
pub fn clear(&mut self)
[src]
Clears the SlabMap, removing all values and optimize free spaces.
pub fn drain(&mut self) -> Drain<T>
[src]
Clears the SlabMap, returning all values as an iterator and optimize free spaces.
pub fn retain(&mut self, f: impl FnMut(usize, &mut T) -> bool)
[src]
Retains only the elements specified by the predicate and optimize free spaces.
use slabmap::SlabMap; let mut s = SlabMap::new(); s.insert(10); s.insert(15); s.insert(20); s.insert(25); s.retain(|_idx, value| *value % 2 == 0); let value: Vec<_> = s.values().cloned().collect(); assert_eq!(value, vec![10, 20]);
pub fn optimize(&mut self)
[src]
Optimizing the free space for speeding up iterations.
If the free space has already been optimized, this method does nothing and completes with O(1).
pub fn iter(&self) -> Iter<T>
[src]
Gets an iterator over the entries of the SlabMap, sorted by key.
If you make a large number of remove
calls, optimize
should be called before calling this function.
pub fn iter_mut(&mut self) -> IterMut<T>
[src]
Gets a mutable iterator over the entries of the slab, sorted by key.
If you make a large number of remove
calls, optimize
should be called before calling this function.
pub fn keys(&self) -> Keys<T>
[src]
Gets an iterator over the keys of the SlabMap, in sorted order.
If you make a large number of remove
calls, optimize
should be called before calling this function.
pub fn values(&self) -> Values<T>
[src]
Gets an iterator over the values of the SlabMap.
If you make a large number of remove
calls, optimize
should be called before calling this function.
pub fn values_mut(&mut self) -> ValuesMut<T>
[src]
Trait Implementations
impl<T: Clone> Clone for SlabMap<T>
[src]
impl<T: Debug> Debug for SlabMap<T>
[src]
impl<T> Default for SlabMap<T>
[src]
impl<T> Index<usize> for SlabMap<T>
[src]
type Output = T
The returned type after indexing.
fn index(&self, index: usize) -> &Self::Output
[src]
impl<T> IndexMut<usize> for SlabMap<T>
[src]
impl<T> IntoIterator for SlabMap<T>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T> IntoIterator for &'a SlabMap<T>
[src]
type Item = (usize, &'a T)
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T> IntoIterator for &'a mut SlabMap<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for SlabMap<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for SlabMap<T> where
T: Send,
T: Send,
impl<T> Sync for SlabMap<T> where
T: Sync,
T: Sync,
impl<T> Unpin for SlabMap<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for SlabMap<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,