Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
AtCoder.Extra.Pool
Description
Fixed-sized array for O(1) allocation and O(1) clearing after O(n) construction.
Synopsis
- data Pool s a = Pool {}
- newtype Index = Index {}
- undefIndex :: Index
- nullIndex :: Index -> Bool
- new :: (Unbox a, PrimMonad m) => Int -> m (Pool (PrimState m) a)
- clear :: PrimMonad m => Pool (PrimState m) a -> m ()
- capacity :: Unbox a => Pool s a -> Int
- size :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> m Int
- alloc :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> a -> m Index
- free :: PrimMonad m => Pool (PrimState m) a -> Index -> m ()
- read :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> Index -> m a
- write :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> Index -> a -> m ()
- modify :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> (a -> a) -> Index -> m ()
- exchange :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> Index -> a -> m a
Pool
Fixed-sized array for O(1) allocation and O(1) clearing after O(n) construction.
Strongly typed index of pool items. User has to explicitly corece
on raw index use, but it's
ok as far as the end user don't see it.
Instances
undefIndex :: Index Source #
Invalid, null Index
.
Constructors
new :: (Unbox a, PrimMonad m) => Int -> m (Pool (PrimState m) a) Source #
O(n) Creates a pool with the specified capacity
.
clear :: PrimMonad m => Pool (PrimState m) a -> m () Source #
O(1) Resets the pool to the initial state.
Metadata
capacity :: Unbox a => Pool s a -> Int Source #
O(1) Returns the maximum number of elements the pool can store.
size :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> m Int Source #
O(1) Returns the number of elements in the pool.
Allocations
free :: PrimMonad m => Pool (PrimState m) a -> Index -> m () Source #
O(1) Frees an element. Be sure to not free a deleted element.
Constraints
- 0≤i<n
Read/write
read :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> Index -> m a Source #
O(1) Reads the k-th value.
Constraints
- 0≤i<n
write :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> Index -> a -> m () Source #
O(1) Writes to the k-th value.
Constraints
- 0≤i<n