Modifying the Trie
The ZipperWriting trait provides methods to modify the trie structure and values. This trait provides comprehensive functionality for creating, updating, and removing data within the trie.
Direct Value Access
get_val_mutreturns a mutable reference to the value at the focus, orNoneif no value existsset_valsets the value at the focus, returning any previously existing valueremove_valremoves the value at the focus, optionally pruning dangling paths
Upsert Value Access (Create-Or-Update)
get_val_or_set_mutreturns a mutable reference to the value at the focus, inserting the provided default if no value existsget_val_or_set_mut_withsimilar to above, but uses a closure to generate the default value when needed
Path Creation and Removal
create_pathensures a path exists to the current focus, creating intermediate nodes as neededprune_pathremoves dangling path segments above the focus that have no values or branchesprune_ascendcombines pruning with ascension, moving to the first non-dangling path
Subtrie Shifting
insert_prefixadds a prefix to all downstream paths from the focusremove_prefixremoves the specified number of bytes from paths above the focus
Subtrie Moving and Copying
graftreplaces the subtrie below the focus with content from another zipper's focusgraft_mapreplaces the subtrie below the focus with the contents of aPathMaptake_mapextracts the subtrie below the focus into a newPathMap, removing it from the original
Branch Removal
remove_branchesremoves all child branches below the focusremove_unmasked_branchesselectively removes branches based on a byte mask
Pruning Behavior
Many operations accept a prune parameter that controls whether dangling paths should be automatically cleaned up. When prune is true, the operation will remove any path segments that become empty, aka "dangling" (no values, and no further downstream branches) as a result of the modification.
Automatic pruning helps maintain a compact trie structure by removing unnecessary nodes, but can be counter-productive when you plan to perform additional operations that might reuse those paths.