slabs

Types

pub opaque type Slab(a)
pub type SlabError {
  BadIndex(index: Int)
}

Constructors

  • BadIndex(index: Int)

Values

pub fn get(slab: Slab(a), index: Int) -> option.Option(a)

Index into the slab and retrieve a value

pub fn get_values(slab: Slab(a)) -> List(#(Int, a))

Retrieve a list of the occupied values and their corresponding indexes

pub fn insert(slab: Slab(a), value: a) -> #(Slab(a), Int)

Insert an item into the slab

pub fn insert_many(
  slab: Slab(a),
  values: List(a),
) -> #(Slab(a), List(Int))

Insert several items into the slab

pub fn length(slab: Slab(a)) -> Int

Returns the amount of items in the slab (including vacant slots)

pub fn new() -> Slab(a)

Create a new slab container

pub fn remove(
  slab: Slab(a),
  index: Int,
) -> Result(#(Slab(a), a), SlabError)

Remove an entry from the slab

pub fn remove_many(
  slab: Slab(a),
  indexes: List(Int),
) -> #(Slab(a), List(a))

Remove several items from a slab at once

Search Document