Data.Map.Internal
- Package
- purescript-ordered-collections
- Repository
- purescript/purescript-ordered-collections
This module defines a type of maps as balanced 2-3 trees, based on http://www.cs.princeton.edu/~dpw/courses/cos326-12/ass/2-3-trees.pdf
#Map Source
data Map k v
Map k v
represents maps from keys of type k
to values of type v
.
Instances
(Eq k) => Eq1 (Map k)
(Eq k, Eq v) => Eq (Map k v)
(Ord k) => Ord1 (Map k)
(Ord k, Ord v) => Ord (Map k v)
(Show k, Show v) => Show (Map k v)
(Ord k) => Semigroup (Map k v)
(Ord k) => Monoid (Map k v)
Functor (Map k)
FunctorWithIndex k (Map k)
Foldable (Map k)
FoldableWithIndex k (Map k)
Traversable (Map k)
TraversableWithIndex k (Map k)
#checkValid Source
checkValid :: forall v k. Map k v -> Boolean
Check whether the underlying tree satisfies the 2-3 invariant
This function is provided for internal use.
#foldSubmap Source
foldSubmap :: forall m v k. Ord k => Monoid m => Maybe k -> Maybe k -> (k -> v -> m) -> Map k v -> m
Fold over the entries of a given map where the key is between a lower and
an upper bound. Passing Nothing
as either the lower or upper bound
argument means that the fold has no lower or upper bound, i.e. the fold
starts from (or ends with) the smallest (or largest) key in the map.
foldSubmap (Just 1) (Just 2) (\_ v -> [v])
(fromFoldable [Tuple 0 "zero", Tuple 1 "one", Tuple 2 "two", Tuple 3 "three"])
== ["one", "two"]
foldSubmap Nothing (Just 2) (\_ v -> [v])
(fromFoldable [Tuple 0 "zero", Tuple 1 "one", Tuple 2 "two", Tuple 3 "three"])
== ["zero", "one", "two"]
#submap Source
submap :: forall v k. Ord k => Maybe k -> Maybe k -> Map k v -> Map k v
Returns a new map containing all entries of the given map which lie
between a given lower and upper bound, treating Nothing
as no bound i.e.
including the smallest (or largest) key in the map, no matter how small
(or large) it is. For example:
submap (Just 1) (Just 2)
(fromFoldable [Tuple 0 "zero", Tuple 1 "one", Tuple 2 "two", Tuple 3 "three"])
== fromFoldable [Tuple 1 "one", Tuple 2 "two"]
submap Nothing (Just 2)
(fromFoldable [Tuple 0 "zero", Tuple 1 "one", Tuple 2 "two", Tuple 3 "three"])
== fromFoldable [Tuple 0 "zero", Tuple 1 "one", Tuple 2 "two"]
The function is entirely specified by the following property:
Given any m :: Map k v, mmin :: Maybe k, mmax :: Maybe k, key :: k,
let m' = submap mmin mmax m in
if (maybe true (\min -> min <= key) mmin &&
maybe true (\max -> max >= key) mmax)
then lookup key m == lookup key m'
else not (member key m')
#fromFoldable Source
fromFoldable :: forall v k f. Ord k => Foldable f => f (Tuple k v) -> Map k v
Convert any foldable collection of key/value pairs to a map. On key collision, later values take precedence over earlier ones.
#fromFoldableWith Source
fromFoldableWith :: forall v k f. Ord k => Foldable f => (v -> v -> v) -> f (Tuple k v) -> Map k v
Convert any foldable collection of key/value pairs to a map. On key collision, the values are configurably combined.
#fromFoldableWithIndex Source
fromFoldableWithIndex :: forall v k f. Ord k => FoldableWithIndex k f => f v -> Map k v
Convert any indexed foldable collection into a map.
#toUnfoldable Source
toUnfoldable :: forall v k f. Unfoldable f => Map k v -> f (Tuple k v)
Convert a map to an unfoldable structure of key/value pairs where the keys are in ascending order
#toUnfoldableUnordered Source
toUnfoldableUnordered :: forall v k f. Unfoldable f => Map k v -> f (Tuple k v)
Convert a map to an unfoldable structure of key/value pairs
#difference Source
difference :: forall w v k. Ord k => Map k v -> Map k w -> Map k v
Difference of two maps. Return elements of the first map where the keys do not exist in the second map.
#filterWithKey Source
filterWithKey :: forall v k. Ord k => (k -> v -> Boolean) -> Map k v -> Map k v
Filter out those key/value pairs of a map for which a predicate fails to hold.