Skip to content
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 comparator cmp.
  • (map? m) returns true if m is a map.
  • (map-empty? m) returns true if map m is empty, in time O(1).
  • (map-len m) returns the number of elements in map m in time O(n).
  • (map-get m key) returns the value associated with key in map m or panics if the key is not found. The time complexity is O(log n).
  • (map-get-or m key not-found) works as map-get, but calls not-found when the key is not present.
  • (map-contains? m key) returns true if map m contains key.
  • (map-set m key value) returns a new map that is created from map m by binding key to value (key may or may not be defined in m). The time complexity is O(log n).
  • (map-remove m key) returns a new map that is created from m by removing key, if it exists. This operation takes O(log n) time.
  • (map-from-assoc cmp assoc) creates a map with comparator cmp and populates it with key-value pairs from associative list assoc.