Belt.Set.Dict: This module separates data from function which is more verbose but slightly more efficient
A immutable sorted set module which allows customize compare behavior.
The implementation uses balanced binary trees, and therefore searching and insertion take time logarithmic in the size of the map.
For more info on this module's usage of identity, `make` and others, please see the top level documentation of Belt, A special encoding for collection safety.
Example usage:
module PairComparator = Belt.Id.MakeComparable(struct
type t = int * int
let cmp (a0, a1) (b0, b1) =
match Pervasives.compare a0 b0 with
| 0 -> Pervasives.compare a1 b1
| c -> c
end)
let mySet = Belt.Set.make ~id:(module PairComparator)
let mySet2 = Belt.Set.add mySet (1, 2)
The API documentation below will assume a predeclared comparator module for integers, IntCmp
This module seprate identity from data, it is a bit more verboe but slightly more efficient due to the fact that there is no need to pack identity and data back after each operation
type('value, 'identity) t
('value, 'identity) t
'value is the element type
'identity the identity of the collection
type('value, 'id) id =
(moduleBelt__.Belt_Id.Comparablewithtypeidentity = 'idandtypet = 'value)
Total ordering between sets. Can be used as the ordering function for doing sets of sets. It compare size first and then iterate over each element following the order of elements
some p s checks if at least one element of the set satisfies the predicate p.
val keepU : ('value, 'id)t->('value-> bool)Js.Fn.arity1->('value, 'id)t
val keep : ('value, 'id)t->('value-> bool)->('value, 'id)t
keep m p returns the set of all elements in s that satisfy predicate p.
val partitionU :
('value, 'id)t->('value-> bool)Js.Fn.arity1->('value, 'id)t * ('value, 'id)t
val partition :
('value, 'id)t->('value-> bool)->('value, 'id)t * ('value, 'id)t
partition m p returns a pair of sets (s1, s2), where s1 is the set of all the elements of s that satisfy the predicate p, and s2 is the set of all the elements of s that do not satisfy p.