plebeia
Library
Module
Module type
Parameter
Class
Class type
2 Types: Trail and cursor
A trail represents the content of the memory stack when recursively exploring a tree. Constructing these trails from closure would be easier, but it would make it harder to port the code to C. The type parameters of the trail keep track of the type of each element on the "stack" using a product type.
The constructors are private. Use '_' prefixed functions with runtime invariant checks.
type t = cursor
2 Constructor with invariant checks
val _Top : trail
2 Creation
val empty : Plebeia__Context.t -> t
Creates a cursor to a new, empty tree.
2 Accessors
val context : t -> Plebeia__Context.t
val index : t -> Plebeia__Index.t option
Get the index of the node pointed by the cursor, if indexed.
2 Segments
2 View
Get the view of the cursor. Returns also the updated cursor with the view.
2 Zipper functions
Result of access_gen
val error_access : access_result -> ( 'a, Error.t ) Result.t
Make an access result into an error
3 Simple 1 step cursor movement
This function expects a cursor positionned on a bud and moves it one step below.
Go down an Extender node. The cursor must point to an Extender.
val go_side : Segment.side -> t -> ( t, Error.t ) Result.t
Go down an Internal node. The cursor must point to an Internal.
3 Complex multi step cursor movement
Many of these functions fail when the given cursor does not point to a bud.
val access_gen : t -> Segment.t -> ( access_result, Error.t ) Result.t
Follow a segment. t
must point to a bud. The function first go below the bud, then follow the segment.
val access_gen' : t -> Segment.t -> ( access_result, Error.t ) Result.t
Follow a segment. t
can be any node.
Moves the cursor back to the bud above. Note that this is not like "cd ../".
If the cursor is already at a bud, it does not move it. This is super confusing. Do not use this function.
Moves the cursor back to the bud above. Note that this is not like "cd ../".
If the cursor is already at a bud, the cursor will move to its parent bud.
Moves the cursor back to the bud above. Like "cd ../". The cursor must point to a bud otherwise parent
fails.
Moves the cursor down a segment, to the root of a sub-tree. Think "cd segment/"
Create a subtree (bud). Think "mkdir segment". The cursor does NOT move from the original position.
Same as subtree but create a subtree if not exists
val get :
t ->
Segment.t ->
( t * [ `Leaf of Plebeia__Node.view | `Bud of Plebeia__Node.view ], Error.t )
Result.t
Gets a value if present in the current tree at the given segment.
Gets a value or a bud at the given segment.
Inserts a value at the given segment in the current tree. The cursor does NOT move from the original position.
Upserts. This can still fail if the segment leads to a subtree. The cursor does NOT move from the original position.
Update. A value must be bound at the segment.
Delete a leaf or subtree. The cursor does NOT move from the original position.
Remove the empty Bud pointed by the cursor. If the non-root parent becomes empty by the removal, remove_empty_bud
recursively removes it, too. If the cursor points non empty bud, it does nothing.
The cursor in the result points to the parent bud of the upmost removed bud.
val alter :
t ->
Segment.segment ->
( Plebeia__Node.view option -> ( Plebeia__Node.node, Error.t ) Result.t ) ->
( t, Error.t ) Result.t
alter
can easily break the invariants.
Folding over the node tree. The function can choose the node traversal from the given cursor: either continuing into its sub-nodes, not traversing its sub-nodes, or quit the entire folding.
If a node is shared at multiple places it is visited MORE THAN ONCE. If you want to avoid visiting a shared node at most once, carry a set of visited nodes by indices and check a node is visited or not.
More generic tree traversal than fold
, which has a step-by-step visitor interface: it does not recurse the structure by itself.
If a node is shared at multiple places it is visited MORE THAN ONCE.
2 Statistics
2 Debug