package patricia-tree
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=18fcde5d35d65c9bb2f9ec4ff732ecdd8969ba6fc2cf51d29ecb3be66e2fe664
sha512=da038d5096deb4bf3c02efd694e962ecf9b2571d140fa1fef17cce474f628ec070b93a44fd742748b9d3ba0e51041f864623d83e9cb0c72214abb0fb4a043625
doc/patricia-tree/PatriciaTree/SetNode/index.html
Module PatriciaTree.SetNode
Source
An optimized representation for sets, i.e. maps to unit: we do not store a reference to unit (note that you can further optimize when you know the representation of the key). This is the node used in MakeHeterogeneousSet
and MakeSet
.
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
module Key : sig ... end
Signature
Types
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 values
A singleton leaf, similar to BASE_MAP.singleton
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
nortree1
should be empty. branching_bit
should have a single bit setprefix
should be normalized (bits belowbranching_bit
set to zero)- All elements of
tree0
should have theirto_int
start byprefix
followed by 0 at positionbranching_bit
). - All elements of
tree1
should have theirto_int
start byprefix
followed by 0 at positionbranching_bit
).
Destructors: access the value
type 'map view = private
| Empty : 'map view
(*Can happen only at the toplevel: there is no empty interior node.
*)| Branch : {
} -> '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 thebranching_bit
are set to zero (i.e.prefix & (branching_bit - 1) = 0
).- All elements of
tree0
should have theirto_int
start byprefix
followed by 0 at positionbranching_bit
). - All elements of
tree1
should have theirto_int
start byprefix
followed by 0 at positionbranching_bit
).
| Leaf : {
} -> 'map view
(*A key -> value mapping.
*)
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.