package patricia-tree
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9670bac52dcb93ea1bfc1afaf7846bc100bcdc63a7a468d5eb43f2b7660c2da9
sha512=aa182adb046c50f6e4742e59a18efdae2c3dd5d175a231bd8b84391351b0d4bda8dd9b1e3a4c8e71770dfc8fd1ab4f5f3cb32ab3062953f76faa435b441c3894
doc/patricia-tree/PatriciaTree/WeakNode/index.html
Module PatriciaTree.WeakNodeSource
NODE used to implement weak key hashes (the key-binding pair is an Ephemeron, the reference to the key is weak, and if the key is garbage collected, the binding disappears from the map.
Warning: not thread-safe. For multi-threaded use, wrap in MutexProtectNode.
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 ... endmodule Value : HETEROGENEOUS_VALUESignature
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
tree0nortree1should be empty. branching_bitshould have a single bit setprefixshould be normalized (bits belowbranching_bitset to zero)- All elements of
tree0should have theirto_intstart byprefixfollowed by 0 at positionbranching_bit). - All elements of
tree1should have theirto_intstart byprefixfollowed 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_bitcontains only one bit set; the corresponding mask is (branching_bit - 1).prefixis normalized: the bits below thebranching_bitare set to zero (i.e.prefix & (branching_bit - 1) = 0).- All elements of
tree0should have theirto_intstart byprefixfollowed by 0 at positionbranching_bit). - All elements of
tree1should have theirto_intstart byprefixfollowed 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.