Safe Haskell | None |
---|---|
Language | Haskell2010 |
See Data.Rsv for an overview of what "reservation" data structures are.
This module implements a relative-key multi-map, where each structure has an idea of "the current key", each insert is indexed by a key-offset relative to the current, and many independent inserts may be performed on the same key.
Currently keys are constrainted by (
. If you have trouble
finding a RMMap
k, Monoid
k)Monoid
instance for a Num
type, that's because it's not there;
see https://wiki.haskell.org/Monoid#Examples on why. In practise, you can
probably just wrap your Num
in a Sum
.
- data RRelMMap k a
- empty :: (Ord k, Monoid k) => RRelMMap k a
- isEmpty :: RRelMMap k a -> Bool
- current :: RRelMMap k a -> k
- (!) :: Ord k => RRelMMap k a -> k -> [a]
- setCurrent :: Ord k => k -> RRelMMap k a -> RRelMMap k a
- insertAfter :: (Ord k, Monoid k) => k -> a -> RRelMMap k a -> (Delete k a, RRelMMap k a)
- type Delete k a = RRelMMap k a -> (Maybe a, RRelMMap k a)
- deleteKey :: Ord k => k -> RRelMMap k a -> RRelMMap k a
- sSetCurrent :: (Ord k, Monad m) => k -> StateT (RRelMMap k a) m ()
- sInsertAfter :: (Ord k, Monoid k, Monad m) => k -> a -> StateT (RRelMMap k a) m (SDelete k a m)
- type SDelete k a m = StateT (RRelMMap k a) m (Maybe a)
- sDeleteKey :: (Ord k, Monad m) => k -> StateT (RRelMMap k a) m ()
Documentation
Read operations
Write operations
setCurrent :: Ord k => k -> RRelMMap k a -> RRelMMap k a Source
Advance to a given key
type Delete k a = RRelMMap k a -> (Maybe a, RRelMMap k a) Source
A map-transition that removes and retrieves the earlier-added item.
If the item was already removed, Nothing
is returned instead.
Write operations in StateT
sSetCurrent :: (Ord k, Monad m) => k -> StateT (RRelMMap k a) m () Source
Same as setCurrent
except in the StateT
monad
sInsertAfter :: (Ord k, Monoid k, Monad m) => k -> a -> StateT (RRelMMap k a) m (SDelete k a m) Source
Same as insertAfter
except in the StateT
monad