ZipperMoving
Some zippers allow the focus to be moved, which is done using the methods in the [ZipperMoving] trait. It is almost always faster to move a zipper's focus than to create a new zipper. Moving to a longer path is called descending while moving to a shorter path is called ascending.
The ZipperMoving trait provides methods to navigate through the trie. It provides both fine-grained single-step movement and higher-level jumping methods.
Descending is not limited in any way, and moving the focus to non-existent paths is one of the ways new paths are created by zippers with writing capability. When ascending, the zipper's focus cannot be moved above the zipper's root. The root is the highest possible position for the zipper's focus.
Reset and the Root Position
- [
reset] moves the focus back to the zipper's root. - [
at_root] checks if the zipper is at its root position.
Absolute Positioning
- [
move_to_path] moves the zipper's focus directly to a specific path relative to the zipper's root.
Stepping vs. Jumping
Zippers may be descended and ascended either by stepping an absolute number of elements, or by jumping to features such as branches, values, or the end of the path. In general, moving by jumping will be faster than stepping.
Stepping Methods
These methods move the zipper by specific byte distances
- [
descend_to_byte] descends down one level to the specified child byte - [
descend_indexed_byte] descends one byte to the nth child branch (by index in the child mask) - [
descend_first_byte] moves down to the first child branch - [
ascend] moves up a specified number of bytes toward the root - [
ascend_byte] moves up exactly one byte (equivalent toascend(1))
Jumping Methods
These methods move the zipper to positions based on trie features:
- [
descend_to] moves to a path relative to the current focus position - [
descend_to_existing] follows a path, stopping if a non-existent path byte is encountered - [
descend_to_val] similar todescend_to_existingbut also stops if a value is encountered - [
descend_until] descends until a position with multiple children or a value is encountered - [
ascend_until] ascends until reaching a position with multiple children, a value, or the root - [
ascend_until_branch] ascends until reaching a position with multiple children, skipping values
Sibling Navigation
- [
to_next_sibling_byte] moves to the next sibling at the current level - [
to_prev_sibling_byte] moves to the previous sibling at the current level