-
Notifications
You must be signed in to change notification settings - Fork 0
module std.map
Jan Špaček edited this page Apr 12, 2016
·
2 revisions
This module implements persistent maps with ordered keys. To establish the
ordering, the map requires a comparator. Comparator is a function that takes two
keys and returns 0 when they are equal, a negative value when the first one is
ordered before the second one and positive value when the first one is ordered
after the first one. One example of such a function is -
on numbers, which
defines the usual ordering, or str-cmp
from module std.string, that
defines lexicographic ordering.
-
(map-new cmp)
creates a new map with comparatorcmp
. -
(map? m)
returns true ifm
is a map. -
(map-empty? m)
returns true if mapm
is empty, in time O(1). -
(map-len m)
returns the number of elements in mapm
in time O(n). -
(map-get m key)
returns the value associated withkey
in mapm
or panics if the key is not found. The time complexity is O(log n). -
(map-get-or m key not-found)
works asmap-get
, but callsnot-found
when the key is not present. -
(map-contains? m key)
returns true if mapm
containskey
. -
(map-set m key value)
returns a new map that is created from mapm
by bindingkey
tovalue
(key
may or may not be defined inm
). The time complexity is O(log n). -
(map-remove m key)
returns a new map that is created fromm
by removingkey
, if it exists. This operation takes O(log n) time. -
(map-from-assoc cmp assoc)
creates a map with comparatorcmp
and populates it with key-value pairs from associative listassoc
.