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

A Zipper is a Cursor in a Trie

Zippers are persistent pointers that refer to a location within a trie, called the zipper's focus. When an operation is applied through a zipper, it accesses and /or acts on the focus. The advantage of zippers is that they don't require re-traversal of the in-memory data structure for each operation.

A zipper is most often used to point to a location within a [PathMap], however a zipper may also operate within other kinds of tries. One example is the [ACT] on-disk file format, which allows a trie to be explored without requiring the entire data structure to be loaded into memory. Another example is a virtualized trie, such as an infinite trie that is defined parametrically.

Zipper Traits

Zipper capabilities are defined across a number of traits. There are many different zipper objects depending on the function of the zipper and the underlying data structure it accesses. Therefore it makes sense to treat zippers as generic types with the feature-specific trait bounds you require.

TraitPurpose / Description
ZipperInspect the trie structure
ZipperConcreteInspect structural sharing
ZipperSubtriesMake a map from a subtrie, or provide an operand to algebraic ops
ZipperReadOnlySubtriesCreate [TrieRef] objects
ZipperForkingCreate temporary zippers
ZipperValuesAccess values
ZipperReadOnlyValuesAccess values with extended lifetime
ZipperReadOnlyConditionalValuesAccess values with witness pattern
ZipperAbsolutePathGet more complete path information
ZipperPathBufferControl zipper's internal buffer allocation
ZipperMovingMoves the zipper's focus within the trie
ZipperIterationTraverse / exploration the trie
ZipperReadOnlyIterationIterate and borrow values in the trie
ZipperReadOnlyConditionalIterationIterate trie values with witness pattern
ZipperWritingModify the trie structure and values, and perform algebraic ops

Zipper and Zipper-like Objects

The pathmap crate provides a number of zipper and zipper-like objects with different capabilities and performance characteristics. It is also permissible to implement most (but not all) of the zipper traits on outside objects. Therefore this is not a complete set of zippers, but includes the core types that work directly on [PathMap] tries.

ObjectLifetimeWritingMovingCost to CreatePrimary Use Case
[PathMap]'staticMedRoot data structure, stand-alone trie
[TrieRefBorrowed]BorrowedUltra LowQuick focus access, no navigation
[TrieRefOwned]'staticLowFocus access without lifetime, no navigation
[ReadZipper]BorrowedMedReading, navigation and iteration
[ReadZipperOwned]'staticHighReading, navigation and iteration, send across threads
[WriteZipper]BorrowedMedTrie modifications
[WriteZipperOwned]'staticHighTrie modifications, send across threads