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 :: (HasCallStack, 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
- newtype Handle s = Handle {}
- newHandle :: PrimMonad m => Index -> m (Handle (PrimState m))
- nullHandle :: PrimMonad m => Handle (PrimState m) -> m Bool
- invalidateHandle :: PrimMonad m => Handle (PrimState m) -> m ()
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.
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
modify :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> (a -> a) -> Index -> m () Source #
O(1) Modifies the k-th value.
Constraints
- 0≤i<n
exchange :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> Index -> a -> m a Source #
O(1) Exchanges the k-th value.
Constraints
- 0≤i<n
Handle
newHandle :: PrimMonad m => Index -> m (Handle (PrimState m)) Source #
O(1) Creates a new sequence Handle
from a root node index.
Since: 1.2.0.0