slotmap-0.1.0.0: Pure Haskell slotmap implementation over ST or IO.

Safe HaskellNone
LanguageHaskell2010

Data.SlotMap

Contents

Synopsis

Documentation

data Key Source #

Weak reference to a SlotMap item.

data SlotMap m a Source #

Opaque SlotMap structure.

Construction

empty :: PrimMonad m => m (SlotMap m a) Source #

Allocate empty SlotMap instance.

clone :: PrimMonad m => SlotMap m a -> m (SlotMap m a) Source #

Allocate new SlotMap and copy. Maintains keys.

Constant Operations

lookup :: PrimMonad m => Key -> SlotMap m a -> m (Maybe a) Source #

Return value associated with key or Nothing if the slot is empty O(1).

delete :: PrimMonad m => Key -> SlotMap m a -> m () Source #

Delete value at key and mark slot for reuse O(1).

unsafeDelete :: PrimMonad m => Key -> SlotMap m a -> m () Source #

Same as delete but does not validate the key O(1).

insert :: PrimMonad m => a -> SlotMap m a -> m Key Source #

Insert a new element into the SlotMap returning a key O(1). This function may cause an allocation if the SlotMap is full.

update :: PrimMonad m => SlotMap m a -> (a -> a) -> Key -> m () Source #

Update item at existing slot O(1). Does nothing if the key is invalid.

unsafeUpdate :: PrimMonad m => SlotMap m a -> (a -> a) -> Key -> m () Source #

Same as update but does not validate the key O(1).

null :: PrimMonad m => SlotMap m a -> m Bool Source #

Check if SlotMap is empty O(1).

capacity :: PrimMonad m => SlotMap m a -> m Int Source #

Total number of slots in the SlotMap O(1).

size :: PrimMonad m => SlotMap m a -> m Int Source #

Number of elements in the SlotMap O(1).

Linear Operations

foldr :: PrimMonad m => (a -> b -> b) -> b -> SlotMap m a -> m b Source #

Fold over every full slot O(N) where N = capacity.

map :: PrimMonad m => (a -> a) -> SlotMap m a -> m () Source #

Apply function to every full slot O(N) where N = capacity.

elems :: PrimMonad m => SlotMap m a -> m [a] Source #

Get every element of a SlotMap as a list O(N) where N = capacity.