Both a WeakNode
and a SetNode
, useful to implement Weak sets.
We use a uniform type 'map view
to pattern match on maps and sets The actual types 'map t
can be a bit different from 'map view
to allow for more efficient representations, but view
should be a constant time operation for quick conversions.
Parameters Signature Typestype ('key, 'map) value = unit
The type of value, which depends on the type of the key and the type of the map.
The type of the map, which is parameterized by a type.
Constructors: build valuesval leaf : 'key key -> ('key , 'map ) value -> 'map t
val branch :
prefix :int ->
branching_bit :int ->
tree0 :'map t ->
tree1 :'map t ->
'map t
A branch node. This shouldn't be called externally unless you know what you're doing! Doing so could easily break the data structure's invariants.
When called, it assumes that:
Neither tree0
nor tree1
should be empty. branching_bit
should have a single bit setprefix
should be normalized (bits below branching_bit
set to zero)All elements of tree0
should have their to_int
start by prefix
followed by 0 at position branching_bit
). All elements of tree1
should have their to_int
start by prefix
followed by 0 at position branching_bit
). Destructors: access the valuetype 'map view = private
| Empty : 'map view
Can happen only at the toplevel: there is no empty interior node.
| Branch : {
prefix : int;
branching_bit : int;
tree0 : 'map t ;
tree1 : 'map t ;
} -> 'map view
Same constraints as branch
:
branching_bit
contains only one bit set; the corresponding mask is (branching_bit - 1).prefix
is normalized: the bits below the branching_bit
are set to zero (i.e. prefix & (branching_bit - 1) = 0
).All elements of tree0
should have their to_int
start by prefix
followed by 0 at position branching_bit
). All elements of tree1
should have their to_int
start by prefix
followed by 0 at position branching_bit
). | Leaf : {
key : 'key key ;
value : ('key , 'map ) value ;
} -> 'map view
This makes the map nodes accessible to the pattern matching algorithm; this corresponds 1:1 to the SimpleNode
implementation. This just needs to be copy-and-pasted for every node type.
val is_empty : 'map t -> bool
Check if the map is empty. Should be constant time.
val view : 'a t -> 'a view
Convert the map to a view. Should be constant time.