hashmap-1.0.0.2: Persistent containers HashMap and HashSet.

Portabilityportable
Stabilityprovisional
Maintainerfox@ucw.cz

Data.HashMap

Contents

Description

Persistent HashMap, which is defined as

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

is an Data.IntMap.IntMap indexed by hash values of keys, containing a map Data.Map.Map k v with keys of the same hash values.

The interface of a HashMap is a suitable subset of Data.IntMap.IntMap.

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

Synopsis

Documentation

data HashMap k v Source

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

Instances

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

Operators

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

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

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

Same as difference.

Query

null :: HashMap k a -> BoolSource

Is the map empty?

size :: HashMap k a -> IntSource

Number of elements in the map.

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

Is the key a member of the map?

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

Is the key not a member of the map?

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

Lookup the value at a key in the map.

findWithDefault :: (Hashable k, Ord k) => a -> k -> HashMap 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 :: HashMap k aSource

The empty map.

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

A map of one element.

Insertion

insert :: (Hashable k, Ord k) => k -> a -> HashMap k a -> HashMap 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 -> HashMap k a -> HashMap 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 -> HashMap k a -> HashMap 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 -> HashMap k a -> (Maybe a, HashMap 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 -> HashMap k a -> HashMap 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 -> HashMap k a -> HashMap 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 -> HashMap k a -> HashMap 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 -> HashMap k a -> HashMap 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 -> HashMap k a -> HashMap 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 -> HashMap k a -> (Maybe a, HashMap 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 -> HashMap k a -> HashMap 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 HashMap.

Combine

Union

union :: Ord k => HashMap k a -> HashMap k a -> HashMap 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) -> HashMap k a -> HashMap k a -> HashMap k aSource

The union with a combining function.

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

The union with a combining function.

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

The union of a list of maps.

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

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

Difference

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

Difference between two maps (based on keys).

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

Difference with a combining function.

differenceWithKey :: Ord k => (k -> a -> b -> Maybe a) -> HashMap k a -> HashMap k b -> HashMap 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 => HashMap k a -> HashMap k b -> HashMap k aSource

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

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

The intersection with a combining function.

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

The intersection with a combining function.

Traversal

Map

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

Map a function over all values in the map.

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

Map a function over all values in the map.

mapAccum :: (a -> b -> (a, c)) -> a -> HashMap k b -> (a, HashMap 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 -> HashMap k b -> (a, HashMap k c)Source

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

Fold

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

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

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

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

Conversion

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

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

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

Return all keys of the map in arbitrary order.

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

The set of all keys of the map.

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

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

Lists

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

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

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

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

fromListWith :: (Hashable k, Ord k) => (a -> a -> a) -> [(k, a)] -> HashMap 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)] -> HashMap k aSource

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

Filter

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

Filter all values that satisfy some predicate.

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

Filter all keys/values that satisfy some predicate.

partition :: Ord k => (a -> Bool) -> HashMap k a -> (HashMap k a, HashMap 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) -> HashMap k a -> (HashMap k a, HashMap 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) -> HashMap k a -> HashMap k bSource

Map values and collect the Just results.

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

Map keys/values and collect the Just results.

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

Map values and separate the Left and Right results.

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

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

Submap

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

Is this a submap?

isSubmapOfBy :: Ord k => (a -> b -> Bool) -> HashMap k a -> HashMap 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) => HashMap k a -> HashMap k a -> BoolSource

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

isProperSubmapOfBy :: Ord k => (a -> b -> Bool) -> HashMap k a -> HashMap 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.