hashmap-1.2.0.0: Persistent containers Map and Set based on hashing.

Portabilityportable
Stabilityprovisional
Maintainerfox@ucw.cz

Data.HashMap

Contents

Description

Persistent Map based on hashing, which is defined as

   data Map k v = Data.IntMap.IntMap (Some k v)

is an Data.IntMap.IntMap indexed by hash values of keys, containing a value of Some e. That contains either one (k, v) pair or a Data.Map.Map k v with keys of the same hash values.

The interface of a Map is a suitable subset of Data.IntMap.IntMap and can be used as a drop-in replacement of Data.Map.Map.

The complexity of operations is determined by the complexities of Data.IntMap.IntMap and Data.Map.Map operations. See the sources of Map to see which operations from containers package are used.

Synopsis

Documentation

data Map k v Source

The abstract type of a Map. Its interface is a suitable subset of Data.IntMap.IntMap.

Instances

Typeable2 Map 
Functor (Map k) 
Foldable (Map k) 
Traversable (Map k) 
(Eq k, Eq v) => Eq (Map k v) 
(Data k, Hashable k, Ord k, Data a) => Data (Map k a) 
(Ord k, Ord v) => Ord (Map k v) 
(Read k, Hashable k, Ord k, Read a) => Read (Map k a) 
(Show k, Show a) => Show (Map k a) 
Ord k => Monoid (Map k a) 

type HashMap k v = Map k vSource

The HashMap is a type synonym for Map for backward compatibility. It is deprecated and will be removed in furture releases.

Operators

(!) :: (Hashable k, Ord k) => Map k a -> k -> aSource

Find the value at a key. Calls error when the element can not be found.

(\\) :: Ord k => Map k a -> Map k b -> Map k aSource

Same as difference.

Query

null :: Map k a -> BoolSource

Is the map empty?

size :: Map k a -> IntSource

Number of elements in the map.

member :: (Hashable k, Ord k) => k -> Map k a -> BoolSource

Is the key a member of the map?

notMember :: (Hashable k, Ord k) => k -> Map k a -> BoolSource

Is the key not a member of the map?

lookup :: (Hashable k, Ord k) => k -> Map k a -> Maybe aSource

Lookup the value at a key in the map.

findWithDefault :: (Hashable k, Ord k) => a -> k -> Map k a -> aSource

The expression (findWithDefault def k map) returns the value at key k or returns def when the key is not an element of the map.

Construction

empty :: Map k aSource

The empty map.

singleton :: Hashable k => k -> a -> Map k aSource

A map of one element.

Insertion

insert :: (Hashable k, Ord k) => k -> a -> Map k a -> Map k aSource

Insert a new key/value pair in the map. If the key is already present in the map, the associated value is replaced with the supplied value, i.e. insert is equivalent to insertWith const.

insertWith :: (Hashable k, Ord k) => (a -> a -> a) -> k -> a -> Map k a -> Map k aSource

Insert with a combining function. insertWith f key value mp will insert the pair (key, value) into mp if key does not exist in the map. If the key does exist, the function will insert f new_value old_value.

insertWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k aSource

Insert with a combining function. insertWithKey f key value mp will insert the pair (key, value) into mp if key does not exist in the map. If the key does exist, the function will insert f key new_value old_value.

insertLookupWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> k -> a -> Map k a -> (Maybe a, Map k a)Source

The expression (insertLookupWithKey f k x map) is a pair where the first element is equal to (lookup k map) and the second element equal to (insertWithKey f k x map).

Delete/Update

delete :: (Hashable k, Ord k) => k -> Map k a -> Map k aSource

Delete a key and its value from the map. When the key is not a member of the map, the original map is returned.

adjust :: (Hashable k, Ord k) => (a -> a) -> k -> Map k a -> Map k aSource

Adjust a value at a specific key. When the key is not a member of the map, the original map is returned.

adjustWithKey :: (Hashable k, Ord k) => (k -> a -> a) -> k -> Map k a -> Map k aSource

Adjust a value at a specific key. When the key is not a member of the map, the original map is returned.

update :: (Hashable k, Ord k) => (a -> Maybe a) -> k -> Map k a -> Map k aSource

The expression (update f k map) updates the value x at k (if it is in the map). If (f x) is Nothing, the element is deleted. If it is (Just y), the key k is bound to the new value y.

updateWithKey :: (Hashable k, Ord k) => (k -> a -> Maybe a) -> k -> Map k a -> Map k aSource

The expression (update f k map) updates the value x at k (if it is in the map). If (f k x) is Nothing, the element is deleted. If it is (Just y), the key k is bound to the new value y.

updateLookupWithKey :: (Hashable k, Ord k) => (k -> a -> Maybe a) -> k -> Map k a -> (Maybe a, Map k a)Source

Lookup and update. The function returns original value, if it is updated. This is different behavior than Data.Map.updateLookupWithKey. Returns the original key value if the map entry is deleted.

alter :: (Hashable k, Ord k) => (Maybe a -> Maybe a) -> k -> Map k a -> Map k aSource

The expression (alter f k map) alters the value x at k, or absence thereof. alter can be used to insert, delete, or update a value in an Map.

Combine

Union

union :: Ord k => Map k a -> Map k a -> Map k aSource

The (left-biased) union of two maps. It prefers the first map when duplicate keys are encountered, i.e. (union == unionWith const).

unionWith :: Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k aSource

The union with a combining function.

unionWithKey :: Ord k => (k -> a -> a -> a) -> Map k a -> Map k a -> Map k aSource

The union with a combining function.

unions :: Ord k => [Map k a] -> Map k aSource

The union of a list of maps.

unionsWith :: Ord k => (a -> a -> a) -> [Map k a] -> Map k aSource

The union of a list of maps, with a combining operation.

Difference

difference :: Ord k => Map k a -> Map k b -> Map k aSource

Difference between two maps (based on keys).

differenceWith :: Ord k => (a -> b -> Maybe a) -> Map k a -> Map k b -> Map k aSource

Difference with a combining function.

differenceWithKey :: Ord k => (k -> a -> b -> Maybe a) -> Map k a -> Map k b -> Map k aSource

Difference with a combining function. When two equal keys are encountered, the combining function is applied to the key and both values. If it returns Nothing, the element is discarded (proper set difference). If it returns (Just y), the element is updated with a new value y.

Intersection

intersection :: Ord k => Map k a -> Map k b -> Map k aSource

The (left-biased) intersection of two maps (based on keys).

intersectionWith :: Ord k => (a -> b -> c) -> Map k a -> Map k b -> Map k cSource

The intersection with a combining function.

intersectionWithKey :: Ord k => (k -> a -> b -> c) -> Map k a -> Map k b -> Map k cSource

The intersection with a combining function.

Traversal

Map

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

Map a function over all values in the map.

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

Map a function over all values in the map.

mapAccum :: (a -> b -> (a, c)) -> a -> Map k b -> (a, Map k c)Source

The function mapAccum threads an accumulating argument through the map in unspecified order of keys.

mapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> Map k b -> (a, Map k c)Source

The function mapAccumWithKey threads an accumulating argument through the map in unspecified order of keys.

Fold

fold :: (a -> b -> b) -> b -> Map k a -> bSource

Fold the values in the map, such that fold f z == foldr f z . elems.

foldWithKey :: (k -> a -> b -> b) -> b -> Map k a -> bSource

Fold the keys and values in the map, such that foldWithKey f z == foldr (uncurry f) z . toAscList.

Conversion

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

Return all elements of the map in arbitrary order of their keys.

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

Return all keys of the map in arbitrary order.

keysSet :: Ord k => Map k a -> Set kSource

The set of all keys of the map.

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

Return all key/value pairs in the map in arbitrary key order.

Lists

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

Convert the map to a list of key/value pairs.

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

Create a map from a list of key/value pairs.

fromListWith :: (Hashable k, Ord k) => (a -> a -> a) -> [(k, a)] -> Map k aSource

Create a map from a list of key/value pairs with a combining function.

fromListWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> [(k, a)] -> Map k aSource

Build a map from a list of key/value pairs with a combining function.

Filter

filter :: Ord k => (a -> Bool) -> Map k a -> Map k aSource

Filter all values that satisfy some predicate.

filterWithKey :: Ord k => (k -> a -> Bool) -> Map k a -> Map k aSource

Filter all keys/values that satisfy some predicate.

partition :: Ord k => (a -> Bool) -> Map k a -> (Map k a, Map k a)Source

Partition the map according to some predicate. The first map contains all elements that satisfy the predicate, the second all elements that fail the predicate.

partitionWithKey :: Ord k => (k -> a -> Bool) -> Map k a -> (Map k a, Map k a)Source

Partition the map according to some predicate. The first map contains all elements that satisfy the predicate, the second all elements that fail the predicate.

mapMaybe :: Ord k => (a -> Maybe b) -> Map k a -> Map k bSource

Map values and collect the Just results.

mapMaybeWithKey :: Ord k => (k -> a -> Maybe b) -> Map k a -> Map k bSource

Map keys/values and collect the Just results.

mapEither :: Ord k => (a -> Either b c) -> Map k a -> (Map k b, Map k c)Source

Map values and separate the Left and Right results.

mapEitherWithKey :: Ord k => (k -> a -> Either b c) -> Map k a -> (Map k b, Map k c)Source

Map keys/values and separate the Left and Right results.

Submap

isSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> BoolSource

Is this a submap?

isSubmapOfBy :: Ord k => (a -> b -> Bool) -> Map k a -> Map k b -> BoolSource

The expression (isSubmapOfBy f m1 m2) returns True if all keys in m1 are in m2, and when f returns True when applied to their respective values.

isProperSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> BoolSource

Is this a proper submap? (ie. a submap but not equal).

isProperSubmapOfBy :: Ord k => (a -> b -> Bool) -> Map k a -> Map k b -> BoolSource

Is this a proper submap? (ie. a submap but not equal). The expression (isProperSubmapOfBy f m1 m2) returns True when m1 and m2 are not equal, all keys in m1 are in m2, and when f returns True when applied to their respective values.