[−][src]Struct super_slab::SuperSlab
A SuperSlab is a collection of Slabs, viewed as single Slab.
Implementations
impl<T> SuperSlab<T>
[src]
pub fn new() -> Self
[src]
Construct a new, empty SuperSlab
.
The function allocates 4 extents with each Slab
having a capacity of 4.
Examples
let slab: SuperSlab<i32> = SuperSlab::new(); assert_eq!(slab.capacity(), 16);
pub fn with_capacity_and_extents(
capacity: usize,
secondary: usize,
extents: usize
) -> Self
[src]
capacity: usize,
secondary: usize,
extents: usize
) -> Self
Construct a new, empty SuperSlab
with the specified capacity.
The returned slab will be able to store exactly capacity
without
allocating an extent. If capacity
is 0, a panic will occur.
It is important to note that this function does not specify the length of the returned slab, but only the capacity. For an explanation of the difference between length and capacity, see Capacity and reallocation.
Examples
// allocate with a capacity of 10, reserve 4 extents, each with a capacity of 2 // this produces two allocation, one for the extents (4 slots) and one for // the primary (10 entries). let mut slab = SuperSlab::with_capacity_and_extents(10, 2, 4); // The slab contains no values, even though it has capacity for more assert_eq!(slab.len(), 0); assert_eq!(slab.capacity(), 10); // These are all done without extending... for i in 0..10 { slab.insert(i); } // ...but this will make the super slab add an extent slab.insert(11); assert_eq!(slab.capacity(), 12);
pub fn with_capacity(capacity: usize) -> Self
[src]
Simpler instantiation of a slab. This will extents will be 1/4 of capacity or capacity if capacity is less than or equal to 100.
Examples
// allocate with a capacity of 10, reserve 4 extents, each with a capacity of 10 // this produces two allocation, one for the extents (4 slots) and one for // the primary (10 entries). let mut slab = SuperSlab::with_capacity(10); // The slab contains no values, even though it has capacity for more assert_eq!(slab.len(), 0); assert_eq!(slab.capacity(), 10); // These are all done without extending... for i in 0..10 { slab.insert(i); } // ...but this will make the super slab add an extent slab.insert(11); assert_eq!(slab.capacity(), 20);
pub fn capacity(&self) -> usize
[src]
Return the number of values the slab can store without reallocating.
Examples
let slab: SuperSlab<i32> = SuperSlab::with_capacity(10); assert_eq!(slab.capacity(), 10);
pub fn clear(&mut self)
[src]
reserve is not supported. It seems to have limited value in a SuperSlab. reserve_exact is not supported. It seems to have limited value in a SuperSlab. shrink_to_fit is not supported. It seems to have limited value in a SuperSlab. compact is not supported. It may be supported in the future Clear the slabs of all values.
Examples
let mut slab = SuperSlab::new(); for i in 0..slab.capacity() { slab.insert(i); } slab.clear(); assert!(slab.is_empty());
pub fn len(&self) -> usize
[src]
Return the number of stored values.
Examples
let mut slab = SuperSlab::new(); for i in 0..6 { slab.insert(i); } assert_eq!(6, slab.len());
pub fn is_empty(&self) -> bool
[src]
Return true
if there are no values stored in the slab.
Examples
let mut slab = SuperSlab::new(); assert!(slab.is_empty()); slab.insert(1); assert!(!slab.is_empty());
pub fn iter(&self) -> Iter<'_, T>ⓘ
[src]
Return an iterator over the slabs.
This function should generally be avoided as it is not efficient. Iterators must iterate over every slot in the slab even if it is vacant. As such, a slab with a capacity of 1 million but only one stored value must still iterate the million slots.
Examples
let mut slab = SuperSlab::with_capacity(2); for i in 0..3 { slab.insert(i); } let mut iterator = slab.iter(); assert_eq!(iterator.next(), Some((0, &0))); assert_eq!(iterator.next(), Some((1, &1))); assert_eq!(iterator.next(), Some((2, &2))); assert_eq!(iterator.next(), None);
pub fn iter_mut(&mut self) -> IterMut<'_, T>ⓘ
[src]
Return an iterator that allows modifying each value.
This function should generally be avoided as it is not efficient. Iterators must iterate over every slot in the slab even if it is vacant. As such, a slab with a capacity of 1 million but only one stored value must still iterate the million slots.
Examples
let mut slab = SuperSlab::with_capacity(2); let key1 = slab.insert(0); let key2 = slab.insert(1); for (key, val) in slab.iter_mut() { if key == key1 { *val += 2; } } assert_eq!(slab[key1], 2); assert_eq!(slab[key2], 1);
pub fn get(&self, key: usize) -> Option<&T>
[src]
Return a reference to the value associated with the given key.
If the given key is not associated with a value, then None
is
returned.
Examples
let mut slab = SuperSlab::new(); let key = slab.insert("hello"); assert_eq!(slab.get(key), Some(&"hello")); assert_eq!(slab.get(123), None);
pub fn get_mut(&mut self, key: usize) -> Option<&mut T>
[src]
Return a mutable reference to the value associated with the given key.
If the given key is not associated with a value, then None
is
returned.
Examples
let mut slab = SuperSlab::new(); let key = slab.insert("hello"); *slab.get_mut(key).unwrap() = "world"; assert_eq!(slab[key], "world"); assert_eq!(slab.get_mut(123), None);
pub unsafe fn get_unchecked(&self, key: usize) -> &T
[src]
Return a reference to the value associated with the given key without performing bounds checking.
Safety
This function should be used with care.
Examples
let mut slab = SuperSlab::new(); let key = slab.insert(2); unsafe { assert_eq!(slab.get_unchecked(key), &2); }
pub unsafe fn get_unchecked_mut(&mut self, key: usize) -> &mut T
[src]
Return a mutable reference to the value associated with the given key without performing bounds checking.
Safety
This function should be used with care.
Examples
let mut slab = SuperSlab::new(); let key = slab.insert(2); unsafe { let val = slab.get_unchecked_mut(key); *val = 13; } assert_eq!(slab[key], 13);
pub fn insert(&mut self, val: T) -> usize
[src]
key_of is not supported. It may be supported in the future. Insert a value in the slab, returning key assigned to the value.
The returned key can later be used to retrieve or remove the value using indexed
lookup and remove
. Additional capacity is allocated if needed. See
Capacity and reallocation.
Panics
Panics if the number of elements in the vector overflows a usize
.
Examples
let mut slab = SuperSlab::new(); let key = slab.insert("hello"); assert_eq!(slab[key], "hello");
pub fn vacant_entry(&mut self) -> VacantEntry<'_, T>
[src]
Return a handle to a vacant entry allowing for further manipulation.
This function is useful when creating values that must contain their
slab key. The returned VacantEntry
reserves a slot in the slab and is
able to query the associated key.
Examples
let mut slab = SuperSlab::new(); let hello = { let entry = slab.vacant_entry(); let key = entry.key(); entry.insert((key, "hello")); key }; assert_eq!(hello, slab[hello].0); assert_eq!("hello", slab[hello].1);
pub fn remove(&mut self, key: usize) -> T
[src]
Remove and return the value associated with the given key.
The key is then released and may be associated with future stored values.
Panics
Panics if key
is not associated with a value.
Examples
let mut slab = SuperSlab::new(); let hello = slab.insert("hello"); assert_eq!(slab.remove(hello), "hello"); assert!(!slab.contains(hello));
pub fn contains(&self, key: usize) -> bool
[src]
Return true
if a value is associated with the given key.
Examples
let mut slab = SuperSlab::new(); let hello = slab.insert("hello"); assert!(slab.contains(hello)); slab.remove(hello); assert!(!slab.contains(hello));
pub fn retain<F>(&mut self, f: F) where
F: FnMut(usize, &mut T) -> bool,
[src]
F: FnMut(usize, &mut T) -> bool,
Retain only the elements specified by the predicate.
In other words, remove all elements e
such that f(usize, &mut e)
returns false. This method operates in place and preserves the key
associated with the retained values.
Examples
let mut slab = SuperSlab::with_capacity(2); let k1 = slab.insert(0); let k2 = slab.insert(1); let k3 = slab.insert(2); slab.retain(|key, val| key == k1 || *val == 1); assert!(slab.contains(k1)); assert!(slab.contains(k2)); assert!(!slab.contains(k3)); assert_eq!(2, slab.len());
pub fn drain(&mut self) -> Drain<'_, T>ⓘ
[src]
Return a draining iterator that removes all elements from the slab and yields the removed items.
Note: Elements are removed even if the iterator is only partially consumed or not consumed at all.
Examples
let mut slab = SuperSlab::new(); let _ = slab.insert(0); let _ = slab.insert(1); let _ = slab.insert(2); { let mut drain = slab.drain(); assert_eq!(Some(0), drain.next()); assert_eq!(Some(1), drain.next()); assert_eq!(Some(2), drain.next()); assert_eq!(None, drain.next()); } assert!(slab.is_empty());
Trait Implementations
impl<T: Clone> Clone for SuperSlab<T>
[src]
impl<T> Debug for SuperSlab<T> where
T: Debug,
[src]
T: Debug,
impl<T> Default for SuperSlab<T>
[src]
impl<T> Index<usize> for SuperSlab<T>
[src]
impl<T> IndexMut<usize> for SuperSlab<T>
[src]
impl<'a, T> IntoIterator for &'a SuperSlab<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) -> Iter<'a, T>ⓘ
[src]
impl<'a, T> IntoIterator for &'a mut SuperSlab<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for SuperSlab<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for SuperSlab<T> where
T: Send,
T: Send,
impl<T> Sync for SuperSlab<T> where
T: Sync,
T: Sync,
impl<T> Unpin for SuperSlab<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for SuperSlab<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,
pub 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<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,