toy-lib-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Pool

Description

Fixed-sized array for \(O(1)\) allocation and \(O(1)\) clearing after \(O(N)\) construction.

Synopsis

Documentation

data Pool s a #

Fixed-sized array for \(O(1)\) allocation.

Constructors

Pool 

Fields

type PoolIndex = Int #

Index of an element in the Pool.

undefPI :: PoolIndex #

Invalid, null PoolIndex.

nullPI :: PoolIndex -> Bool #

Returns True if the index is invalid.

newPool :: (Unbox a, PrimMonad m) => Int -> m (Pool (PrimState m) a) #

\(O(N)\) Creates a pool with the specified capacity.

capacityPool :: Unbox a => Pool s a -> Int #

\(O(1)\) Returns the maximum number of elements the pool can store.

sizePool :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> m Int #

\(O(1)\) Returns the number of elements in the pool.

clearPool :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> m () #

\(O(1)\) Resets the pool to the initial state.

allocPool :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> a -> m PoolIndex #

\(O(1)\) Allocates a new element. TODO: capacity validation?

deallocPool :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> PoolIndex -> m () #

\(O(1)\) Deallocates an element. Be sure to not deallocate a deleted element. TODO: consider setting up validation of slots?