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
13 changes: 5 additions & 8 deletions src/dense_byte_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,14 +636,11 @@ impl<V: Clone + Send + Sync, A: Allocator> CellByteNode<V, A> {
}
let cf = self.get_mut(k).unwrap();
let (rec, val) = cf.both_mut_refs();
let rec = match rec {
Some(rec) => rec,
None => {
*rec = Some(TrieNodeODRc::new_allocated_in(0, 0, alloc));
rec.as_mut().unwrap()
}
};
(rec, val)
//A zipper can't be rooted at the empty sentinel, so an emptied link gets a real node too
if rec.as_ref().map_or(true, |rec| rec.is_empty()) {
*rec = Some(TrieNodeODRc::new_allocated_in(0, 0, alloc));
}
(rec.as_mut().unwrap(), val)
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/zipper_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,4 +1637,34 @@ mod tests {
}
}
}

/// An exclusive zipper rooted at a link emptied by `remove_branches`, `take_map` or a graft of nothing
#[test]
fn exclusive_zipper_at_emptied_link() {
let preps: [fn(&mut WriteZipperUntracked<u64>); 4] = [
|z| { z.remove_branches(false); },
|z| { z.take_map(false); },
|z| { let e = PathMap::<u64>::new(); z.graft(&e.read_zipper()); },
|z| { let e = PathMap::<u64>::new(); z.restrict(&e.read_zipper()); },
];
for (i, prep) in preps.iter().enumerate() {
let mut map = PathMap::<u64>::new();
for p in [&[0u8, 0, 1][..], &[0, 0, 1, 2], &[0]] { map.set_val_at(p, 1); }
{
let mut wz = map.write_zipper_at_path(&[0u8, 0]);
prep(&mut wz);
let zh = wz.zipper_head();
let mut w = zh.write_zipper_at_exclusive_path(&[]).unwrap();
assert!(!w.descend_to_existing_byte(1), "prep {i}");
w.descend_to(&[7u8, 7]);
assert!(!w.path_exists(), "prep {i}");
assert_eq!(w.ascend_until(), 2, "prep {i}");
w.descend_to(&[7u8, 7]);
w.set_val(5);
}
assert_eq!(map.get(&[0u8, 0, 7, 7]), Some(&5), "prep {i}");
assert_eq!(map.get(&[0u8]), Some(&1), "prep {i}");
assert_eq!(map.val_count(), 2, "prep {i}");
}
}
}