O(n) Return a list of this map's keys. The list is produced
lazily.
Modulerebase-1.21.2Haskell2010
Rebase.Data.HashMap.Strict
- 1 type
- 56 values
- Packagerebase-1.21.2
- Exports57
- LanguageHaskell2010
- LicenceMIT
- SourceInternal.hs
O(n) Return a list of this map's elements. The list is
produced lazily. The order of its elements is unspecified, and it may
change from version to version of either this package or of hashable.
O(n) Reduce this map by applying a binary operator to all
elements, using the given starting value (typically the
left-identity of the operator).
O(n) Reduce this map by applying a binary operator to all
elements, using the given starting value (typically the
right-identity of the operator).
A map from keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
Instances41Bifoldable, Eq2, Ord2, Show2, NFData2, Hashable2, …
Bifoldable HashMapDefined in unordered-containers-0.2.21 · Data.HashMap.InternalEq2 HashMapDefined in unordered-containers-0.2.21 · Data.HashMap.InternalOrd2 HashMapDefined in unordered-containers-0.2.21 · Data.HashMap.InternalShow2 HashMapDefined in unordered-containers-0.2.21 · Data.HashMap.InternalNFData2 HashMapDefined in unordered-containers-0.2.21 · Data.HashMap.InternalHashable2 HashMapDefined in unordered-containers-0.2.21 · Data.HashMap.Internal(Lift k, Lift v) => Lift (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalFunctor (HashMap k)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalFoldable (HashMap k)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalTraversable (HashMap k)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalEq k => Eq1 (HashMap k)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalOrd k => Ord1 (HashMap k)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal(Hashable k, Read k) => Read1 (HashMap k)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalShow k => Show1 (HashMap k)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalNFData k => NFData1 (HashMap k)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalHashable k => Hashable1 (HashMap k)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal(Hashable k, Eq k) => Alt (HashMap k)Defined in semigroupoids-6.0.1 · Data.Functor.Alt(Hashable k, Eq k) => Apply (HashMap k)Defined in semigroupoids-6.0.1 · Data.Functor.Bind.ClassA 'HashMap k' is not Applicative, but it is an instance of Apply
(Hashable k, Eq k) => Bind (HashMap k)Defined in semigroupoids-6.0.1 · Data.Functor.Bind.Class(Hashable k, Eq k) => Plus (HashMap k)Defined in semigroupoids-6.0.1 · Data.Functor.PlusInvariant (HashMap k)Defined in invariant-0.6.4 · Data.Functor.Invariantfrom the
unordered-containerspackageFoldableWithKey (HashMap k)Defined in keys-3.12.3 · Data.Key(Eq k, Hashable k) => Indexable (HashMap k)Defined in keys-3.12.3 · Data.KeyKeyed (HashMap k)Defined in keys-3.12.3 · Data.Key(Eq k, Hashable k) => Lookup (HashMap k)Defined in keys-3.12.3 · Data.KeyTraversableWithKey (HashMap k)Defined in keys-3.12.3 · Data.Key(Eq k, Hashable k) => Zip (HashMap k)Defined in keys-3.12.3 · Data.Key(Eq k, Hashable k) => ZipWithKey (HashMap k)Defined in keys-3.12.3 · Data.Key(Default k, Hashable k) => Pointed (HashMap k)Defined in pointed-5.0.4 · Data.PointedHashable k => IsList (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal(Eq k, Eq v) => Eq (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalNote that, in the presence of hash collisions, equal
HashMaps may behave differently, i.e. extensionality may be violated:Example2 expressions data D = A | B deriving (Eq, Show)instance Hashable D where hashWithSalt salt _d = salt
Example2 expressions x = fromList [(A,1), (B,2)]y = fromList [(B,2), (A,1)]
Example3 expressions x == yTruetoList x[(A,1),(B,2)]toList y[(B,2),(A,1)]
In general, the lack of extensionality can be observed with any function that depends on the key ordering, such as folds and traversals.
(Data k, Data v, Hashable k) => Data (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal(Ord k, Ord v) => Ord (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalThe ordering is total and consistent with the Eq instance. However, nothing else about the ordering is specified, and it may change from version to version of either this package or of
hashable.(Hashable k, Read k, Read e) => Read (HashMap k e)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal(Show k, Show v) => Show (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalHashable k => Semigroup (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalHashable k => Monoid (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal(NFData k, NFData v) => NFData (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal(Hashable k, Hashable v) => Hashable (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.Internaltype Item (HashMap k v) = (k, v)Defined in unordered-containers-0.2.21 · Data.HashMap.Internaltype Key (HashMap k) = kDefined in keys-3.12.3 · Data.Key
O(n) Reduce this map by applying a binary operator to all
elements, using the given starting value (typically the
left-identity of the operator). Each application of the operator
is evaluated before using the result in the next application.
This function is strict in the starting value.
O(1) Construct an empty map.
O(n) Transform this map by applying a function to every value.
O(\log n) Return the value to which the specified key is mapped.
Calls error if this map contains no mapping for the key.
O(n) Filter this map by retaining only elements which values
satisfy a predicate.
O(n) Return a list of this map's values. The list is produced
lazily.
O(n) Reduce this map by applying a binary operator to all
elements, using the given starting value (typically the
right-identity of the operator). Each application of the operator
is evaluated before using the result in the next application.
This function is strict in the starting value.
O(n) Return the number of key-value mappings in this map.
Given maps bc and ab, relate the keys of ab to the values of bc,
by using the values of ab as keys for lookups in bc.
Complexity: O (n * \log(m)) , where m is the size of the first argument
compose (fromList [('a', "A"), ('b', "B")]) (fromList [(1,'a'),(2,'b'),(3,'z')])fromList [(1,"A"),(2,"B")]
(compose bc ab !?) = (bc !?) <=< (ab !?)
O(1) Construct a map with a single element.
O(n \log n) Construct a map with the supplied mappings. If the
list contains duplicate mappings, the later mappings take
precedence.
O(n+m) Intersection of two maps. If a key occurs in both maps
the provided function is used to combine the values from the two
maps.
O(n+m) Intersection of two maps. If a key occurs in both maps
the provided function is used to combine the values from the two
maps.
O(n) Transform this map by applying a function to every value
and retaining only some of them.
O(n+m) The union of two maps. If a key occurs in both maps, the
mapping from the first will be the mapping in the result.
Examples
union (fromList [(1,'a'),(2,'b')]) (fromList [(2,'c'),(3,'d')])fromList [(1,'a'),(2,'b'),(3,'d')]
O(\log n) Remove the mapping for the specified key from this map
if present.
O(n \log m) Difference of two maps. Return elements of the first map
not existing in the second.
O(n \log m) Check whether the key sets of two maps are disjoint
(i.e., their intersection is empty).
xs `disjoint` ys = null (xs `intersection` ys)
O(n) Filter this map by retaining only elements satisfying a
predicate.
O(\log n) Return the value to which the specified key is mapped,
or the default value if this map contains no mapping for the key.
O(n) Reduce the map by applying a function to each element
and combining the results with a monoid operation.
O(n) Reduce this map by applying a binary operator to all
elements, using the given starting value (typically the
left-identity of the operator).
O(n) Reduce this map by applying a binary operator to all
elements, using the given starting value (typically the
left-identity of the operator). Each application of the operator
is evaluated before using the result in the next application.
This function is strict in the starting value.
O(n) Reduce this map by applying a binary operator to all
elements, using the given starting value (typically the
right-identity of the operator).
O(n) Reduce this map by applying a binary operator to all
elements, using the given starting value (typically the
right-identity of the operator). Each application of the operator
is evaluated before using the result in the next application.
This function is strict in the starting value.
O(n \log m) Intersection of two maps. Return elements of the first
map for keys existing in the second.
O(n \log m) Inclusion of maps. A map is included in another map if the keys
are subsets and the corresponding values are equal:
isSubmapOf m1 m2 = keys m1 `isSubsetOf` keys m2 &&
and [ v1 == v2 | (k1,v1) <- toList m1; let v2 = m2 ! k1 ]Examples
fromList [(1,'a')] `isSubmapOf` fromList [(1,'a'),(2,'b')]True
fromList [(1,'a'),(2,'b')] `isSubmapOf` fromList [(1,'a')]False
O(n \log m) Inclusion of maps with value comparison. A map is included in
another map if the keys are subsets and if the comparison function is true
for the corresponding values:
isSubmapOfBy cmpV m1 m2 = keys m1 `isSubsetOf` keys m2 &&
and [ v1 `cmpV` v2 | (k1,v1) <- toList m1; let v2 = m2 ! k1 ]Examples
isSubmapOfBy (<=) (fromList [(1,'a')]) (fromList [(1,'b'),(2,'c')])True
isSubmapOfBy (<=) (fromList [(1,'b')]) (fromList [(1,'a'),(2,'c')])False
O(\log n) Return the value to which the specified key is mapped,
or Nothing if this map contains no mapping for the key.
O(\log n) Return the value to which the specified key is mapped,
or the default value if this map contains no mapping for the key.
DEPRECATED: lookupDefault is deprecated as of version 0.2.11, replaced by findWithDefault.
O(\log n) For a given key, return the equal key stored in the map,
if present, otherwise return Nothing.
This function can be used for interning, i.e. to reduce memory usage.
O(n).
mapKeys f s is the map obtained by applying f to each key of s.
The size of the result may be smaller if f maps two or more distinct
keys to the same new key. In this case there is no guarantee which of the
associated values is chosen for the conflicting key.
mapKeys (+ 1) (fromList [(5,"a"), (3,"b")])fromList [(4,"b"),(6,"a")]mapKeys (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")])fromList [(1,"c")]mapKeys (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")])fromList [(3,"c")]
Construct a set containing all elements from a list of sets.
O(\log n) Adjust the value tied to a given key in this map only
if it is present. Otherwise, leave the map alone.
O(\log n) The expression (alterF f k map) alters the value x at
k, or absence thereof.
alterF can be used to insert, delete, or update a value in a map.
Note: alterF is a flipped version of the at combinator from
Control.Lens.At.
O(n \log n) Construct a map from a list of elements. Uses
the provided function f to merge duplicate entries with
(f newVal oldVal).
Examples
Given a list xs, create a map with the number of occurrences of each
element in xs:
let xs = ['a', 'b', 'a']
in fromListWith (+) [ (x, 1) | x <- xs ]
= fromList [('a', 2), ('b', 1)]Given a list of key-value pairs xs :: [(k, v)], group all values by their
keys and return a HashMap k [v].
let xs = ('a', 1), ('b', 2), ('a', 3)]
in fromListWith (++) [ (k, [v]) | (k, v) <- xs ]
= fromList [('a', [3, 1]), ('b', [2])]Note that the lists in the resulting map contain elements in reverse order from their occurrences in the original list.
More generally, duplicate entries are accumulated as follows;
this matters when f is not commutative or not associative.
fromListWith f [(k, a), (k, b), (k, c), (k, d)]
= fromList [(k, f d (f c (f b a)))]O(n \log n) Construct a map from a list of elements. Uses
the provided function to merge duplicate entries.
Examples
Given a list of key-value pairs where the keys are of different flavours, e.g:
data Key = Div | Suband the values need to be combined differently when there are duplicates, depending on the key:
combine Div = div
combine Sub = (-)then fromListWithKey can be used as follows:
fromListWithKey combine [(Div, 2), (Div, 6), (Sub, 2), (Sub, 3)]
= fromList [(Div, 3), (Sub, 1)]More generally, duplicate entries are accumulated as follows;
fromListWith f [(k, a), (k, b), (k, c), (k, d)]
= fromList [(k, f k d (f k c (f k b a)))]O(\log n) Associate the specified value with the specified
key in this map. If this map previously contained a mapping for
the key, the old value is replaced.
O(\log n) Associate the value with the key in this map. If
this map previously contained a mapping for the key, the old value
is replaced by the result of applying the given function to the new
and old value. Example:
insertWith f k v map
where f new old = new + oldO(n) Transform this map by applying a function to every value
and retaining only some of them.
O(n) Transform this map by applying a function to every value.
O(n) Perform an Applicative action for each key-value pair
in a HashMap and produce a HashMap of all the results. Each HashMap
will be strict in all its values.
traverseWithKey f = fmap (map id) . Data.HashMap.Lazy.traverseWithKey f
Note: the order in which the actions occur is unspecified. In particular, when the map contains hash collisions, the order in which the actions associated with the keys involved will depend in an unspecified way on their insertion order.
O(n+m) The union of two maps. If a key occurs in both maps,
the provided function (first argument) will be used to compute the result.
O(n+m) The union of two maps. If a key occurs in both maps,
the provided function (first argument) will be used to compute the result.