Loading [MathJax]/jax/output/HTML-CSS/jax.js
ac-library-hs-1.4.0.0: Data structures and algorithms
Safe HaskellNone
LanguageGHC2021

AtCoder.Extra.Pool

Description

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

Synopsis

Pool

data Pool s a Source #

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

Since: 1.2.0.0

Constructors

Pool 

Fields

newtype Index Source #

Strongly typed index of pool items. User has to explicitly corece on raw index use.

Since: 1.2.0.0

Constructors

Index 

Fields

Instances

Instances details
Show Index Source # 
Instance details

Defined in AtCoder.Extra.Pool

Methods

showsPrec :: Int -> Index -> ShowS #

show :: Index -> String #

showList :: [Index] -> ShowS #

Eq Index Source #

Since: 1.2.0.0

Instance details

Defined in AtCoder.Extra.Pool

Methods

(==) :: Index -> Index -> Bool #

(/=) :: Index -> Index -> Bool #

Ord Index Source # 
Instance details

Defined in AtCoder.Extra.Pool

Methods

compare :: Index -> Index -> Ordering #

(<) :: Index -> Index -> Bool #

(<=) :: Index -> Index -> Bool #

(>) :: Index -> Index -> Bool #

(>=) :: Index -> Index -> Bool #

max :: Index -> Index -> Index #

min :: Index -> Index -> Index #

Prim Index Source #

Since: 1.2.0.0

Instance details

Defined in AtCoder.Extra.Pool

Unbox Index Source #

Since: 1.2.0.0

Instance details

Defined in AtCoder.Extra.Pool

Vector Vector Index Source #

Since: 1.2.0.0

Instance details

Defined in AtCoder.Extra.Pool

MVector MVector Index Source #

Since: 1.2.0.0

Instance details

Defined in AtCoder.Extra.Pool

newtype Vector Index Source #

Since: 1.2.0.0

Instance details

Defined in AtCoder.Extra.Pool

newtype Vector Index = V_Index (Vector Index)
newtype MVector s Index Source #

Since: 1.2.0.0

Instance details

Defined in AtCoder.Extra.Pool

newtype MVector s Index = MV_Index (MVector s Index)

undefIndex :: Index Source #

Invalid, null Index.

Since: 1.2.0.0

nullIndex :: Index -> Bool Source #

Returns True for undefIndex.

Since: 1.2.0.0

Constructors

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

O(n) Creates a pool with the specified capacity.

Since: 1.2.0.0

clear :: PrimMonad m => Pool (PrimState m) a -> m () Source #

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

Since: 1.2.0.0

Metadata

capacity :: Unbox a => Pool s a -> Int Source #

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

Since: 1.2.0.0

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

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

Since: 1.2.0.0

Allocations

alloc :: (HasCallStack, PrimMonad m, Unbox a) => Pool (PrimState m) a -> a -> m Index Source #

O(1) Allocates a new element.

Constraints

  • The number of elements must not exceed the capacity.

Since: 1.2.0.0

free :: PrimMonad m => Pool (PrimState m) a -> Index -> m () Source #

O(1) Frees an element. Be sure to not free a deleted element.

Constraints

  • 0i<n

Since: 1.2.0.0

Read/write

read :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> Index -> m a Source #

O(1) Reads the k-th value.

Constraints

  • 0i<n

Since: 1.2.0.0

write :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> Index -> a -> m () Source #

O(1) Writes to the k-th value.

Constraints

  • 0i<n

Since: 1.2.0.0

modify :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> (a -> a) -> Index -> m () Source #

O(1) Given a user function f, modifies the k-th value with it.

Constraints

  • 0i<n

Since: 1.2.0.0

exchange :: (PrimMonad m, Unbox a) => Pool (PrimState m) a -> Index -> a -> m a Source #

O(1) Exchanges the k-th value.

Constraints

  • 0i<n

Since: 1.2.0.0

Handle

newtype Handle s Source #

Mutable Handle of an Index.

Since: 1.2.0.0

Constructors

Handle 

Fields

newHandle :: PrimMonad m => Index -> m (Handle (PrimState m)) Source #

O(1) Creates a new Handle from a root node index.

Since: 1.2.0.0

nullHandle :: PrimMonad m => Handle (PrimState m) -> m Bool Source #

O(1) Returns whether the handle represents null.

Since: 1.2.0.0

invalidateHandle :: PrimMonad m => Handle (PrimState m) -> m () Source #

O(1) Invalidates a handle. Note that it does not change or free the pool item.

Since: 1.2.0.0