Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Paths and Absolute Paths

Some zippers maintain can expose their focus position within the trie as a path. The following traits expose access to the path buffer in some way.

Zipper Relative Path

The [path] method in [ZipperMoving] returns the current path from the zipper's root to its focus as a byte slice. This represents the sequence of bytes traversed to reach the current focus position.

Note that this path is relative to the zipper's root, which may not be the same as the absolute path from the original data structure's root if the zipper was created with a prefix or from a subtrie.

ZipperAbsolutePath

The [ZipperAbsolutePath] trait provides methods to access a more complete path slice, including the [origin_path], and may extend above the zipper's root.

Origin and Root Prefix Paths

The trait provides two key methods:

  • [origin_path] returns the entire path from the zipper's origin to its current focus. The origin depends on how the zipper was created - for zippers created directly from a [PathMap], this starts at the map's root.

  • [root_prefix_path] returns the path from the zipper's origin to the zipper's root. This value remains constant throughout the zipper's life and is unaffected by the focus position.

The relationship between these paths is: origin_path() == root_prefix_path() + path().

After calling [reset] to return to the zipper's root, root_prefix_path() equals origin_path().

ZipperPathBuffer

The [ZipperPathBuffer] trait provides low-level control over the zipper's internal path buffer management. This trait is primarily used for performance optimization.

Buffer Management

The trait offers methods for direct buffer manipulation:

  • [prepare_buffers] ensures the path buffer is allocated to facilitate zipper movement. Normally buffer allocation is done lazily.
  • [reserve_buffers] grows the internal buffers to accommodate larger paths and deeper node stacks, but never shrinks them.
  • [origin_path_assert_len] provides unsafe access to the path buffer beyond its current length.

The buffer management is designed to minimize allocations during zipper operations by pre-allocating the buffers for expected path lengths and traversal depths, so that the buffer can be sized once, instead of incurring multiple reallocs.