Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/binary_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn binary_descend_until(bencher: Bencher, n: u64) {
if start > 0 {
zipper.descend_to(&key[..start]);
}
if zipper.descend_until() {
if zipper.descend_until(&mut ()) {
sink += 1;
}
}
Expand Down Expand Up @@ -107,7 +107,7 @@ fn binary_descend_until_max_bytes(bencher: Bencher, n: u64) {
if start > 0 {
zipper.descend_to(&key[..start]);
}
if zipper.descend_until_max_bytes(DESCEND_UNTIL_MAX_BYTES) {
if zipper.descend_until_max_bytes(DESCEND_UNTIL_MAX_BYTES, &mut ()) {
sink += 1;
}
}
Expand Down
6 changes: 3 additions & 3 deletions benches/oeis.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use std::io::Read;
use std::usize;
use pathmap::PathMap;
use pathmap::zipper::{Zipper, ZipperValues, ZipperMoving, ZipperWriting, ZipperCreation};
use pathmap::zipper::{Zipper, ZipperValues, ZipperMoving, ZipperPath, ZipperWriting, ZipperCreation};
use num::BigInt;
use divan::{Divan, Bencher, black_box};

const MAX_OFFSET: u8 = 10;

fn drop_symbol_head_byte<Z: ZipperWriting<usize> + Zipper + ZipperMoving>(loc: &mut Z) {
fn drop_symbol_head_byte<Z: ZipperWriting<usize> + Zipper + ZipperMoving + ZipperPath>(loc: &mut Z) {
let mut it = loc.child_mask().iter();

let p = loc.path().to_vec();
while let Some(b) = it.next() {
if b == 0 { continue }
loc.descend_to_existing_byte(b);
loc.join_k_path_into(b as usize, true);
assert!(loc.ascend(1));
assert_eq!(loc.ascend(1), 1);
}
loc.reset();
loc.descend_to(&p[..]);
Expand Down
4 changes: 2 additions & 2 deletions benches/sparse_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn sparse_descend_until(bencher: Bencher, n: u64) {
if start > 0 {
zipper.descend_to(&key[..start]);
}
if zipper.descend_until() {
if zipper.descend_until(&mut ()) {
sink += 1;
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ fn sparse_descend_until_max_bytes(bencher: Bencher, n: u64) {
if start > 0 {
zipper.descend_to(&key[..start]);
}
if zipper.descend_until_max_bytes(DESCEND_UNTIL_MAX_BYTES) {
if zipper.descend_until_max_bytes(DESCEND_UNTIL_MAX_BYTES, &mut ()) {
sink += 1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions benches/superdense_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn superdense_descend_until(bencher: Bencher, n: u64) {
if start > 0 {
zipper.descend_to(&key[..start]);
}
if zipper.descend_until() {
if zipper.descend_until(&mut ()) {
sink += 1;
}
}
Expand All @@ -123,7 +123,7 @@ fn superdense_descend_until_max_bytes(bencher: Bencher, n: u64) {
if start > 0 {
zipper.descend_to_existing(&key[..start]);
}
if zipper.descend_until_max_bytes(DESCEND_UNTIL_MAX_BYTES) {
if zipper.descend_until_max_bytes(DESCEND_UNTIL_MAX_BYTES, &mut ()) {
sink += 1;
}
}
Expand Down
1 change: 1 addition & 0 deletions pathmap-book/src/1.02.00_zippers.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Zipper capabilities are defined across a number of traits. There are many diffe
| [`ZipperValues`](./1.02.02_zipper_values.md#zippervalues) | Access values |
| [`ZipperReadOnlyValues`](./1.02.02_zipper_values.md#zipperreadonlyvalues) | Access values with extended lifetime |
| [`ZipperReadOnlyConditionalValues`](./1.02.02_zipper_values.md#zipperreadonlyconditionalvalues) | Access values with `witness` pattern |
| [`ZipperPath`](./1.02.03_zipper_paths.md#zipper_relative_path) | Get basic path information |
| [`ZipperAbsolutePath`](./1.02.03_zipper_paths.md#zipperabsolutepath) | Get more complete path information |
| [`ZipperPathBuffer`](./1.02.03_zipper_paths.md#zipperpathbuffer) | Control zipper's internal buffer allocation |
| [`ZipperMoving`](./1.02.04_zipper_moving.md) | Moves the zipper's focus within the trie |
Expand Down
6 changes: 3 additions & 3 deletions pathmap-book/src/1.02.03_zipper_paths.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 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.
Some zippers maintain and can expose their focus position within the trie as a contiguous `path` of type `&[u8]`. 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.
The [`path`] method in the [`ZipperPath`] trait 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.
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 within 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.
Expand Down
2 changes: 1 addition & 1 deletion pathmap-book/src/1.02.04_zipper_moving.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Descending is not limited in any way, and moving the focus to non-existent paths

## Absolute Positioning

- [`move_to_path`] moves the zipper's focus directly to a specific path relative to the zipper's root.
- [`move_to_path`] moves the zipper's focus directly to a specific path relative to the zipper's root. This method belongs to the [`ZipperPath`] trait, because it needs to know where the focus currently is in order to get to where it's going.

## 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.
Expand Down
6 changes: 4 additions & 2 deletions pathmap-book/src/api_links.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
[`WriteZipperOwned`]: https://docs.rs/pathmap/latest/pathmap/zipper/struct.WriteZipperOwned.html
[`WriteZipperUntracked`]: https://docs.rs/pathmap/latest/pathmap/zipper/struct.WriteZipperUntracked.html
[`Zipper`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.Zipper.html
[`ZipperPath`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperPath.html
[`ZipperAbsolutePath`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperAbsolutePath.html
[`ZipperConcrete`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperConcrete.html
[`ZipperForking`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperForking.html
Expand Down Expand Up @@ -46,6 +47,7 @@
[`TrieRef`]: https://docs.rs/pathmap/latest/pathmap/zipper/enum.TrieRef.html
[`WriteZipperOwned`]: https://docs.rs/pathmap/latest/pathmap/zipper/struct.WriteZipperOwned.html
[`WriteZipper`]: https://docs.rs/pathmap/latest/pathmap/zipper/struct.WriteZipperUntracked.html
[`ZipperPath`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperPath.html
[`ZipperAbsolutePath`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperAbsolutePath.html
[`ZipperConcrete`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperConcrete.html
[`ZipperForking`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperForking.html
Expand Down Expand Up @@ -97,12 +99,12 @@
[`make_map`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperSubtries.html#tymethod.make_map
[`meet_2`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperWriting.html#tymethod.meet_2
[`meet_into`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperWriting.html#tymethod.meet_into
[`move_to_path`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperMoving.html#tymethod.move_to_path
[`move_to_path`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperPath.html#tymethod.move_to_path
[`origin_path_assert_len`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperPathBuffer.html#tymethod.origin_path_assert_len
[`origin_path`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperAbsolutePath.html#tymethod.origin_path
[`path_exists_at`]: https://docs.rs/pathmap/latest/pathmap/struct.PathMap.html#method.path_exists_at
[`path_exists`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.Zipper.html#tymethod.path_exists
[`path`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperMoving.html#tymethod.path
[`path`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperPath.html#tymethod.path
[`prepare_buffers`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperPathBuffer.html#tymethod.prepare_buffers
[`prune_ascend`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperWriting.html#tymethod.prune_ascend
[`prune_path`]: https://docs.rs/pathmap/latest/pathmap/zipper/trait.ZipperWriting.html#tymethod.prune_path
Expand Down
25 changes: 21 additions & 4 deletions pathmap-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,31 @@ fn derive_poly_zipper_with_traits(
quote! {}
};
Some(quote! {
impl #impl_generics pathmap::zipper::ZipperMoving for #enum_name #ty_generics
impl #impl_generics pathmap::zipper::ZipperPath for #enum_name #ty_generics
#zipper_moving_where
{
fn path(&self) -> &[u8] {
match self {
#(#variant_arms => inner.path(),)*
}
}
}

impl #impl_generics pathmap::zipper::ZipperMoving for #enum_name #ty_generics
#zipper_moving_where
{
fn at_root(&self) -> bool {
match self {
#(#variant_arms => inner.at_root(),)*
}
}

#[inline]
fn focus_byte(&self) -> Option<u8> {
match self {
#(#variant_arms => inner.focus_byte(),)*
}
}

fn val_count(&self) -> usize {
match self {
Expand Down Expand Up @@ -500,19 +517,19 @@ fn derive_poly_zipper_with_traits(
}
}

fn ascend(&mut self, steps: usize) -> bool {
fn ascend(&mut self, steps: usize) -> usize {
match self {
#(#variant_arms => inner.ascend(steps),)*
}
}

fn ascend_until(&mut self) -> bool {
fn ascend_until(&mut self) -> usize {
match self {
#(#variant_arms => inner.ascend_until(),)*
}
}

fn ascend_until_branch(&mut self) -> bool {
fn ascend_until_branch(&mut self) -> usize {
match self {
#(#variant_arms => inner.ascend_until_branch(),)*
}
Expand Down
Loading