template <typename T, typename KeyType = size_t>

class GrowableSlab

Defined at line 29 of file ../../src/lib/vmo_store/growable_slab.h

A slab data structure to store items of type `T` keyed by `KeyType`.

`KeyType` must be an integer type, it is used to index an underlying vector storage of `T`.

`GrowableSlab` is always created with zero capacity and can grow in capacity up to the maximum

namespace of `std::numeric_limits

<KeyType

>::max()-1`.

`GrowableSlab` acts as a container for `T` with O(1) guarantee on `Push`, `Insert`, `Get`, and

`Erase` operations, and O(capacity) on `Grow`.

This structure is not thread-safe.

Public Methods

void GrowableSlab<T, KeyType> ()

Defined at line 36 of file ../../src/lib/vmo_store/growable_slab.h

KeyType capacity ()

Returns the currently allocated capacity of the slab.

Defined at line 39 of file ../../src/lib/vmo_store/growable_slab.h

KeyType count ()

Returns the number of items held by the slab.

Defined at line 41 of file ../../src/lib/vmo_store/growable_slab.h

KeyType free ()

Returns the number of free slots available on the slab.

Defined at line 43 of file ../../src/lib/vmo_store/growable_slab.h

bool is_empty ()

Defined at line 45 of file ../../src/lib/vmo_store/growable_slab.h

void Grow ()

Grows the slab by a fixed factor if there are no more free slots.

Note that the worst-case complexity for `Grow` is O(new_capacity).

Defined at line 50 of file ../../src/lib/vmo_store/growable_slab.h

void GrowTo (KeyType capacity)

Defined at line 56 of file ../../src/lib/vmo_store/growable_slab.h

std::optional<KeyType> Push (T && value)

Inserts `value` on the slab, using a key from the available pool.

Returns a valid `KeyType` if there was an available slot to put `value` in.

Defined at line 67 of file ../../src/lib/vmo_store/growable_slab.h

zx_status_t Insert (KeyType key, T && value)

Attempts to insert `value` at slot `key` in the slab.

Returns `ZX_ERR_OUT_OF_RANGE` if `key` is not in the valid namespace.

Returns `ZX_ERR_ALREADY_EXISTS` if `key` is already occupied by another value.

Defined at line 78 of file ../../src/lib/vmo_store/growable_slab.h

T * Get (KeyType key)

Gets the value `T` stored at `key`.

Returns `nullptr` if `key` is invalid or the slot is not occupied.

Defined at line 97 of file ../../src/lib/vmo_store/growable_slab.h

std::optional<T> Erase (KeyType key)

Erases the value at `key`, freeing the slot and returning the stored value.

`Erase` returns a valid `T` if `key` pointed to an occupied slot.

Defined at line 107 of file ../../src/lib/vmo_store/growable_slab.h

void Clear ()

Removes all currently stored values from the slab, returning all slots to the free-list.

Defined at line 123 of file ../../src/lib/vmo_store/growable_slab.h

Iterator begin ()

TODO(https://fxbug.dev/42078992): Create a separate ConstIterator class for const

begin() and end() iterators.

Defined at line 131 of file ../../src/lib/vmo_store/growable_slab.h

Iterator end ()

Defined at line 133 of file ../../src/lib/vmo_store/growable_slab.h

void GrowableSlab<T, KeyType> (const GrowableSlab<T, KeyType> & )

Defined at line 201 of file ../../src/lib/vmo_store/growable_slab.h

GrowableSlab<T, KeyType> & operator= (const GrowableSlab<T, KeyType> & )

Defined at line 201 of file ../../src/lib/vmo_store/growable_slab.h

Records