multimap-1.2.1: A multimap.

Portabilitynon-portable (DeriveDataTypeable)
Maintainerjulian.fleischer@fu-berlin.de
Safe HaskellSafe-Inferred

Data.MultiMap

Contents

Description

A very simple MultiMap, based on Map from the containers package.

Synopsis

MultiMap type

data MultiMap k v Source

A MultiMap with keys k and values v.

A key can have multiple values (but not zero). The same value can be added multiple times (thus no constraints are ever imposed on v).

Internally this is simply a Map k [v]. See toMap for accessing the underlying Map.

Instances

Typeable2 MultiMap 
(Data k, Data v, Ord k) => Data (MultiMap k v) 

Query

null :: MultiMap k a -> BoolSource

O(1). Check whether the multimap is empty or not.

size :: MultiMap k a -> IntSource

O(1). The number of elements in the multimap.

numKeys :: MultiMap k a -> Word32Source

O(1). The number of keys in the multimap.

As this is a multimap, the number of keys is not necessarily equal to the number of values.

numValues :: MultiMap k a -> Word32Source

O(1). The number of values in the multimap.

As this is a multimap, the number of keys is not necessarily equal to the number of values.

member :: Ord k => MultiMap k a -> k -> BoolSource

O(log n). Is the key a member of the multimap?

notMember :: Ord k => MultiMap k a -> k -> BoolSource

O(log n). Is the key not a member of the multimap?

lookup :: Ord k => k -> MultiMap k a -> [a]Source

O(log n). Lookup the value at a key in the map.

The function will return the corrsponding values as a List, or the empty list if no values are associated witht the given key.

Operators

(!) :: Ord k => MultiMap k a -> k -> [a]Source

As flip lookup

Construction

empty :: MultiMap k aSource

O(1). The empty multimap.

Insertion

insert :: Ord k => k -> a -> MultiMap k a -> MultiMap k aSource

O(log n). Insert a new key and value in the map.

Delete

delete :: Ord k => k -> MultiMap k a -> MultiMap k aSource

O(log n). Delete a key and all its values from the map.

Traversal

map :: (a -> b) -> MultiMap k a -> MultiMap k bSource

Map a function over all values in the map.

mapKeys :: Ord k2 => (k1 -> k2) -> MultiMap k1 a -> MultiMap k2 aSource

mapKeys f s is the multimap obtained by applying f to each key of s.

mapWithKey :: (k -> a -> b) -> MultiMap k a -> MultiMap k bSource

Map a function over all key/value pairs in the map.

Folds

foldr :: (a -> b -> b) -> b -> MultiMap k a -> bSource

Fold the values in the map using the given right-associative binary operator.

foldl :: (a -> b -> a) -> a -> MultiMap k b -> aSource

Fold the values in the map using the given left-associative binary operator.

foldrWithKey :: (k -> a -> b -> b) -> b -> MultiMap k a -> bSource

O(n). Fold the keys and values in the map using the given right-associative binary operator, taking into account not only the value but also the key.

foldlWithKey :: (a -> k -> b -> a) -> a -> MultiMap k b -> aSource

O(n). Fold the keys and values in the map using the given left-associative binary operator, taking into account not only the value but also the key.

Conversion

elems :: MultiMap k a -> [[a]]Source

O(n). Return all elements of the multimap in the ascending order of their keys.

A list of lists is returned since a key can have multiple values. Use concat to flatten.

keys :: MultiMap k a -> [k]Source

O(n). Return all keys of the multimap in ascending order.

keysSet :: MultiMap k a -> Set kSource

O(n). The set of all keys of the multimap.

assocs :: MultiMap k a -> [(k, [a])]Source

O(n). Return all key/value pairs in the multimap in ascending key order.

toMap :: MultiMap k a -> Map k [a]Source

O(1). Return the map of lists.

toMapOfSets :: Ord a => MultiMap k a -> Map k (Set a)Source

/O(k*m*log m) where k is the number of keys and m the maximum number of elements associated with a single key/

toList :: MultiMap k a -> [(k, a)]Source

Return a flattened list of key/value pairs.

fromList :: Ord k => [(k, a)] -> MultiMap k aSource

O(n*log n) Create a multimap from a list of key/value pairs.

 fromList xs == foldr (uncurry insert) empty

fromMap :: Map k [a] -> MultiMap k aSource

Turns a map of lists into a multimap.

Min/Max

findMin :: MultiMap k a -> Maybe kSource

O(log n) Find the minimal key of the multimap.

findMax :: MultiMap k a -> Maybe kSource

O(log n) Find the maximal key of the multimap.

findMinWithValues :: MultiMap k a -> Maybe (k, [a])Source

O(log n) Find the minimal key and the values associated with it.

findMaxWithValues :: MultiMap k a -> Maybe (k, [a])Source

O(log n) Find the maximal key and the values associated with it.