An implementation of bidirectional maps between values of two
key types. A Bimap
is essentially a bijection between subsets of
its two argument types.
Most functions implicitly consider the left-hand type to be the
key, and the right-hand type to be the value.
Functions with an R
suffix reverse this convention, treating the
left-hand type as the key.
- data Bimap a b
- null :: Bimap a b -> Bool
- size :: Bimap a b -> Int
- member :: (Ord a, Ord b) => a -> Bimap a b -> Bool
- memberR :: (Ord a, Ord b) => b -> Bimap a b -> Bool
- notMember :: (Ord a, Ord b) => a -> Bimap a b -> Bool
- notMemberR :: (Ord a, Ord b) => b -> Bimap a b -> Bool
- pairMember :: (Ord a, Ord b) => (a, b) -> Bimap a b -> Bool
- pairNotMember :: (Ord a, Ord b) => (a, b) -> Bimap a b -> Bool
- lookup :: (Ord a, Ord b, Monad m) => a -> Bimap a b -> m b
- lookupR :: (Ord a, Ord b, Monad m) => b -> Bimap a b -> m a
- (!) :: (Ord a, Ord b) => Bimap a b -> a -> b
- (!>) :: (Ord a, Ord b) => Bimap a b -> b -> a
- empty :: Bimap a b
- singleton :: a -> b -> Bimap a b
- insert :: (Ord a, Ord b) => a -> b -> Bimap a b -> Bimap a b
- delete :: (Ord a, Ord b) => a -> Bimap a b -> Bimap a b
- deleteR :: (Ord a, Ord b) => b -> Bimap a b -> Bimap a b
- fromList :: (Ord a, Ord b) => [(a, b)] -> Bimap a b
- toList :: Bimap a b -> [(a, b)]
- toAscList :: Bimap a b -> [(a, b)]
- toAscListR :: Bimap a b -> [(b, a)]
- keys :: Bimap a b -> [a]
- keysR :: Bimap a b -> [b]
- elems :: Bimap a b -> [b]
- assocs :: Bimap a b -> [(a, b)]
- fold :: (a -> b -> c -> c) -> c -> Bimap a b -> c
- valid :: (Ord a, Ord b) => Bimap a b -> Bool
- twist :: Bimap a b -> Bimap b a
- twisted :: (Bimap a b -> Bimap a b) -> Bimap b a -> Bimap b a
Bimap type
A bidirectional map between values of types a
and b
.
Query
member :: (Ord a, Ord b) => a -> Bimap a b -> BoolSource
Is the specified value a member of the bimap?
memberR :: (Ord a, Ord b) => b -> Bimap a b -> BoolSource
A version of member
specialized to the right key.
notMember :: (Ord a, Ord b) => a -> Bimap a b -> BoolSource
Is the specified value not a member of the bimap?
notMemberR :: (Ord a, Ord b) => b -> Bimap a b -> BoolSource
A version of notMember
specialized to the right key.
pairMember :: (Ord a, Ord b) => (a, b) -> Bimap a b -> BoolSource
Are the two values associated with each other in the bimap?
This function is uncurried in its first two arguments, so that it can be used infix.
pairNotMember :: (Ord a, Ord b) => (a, b) -> Bimap a b -> BoolSource
Are the two values not in the bimap, or not associated with
each other? (Complement of pairMember
.)
lookup :: (Ord a, Ord b, Monad m) => a -> Bimap a b -> m bSource
Lookup a left key in the bimap, returning the associated right key.
This function will return
the result in the monad, or fail
if
the value isn't in the bimap.
lookupR :: (Ord a, Ord b, Monad m) => b -> Bimap a b -> m aSource
A version of lookup
that is specialized to the right key,
and returns only the left key.
(!) :: (Ord a, Ord b) => Bimap a b -> a -> bSource
Find the right key corresponding to a given left key.
Calls
when the key is not in the bimap.
error
(!>) :: (Ord a, Ord b) => Bimap a b -> b -> aSource
A version of (!)
that is specialized to the right key,
and returns only the left key.
Construction
Update
insert :: (Ord a, Ord b) => a -> b -> Bimap a b -> Bimap a bSource
Insert a pair of values into the bimap, associating them. If either of the values is already in the bimap, any overlapping bindings are deleted.
delete :: (Ord a, Ord b) => a -> Bimap a b -> Bimap a bSource
Delete a value and its twin from a bimap. When the value is not a member of the bimap, the original bimap is returned.
deleteR :: (Ord a, Ord b) => b -> Bimap a b -> Bimap a bSource
A version of delete
specialized to the right key.
Conversion/traversal
fromList :: (Ord a, Ord b) => [(a, b)] -> Bimap a bSource
Build a map from a list of pairs. If there are any overlapping pairs in the list, the later ones will override the earlier ones.
toAscList :: Bimap a b -> [(a, b)]Source
Convert to a list of associated pairs, with the left-hand values in ascending order. Since pair ordering is lexical, the pairs will also be in ascending order.
toAscListR :: Bimap a b -> [(b, a)]Source
Convert to a list of associated pairs, with the right-hand values first in the pair and in ascending order. Since pair ordering is lexical, the pairs will also be in ascending order.
assocs :: Bimap a b -> [(a, b)]Source
Return all associated pairs in the bimap, with the left-hand values in ascending order.