Skip to content
FutureBlitz

    Install

    Import std.collections.pool

    std.collections.pool

    Values kept by Handles, which find nothing once their value is removed.

    Pool<T>: values kept by Handles that stay valid until their value is removed, like a scene's objects. A removed value's slot is reused, and its Generation counts how many times, so an old Handle to it finds nothing. Generations start at 1, so a Handle's zero finds nothing too.

    std/collections/pool.fb

    Types

    Handle struct

    Public Struct Handle<T> Implements Hashable

    Where a value is in its Pool, which only the Pool makes. Two are equal when they're the same value's, so a Handle can be a Map's key or a Set's value.

    Examples

    Local pool = Pool<String>()
    Local a = pool.Add("a")
    Local names = {a: "first"}
    Expect(names.Contains(a) && pool.Get(a) == "a")

    std/collections/pool.fb, line 20

    • Public ReadOnly Field Index: Int field #

      Its slot in the Pool.

    Pool class

    @DebugElements Public Class Pool<T> Implements Iterable<T>, Cloneable, Defaultable

    Values kept by Handles that stay valid until their value is removed, reusing removed values' slots.

    Examples

    Local names = Pool<String>()
    Local ada = names.Add("Ada")
    names.Add("Alan")
    Expect(names.Get(ada) == "Ada")
    Expect(names.Remove(ada))
    Expect(names.Get(ada) == Null)
    // Grace takes Ada's slot, but Ada's Handle still finds nothing.
    Local grace = names.Add("Grace")
    Expect(grace.Index == ada.Index && names.Get(ada) == Null)
    Expect(names.Count == 2)

    std/collections/pool.fb, line 43

    • Public Property Count: Int property #

      How many values it holds.

    • Public Property Capacity: Int property #

      How many values it has slots for before it needs more memory.

    • @PanicsAtCaller Public Method Reserve(count: Int) method #

      Makes room for count slots in all, so adding up to that many values doesn't move them again.

    • Public Method Add(value: T): Handle<T> method #

      Adds the value, and gives its Handle.

    • Public Method Get(handle: Handle<T>): T? method #

      The handle's value, or Null once it's removed.

    • Public Method Set(handle: Handle<T>, value: T): Bool method #

      Gives the handle's value a new value, and tells whether it's still there.

    • Public Method Contains(handle: Handle<T>): Bool method #

      Whether the handle's value is still there: its slot hasn't been emptied since.

    • Public Method Remove(handle: Handle<T>): Bool method #

      Removes the handle's value, and tells whether it was there.

    • Public Method Clear() method #

      Removes every value. Their Handles find nothing after.

    • Public Static Method DefaultValue(): Pool<T> static method #

      A new, empty Pool.

    • Public Method Clone(): Pool<T> method #

      A new Pool with the same values, which the same Handles find.

    • Public Method Iterate(): PoolIterator<T> method #

      The values, in the order of their slots. Removing values while going over them is fine.

    • Public Method IterateHandles(): PoolHandles<T> method #

      Each value with its Handle, in the order of their slots, for 'For handle, value In pool.IterateHandles()'. Removing values while going over them is fine.

    PoolIterator struct

    Public Struct PoolIterator<T> Implements Iterator<T>

    The values of a Pool, in slot order, which a For loop goes over.

    std/collections/pool.fb, line 151

    • Public ByRef Method Next(): T? method #

      The next value, by slot, or Null after the last.

    PoolHandles struct

    Public Struct PoolHandles<T> Implements Iterator<(Handle<T>, T)>

    The values of a Pool with their Handles, as (handle, value), in slot order.

    std/collections/pool.fb, line 166

    • Public ByRef Method Next(): (Handle<T>, T)? method #

      The next value with its Handle, by slot, or Null after the last.

    Report an issue with this page or with FutureBlitz on GitHub.