[][src]Crate super_slab

Why multiply, when you can divide. I'd like to acknowledge the wonderful work done by the developers of Slab. Much of this is a direct derivative of their work.

Build on top of Slab, SuperSlab uses an extent model, where a primary capacity is allocated. When full, a new slab of a secondary size is added to the SuperSlab. The primary advantage is that allocation doesn't reallocate the Slab.

Nearly all of the Slab methods are present here as well. The notable exceptions being:

  • reserve()
  • reserve_exact()
  • shrink_to_fit()
  • compact()
  • key_of
  • various flavors of DoubleEndedIterator


Basic storing and retrieval.

let mut slab = SuperSlab::new();

let hello = slab.insert("hello");
let world = slab.insert("world");

assert_eq!(slab[hello], "hello");
assert_eq!(slab[world], "world");

slab[world] = "earth";
assert_eq!(slab[world], "earth");

Sometimes it is useful to be able to associate the key with the value being inserted in the slab. This can be done with the vacant_entry API as such:

let mut slab = SuperSlab::new();

let hello = {
    let entry = slab.vacant_entry();
    let key = entry.key();

    entry.insert((key, "hello"));

assert_eq!(hello, slab[hello].0);
assert_eq!("hello", slab[hello].1);

It is generally a good idea to specify the desired capacity of a slab at creation time. Note that SuperSlab will add a new slab when attempting to insert a new value once the existing capacity has been reached.

let mut slab = SuperSlab::with_capacity(1024);

// ... use the slab

slab.insert("the slab is not at capacity yet");

For complete constroll, you can specify the primary capacity, the secondary capacity and the capacity of the slab vec.

// allocate a primary capacity of 5000, once that fills, a new slab
// with capacity 1000 will be allocated. Once 8 have been allocated,
// the slab vec will need to be reallocated.

let mut slab = SuperSlab::with_capacity_and_extents(5000, 1000, 8);

// ... use the slab

slab.insert("the slab is not at capacity yet");



A draining iterator for Slabs


An iterator over the Slabs


A mutable iterator over the Slabs


A SuperSlab is a collection of Slabs, viewed as single Slab.


A handle to a vacant entry in a Slab.