Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Synopsis
- data ShareMap k v
- empty :: ShareMap k v
- toHashMap :: (Hashable k, Eq k) => ShareMap k v -> HashMap k v
- insertWith :: (Hashable k, Eq k) => (v -> v -> v) -> k -> v -> ShareMap k v -> ShareMap k v
- map :: (a -> b) -> ShareMap k a -> ShareMap k b
- mergeKeysWith :: (Hashable k, Eq k) => (v -> v -> v) -> k -> k -> ShareMap k v -> ShareMap k v
Documentation
A HashMap that can share the values of some entries
If two keys k1
and k2
are mapped to single v
, updating
the entry for k1
also updates the entry for k2
and viceversa.
The user of the map is responsible for indicating which keys are going to share their values.
Keys can be updated with shareMapInsertWith
and mergeKeysWith
.
Instances
insertWith :: (Hashable k, Eq k) => (v -> v -> v) -> k -> v -> ShareMap k v -> ShareMap k v Source #
insertWith f k v m
is the map m
plus key k
being associated to
value v
.
If k
is present in m
, then k
and any other key sharing its value
will be associated to f v (m ! k)
.
mergeKeysWith :: (Hashable k, Eq k) => (v -> v -> v) -> k -> k -> ShareMap k v -> ShareMap k v Source #
mergeKeysWith f k0 k1 m
updates the k0
value to f (m ! k0) (m ! k1)
and k1
shares the value with k0
.
If k0
and k1
are already sharing their values in m
, or both keys are
missing, this operation returns m
unmodified.
If only one of the keys is present, the other key is associated with the existing value.