pub fn insert(&mut self, val: T) -> usize {
        let primary_capacity = self.primary_capacity;
        let secondary_capacity = self.secondary_capacity;
        // find a slab that is not at capacity and insert into it
        match self.slabs.iter_mut().enumerate().find(|val| val.1.len() != val.1.capacity()) {
            Some((idx, slab)) => {
                let k = slab.insert(val);
                if idx == 0 {
                    k
                } else {
                    k + primary_capacity + ((idx - 1) * secondary_capacity)
                }
            },
            None => {
                let mut slab = Slab::with_capacity(self.secondary_capacity);
                let res = self.conv_into_key(slab.insert(val), self.slabs.len());
                self.slabs.push(slab);
                res
            },
        }
    }
/// 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](index.html#capacity-and-reallocation).
///
/// # Panics
///
/// Panics if the number of elements in the vector overflows a `usize`.
///
/// # Examples
///
/// ```
/// # use super_slab::*;
/// let mut slab = SuperSlab::new();
/// let key = slab.insert("hello");
/// assert_eq!(slab[key], "hello");
/// ```
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.
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 .
pub fn insert(&mut self, val: T) -> usize {
        let primary_capacity = self.primary_capacity;
        let secondary_capacity = self.secondary_capacity;
        // find a slab that is not at capacity and insert into it
        match self.slabs.iter_mut().enumerate().find(|val| val.1.len() != val.1.capacity()) {
            Some((idx, slab)) => {
                let k = slab.insert(val);
                if idx == 0 {
                    k
                } else {
                    k + primary_capacity + ((idx - 1) * secondary_capacity)
                }
            },
            None => {
                let mut slab = Slab::with_capacity(self.secondary_capacity);
                let res = self.conv_into_key(slab.insert(val), self.slabs.len());
                self.slabs.push(slab);
                res
            },
        }
    }
pub fn insert ( & mut self , val : T ) -> usize { let primary_capacity = self . primary_capacity ; let secondary_capacity = self . secondary_capacity ; // find a slab that is not at capacity and insert into it match self . slabs . iter_mut ( ) . enumerate ( ) . find ( | val | val . 1 . len ( ) != val . 1 . capacity ( ) ) { Some ( ( idx , slab ) ) => { let k = slab . insert ( val ) ; if idx == 0 { k } else { k + primary_capacity + ( ( idx - 1 ) * secondary_capacity ) } } , None => { let mut slab = Slab :: with_capacity ( self . secondary_capacity ) ; let res = self . conv_into_key ( slab . insert ( val ) , self . slabs . len ( ) ) ; self . slabs . push ( slab ) ; res } , } }
Insert a value in the slab, returning key assigned to the value.
Insert a value in the slab returning key assigned to the value .
&mut self
val
T
&mut self
val
T
panics
Panics if the number of elements in the vector overflows a `usize`.
Panics if the number of elements in the vector overflows a ` usize ` .
examples
None
use super_slab::*;
let mut slab = SuperSlab::new();
let key = slab.insert("hello");
assert_eq!(slab[key], "hello");
```
let mut slab = SuperSlab :: new () ; let key = slab . insert ( " hello " ) ; assert_eq! ( slab [ key ] " hello " ) ; ` ` `