-
Notifications
You must be signed in to change notification settings - Fork 0
module std.set
This module provides ordered persistent sets. Sets are isomorphic to maps with no values, but the implementations of maps and sets in Spiral use completely different data structures, so sets have some extra operations (notably indexing). A set also needs a comparator, as described in module std.map.
-
(set-new cmp)
creates an empty set with comparatorcmp
. -
(set-empty? s)
decides in time O(1) whether the sets
is empty. -
(set-len s)
returns the number of elements in sets
. This takes time O(1). -
(set-contains? s key)
returns true if the sets
containskey
, with time complexity O(log n). -
(set-insert s key)
returns a set that contains all keys from sets
with the keykey
in time O(log n). -
(set-remove s key)
returns a set that contains all keys from sets
exceptkey
in time O(log n). -
(set-to-list s)
returns an ordered list of all keys from sets
. This operation takes O(n) time. -
(set-from-list cmp keys)
creates a new set with comparatorcmp
containing allkeys
in O(n log n). -
(set-find-index s key)
returns the index ofkey
in the sets
or false if the key is not contained ins
. -
(set-get-index s idx)
returns the key at indexidx
in sets
or panics when the index is out of range. -
(set-remove-index s idx)
returns sets
without the key at indexidx
or panics if the index is out of range.