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
6 changes: 3 additions & 3 deletions benches/binary_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ fn binary_k_path_iter(bencher: Bencher, n: u64) {
//NOTE: 30 was found empirically and has no special meaning. It's just a number that is deep enough
// that there happens not to be any non-unique paths at that depth, given the RNG I tested. If this
// test fails, make that number smaller.
zipper.descend_first_k_path(KEY_LENGTH-30);
while zipper.to_next_k_path(KEY_LENGTH-30) {
zipper.descend_first_k_path(KEY_LENGTH-30, &mut ());
while zipper.to_next_k_path(KEY_LENGTH-30, &mut ()) {
count += 1;
}
assert_eq!(count, n);
Expand All @@ -196,7 +196,7 @@ fn binary_zipper_iter(bencher: Bencher, n: u64) {
bencher.bench_local(|| {
let mut count = 0;
let mut zipper = map.read_zipper();
while zipper.to_next_val() {
while zipper.to_next_val(&mut ()) {
count += 1;
}
assert_eq!(count, n);
Expand Down
4 changes: 2 additions & 2 deletions benches/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ fn parallel_copy_traverse(bencher: Bencher, (elements, thread_cnt): (usize, &str
Ok((mut reader_z, mut writer_z)) => {
//We got the zippers, do the stuff
let witness = reader_z.witness();
while let Some(val) = reader_z.to_next_get_val_with_witness(&witness) {
while let Some(val) = reader_z.to_next_get_val_with_witness(&witness, &mut ()) {
writer_z.move_to_path(reader_z.path());
writer_z.set_val(*val);

Expand Down Expand Up @@ -363,7 +363,7 @@ fn parallel_copy_traverse(bencher: Bencher, (elements, thread_cnt): (usize, &str
let mut writer_z = unsafe{ zipper_head.write_zipper_at_exclusive_path_unchecked(&[b'o', b'u', b't', 0]) };
let mut reader_z = unsafe{ zipper_head.read_zipper_at_path_unchecked(&[b'i', b'n', 0]) };
let witness = reader_z.witness();
while let Some(val) = reader_z.to_next_get_val_with_witness(&witness) {
while let Some(val) = reader_z.to_next_get_val_with_witness(&witness, &mut ()) {
writer_z.move_to_path(reader_z.path());
writer_z.set_val(*val);
sanity_counter += 1;
Expand Down
6 changes: 3 additions & 3 deletions benches/sparse_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ fn sparse_k_path_iter(bencher: Bencher, n: u64) {
bencher.bench_local(|| {
let mut zipper = map.read_zipper();
let mut count = 1;
zipper.descend_first_k_path(5);
while zipper.to_next_k_path(5) {
zipper.descend_first_k_path(5, &mut ());
while zipper.to_next_k_path(5, &mut ()) {
count += 1;
}
assert_eq!(count, n);
Expand All @@ -318,7 +318,7 @@ fn sparse_zipper_cursor(bencher: Bencher, n: u64) {
bencher.bench_local(|| {
let mut count = 0;
let mut zipper = map.read_zipper();
while zipper.to_next_val() {
while zipper.to_next_val(&mut ()) {
count += 1;
}
assert_eq!(count, n);
Expand Down
6 changes: 3 additions & 3 deletions benches/superdense_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ fn superdense_k_path_iter(bencher: Bencher, n: u64) {
let mut zipper = map.read_zipper();
let mut count = 1;

zipper.descend_first_k_path(2);
while zipper.to_next_k_path(2) {
zipper.descend_first_k_path(2, &mut ());
while zipper.to_next_k_path(2, &mut ()) {
count += 1;
}
assert_eq!(count, n);
Expand Down Expand Up @@ -291,7 +291,7 @@ fn superdense_zipper_cursor(bencher: Bencher, n: u64) {
bencher.bench_local(|| {
let mut count = 0;
let mut zipper = map.read_zipper();
while zipper.to_next_val() {
while zipper.to_next_val(&mut ()) {
count += 1;
}
assert_eq!(count, n);
Expand Down
71 changes: 52 additions & 19 deletions pathmap-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum PolyZipperTrait {
ZipperMoving,
ZipperIteration,
ZipperConcrete,
ZipperPath,
ZipperAbsolutePath,
ZipperPathBuffer,
ZipperSubtries,
Expand All @@ -33,6 +34,7 @@ impl PolyZipperTrait {
"ZipperMoving" => Some(Self::ZipperMoving),
"ZipperIteration" => Some(Self::ZipperIteration),
"ZipperConcrete" => Some(Self::ZipperConcrete),
"ZipperPath" => Some(Self::ZipperPath),
"ZipperAbsolutePath" => Some(Self::ZipperAbsolutePath),
"ZipperPathBuffer" => Some(Self::ZipperPathBuffer),
"ZipperSubtries" => Some(Self::ZipperSubtries),
Expand All @@ -54,6 +56,7 @@ fn all_poly_zipper_traits() -> BTreeSet<PolyZipperTrait> {
ZipperMoving,
ZipperIteration,
ZipperConcrete,
ZipperPath,
ZipperAbsolutePath,
ZipperPathBuffer,
ZipperSubtries,
Expand Down Expand Up @@ -98,6 +101,11 @@ fn add_trait_dependencies(traits: &mut BTreeSet<PolyZipperTrait>) {
}
}
if traits.contains(&ZipperAbsolutePath) {
if traits.insert(ZipperPath) {
changed = true;
}
}
if traits.contains(&ZipperPath) {
if traits.insert(ZipperMoving) {
changed = true;
}
Expand Down Expand Up @@ -459,19 +467,16 @@ fn derive_poly_zipper_with_traits(
quote! {}
};
Some(quote! {
impl #impl_generics pathmap::zipper::ZipperPath for #enum_name #ty_generics
impl #impl_generics pathmap::zipper::ZipperMoving for #enum_name #ty_generics
#zipper_moving_where
{
fn path(&self) -> &[u8] {
#[inline]
fn depth(&self) -> usize {
match self {
#(#variant_arms => inner.path(),)*
#(#variant_arms => inner.depth(),)*
}
}
}

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(),)*
Expand Down Expand Up @@ -572,6 +577,33 @@ fn derive_poly_zipper_with_traits(
None
};

// Generate ZipperPath trait implementation
let zipper_path_impl = if traits.contains(&PolyZipperTrait::ZipperPath) {
let variant_arms = &variant_arms;
let zipper_path_where = if include_where_clause {
quote! {
where
#(#inner_types: pathmap::zipper::ZipperPath,)*
#where_clause
}
} else {
quote! {}
};
Some(quote! {
impl #impl_generics pathmap::zipper::ZipperPath for #enum_name #ty_generics
#zipper_path_where
{
fn path(&self) -> &[u8] {
match self {
#(#variant_arms => inner.path(),)*
}
}
}
})
} else {
None
};

// Generate ZipperAbsolutePath trait implementation
let zipper_absolute_path_impl = if traits.contains(&PolyZipperTrait::ZipperAbsolutePath) {
let variant_arms = &variant_arms;
Expand Down Expand Up @@ -660,27 +692,27 @@ fn derive_poly_zipper_with_traits(
impl #impl_generics pathmap::zipper::ZipperIteration for #enum_name #ty_generics
#zipper_iteration_where
{
fn to_next_val(&mut self) -> bool {
fn to_next_val<Obs: pathmap::zipper::PathObserver>(&mut self, obs: &mut Obs) -> bool {
match self {
#(#variant_arms => inner.to_next_val(),)*
#(#variant_arms => inner.to_next_val(obs),)*
}
}

fn descend_last_path(&mut self) -> bool {
fn descend_last_path<Obs: pathmap::zipper::PathObserver>(&mut self, obs: &mut Obs) -> bool {
match self {
#(#variant_arms => inner.descend_last_path(),)*
#(#variant_arms => inner.descend_last_path(obs),)*
}
}

fn descend_first_k_path(&mut self, k: usize) -> bool {
fn descend_first_k_path<Obs: pathmap::zipper::PathObserver>(&mut self, k: usize, obs: &mut Obs) -> bool {
match self {
#(#variant_arms => inner.descend_first_k_path(k),)*
#(#variant_arms => inner.descend_first_k_path(k, obs),)*
}
}

fn to_next_k_path(&mut self, k: usize) -> bool {
fn to_next_k_path<Obs: pathmap::zipper::PathObserver>(&mut self, k: usize, obs: &mut Obs) -> bool {
match self {
#(#variant_arms => inner.to_next_k_path(k),)*
#(#variant_arms => inner.to_next_k_path(k, obs),)*
}
}
}
Expand All @@ -705,9 +737,9 @@ fn derive_poly_zipper_with_traits(
impl #impl_generics pathmap::zipper::ZipperReadOnlyIteration<'trie, V> for #enum_name #ty_generics
#zipper_read_only_iteration_where
{
fn to_next_get_val(&mut self) -> Option<&'trie V> {
fn to_next_get_val<Obs: pathmap::zipper::PathObserver>(&mut self, obs: &mut Obs) -> Option<&'trie V> {
match self {
#(#variant_arms => inner.to_next_get_val(),)*
#(#variant_arms => inner.to_next_get_val(obs),)*
}
}
}
Expand All @@ -731,9 +763,9 @@ fn derive_poly_zipper_with_traits(
impl #impl_generics pathmap::zipper::ZipperReadOnlyConditionalIteration<'trie, V> for #enum_name #ty_generics
#zipper_read_only_conditional_iteration_where
{
fn to_next_get_val_with_witness<'w>(&mut self, witness: &'w Self::WitnessT) -> Option<&'w V> where 'trie: 'w {
fn to_next_get_val_with_witness<'w, Obs: pathmap::zipper::PathObserver>(&mut self, witness: &'w Self::WitnessT, obs: &mut Obs) -> Option<&'w V> where 'trie: 'w {
match (self, witness) {
#((Self::#variant_names(inner), #witness_enum_name::#variant_names(w)) => inner.to_next_get_val_with_witness(w),)*
#((Self::#variant_names(inner), #witness_enum_name::#variant_names(w)) => inner.to_next_get_val_with_witness(w, obs),)*
_ => {
debug_assert!(false, "Witness variant must match zipper variant");
None
Expand Down Expand Up @@ -847,6 +879,7 @@ fn derive_poly_zipper_with_traits(
// #zipper_forking_impl
#zipper_moving_impl
#zipper_concrete_impl
#zipper_path_impl
#zipper_absolute_path_impl
#zipper_path_buffer_impl
#zipper_iteration_impl
Expand Down
Loading