Skip to content

Commit c77aab8

Browse files
committed
Renaming ZipperMovingPriv trait to ZipperPathBuffer trait, and promoting it from internal to external interface, and removing ZipperMoving dependency on that trait. Now, in effect, ZipperMoving is no longer a sealed trait
1 parent 2ba6821 commit c77aab8

6 files changed

Lines changed: 38 additions & 37 deletions

File tree

src/arena_compact.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ use crate::{
8181
utils::{BitMask, ByteMask, find_prefix_overlap},
8282
zipper::{
8383
Zipper, ZipperValues, ZipperForking, ZipperAbsolutePath, ZipperIteration,
84-
ZipperMoving, ZipperMovingPriv, ZipperReadOnlyValues,
84+
ZipperMoving, ZipperPathBuffer, ZipperReadOnlyValues,
8585
ZipperConcretePriv, ZipperConcrete,
8686
},
8787
};
@@ -1381,7 +1381,7 @@ where Storage: AsRef<[u8]>
13811381
}
13821382
}
13831383

1384-
impl<'tree, Storage> ZipperMovingPriv for ACTZipper<'tree, Storage>
1384+
impl<'tree, Storage> ZipperPathBuffer for ACTZipper<'tree, Storage>
13851385
where Storage: AsRef<[u8]>
13861386
{
13871387
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] {

src/experimental.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Zipper for FullZipper {
1717
fn child_mask(&self) -> ByteMask { [!0u64, !0u64, !0u64, !0u64].into() }
1818
}
1919

20-
impl ZipperMovingPriv for FullZipper {
20+
impl ZipperPathBuffer for FullZipper {
2121
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] {
2222
assert!(len <= self.path.capacity());
2323
unsafe{ core::slice::from_raw_parts(self.path.as_ptr(), len) }

src/morphisms.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl SplitCataJumping {
317317
}
318318
}
319319

320-
impl<'a, Z, V: 'a> Catamorphism<V> for Z where Z: Zipper + ZipperReadOnlyValues<'a, V> + ZipperConcrete + ZipperAbsolutePath {
320+
impl<'a, Z, V: 'a> Catamorphism<V> for Z where Z: Zipper + ZipperReadOnlyValues<'a, V> + ZipperConcrete + ZipperAbsolutePath + ZipperPathBuffer {
321321
fn into_cata_side_effect_fallible<W, Err, AlgF>(self, mut alg_f: AlgF) -> Result<W, Err>
322322
where AlgF: FnMut(&ByteMask, &mut [W], Option<&V>, &[u8]) -> Result<W, Err>,
323323
{
@@ -392,7 +392,7 @@ impl<V: 'static + Clone + Send + Sync + Unpin> Catamorphism<V> for BytesTrieMap<
392392
#[inline]
393393
fn cata_side_effect_body<'a, Z, V: 'a, W, Err, AlgF, const JUMPING: bool>(mut z: Z, mut alg_f: AlgF) -> Result<W, Err>
394394
where
395-
Z: Zipper + ZipperReadOnlyValues<'a, V> + ZipperAbsolutePath,
395+
Z: Zipper + ZipperReadOnlyValues<'a, V> + ZipperAbsolutePath + ZipperPathBuffer,
396396
AlgF: FnMut(&ByteMask, &mut [W], usize, Option<&V>, &[u8]) -> Result<W, Err>
397397
{
398398
//`stack` holds a "frame" at each forking point above the zipper position. No frames exist for values
@@ -469,7 +469,7 @@ fn ascend_to_fork<'a, Z, V: 'a, W, Err, AlgF, const JUMPING: bool>(z: &mut Z,
469469
alg_f: &mut AlgF, children: &mut [W]
470470
) -> Result<W, Err>
471471
where
472-
Z: Zipper + ZipperReadOnlyValues<'a, V> + ZipperAbsolutePath,
472+
Z: Zipper + ZipperReadOnlyValues<'a, V> + ZipperAbsolutePath + ZipperPathBuffer,
473473
AlgF: FnMut(&ByteMask, &mut [W], usize, Option<&V>, &[u8]) -> Result<W, Err>
474474
{
475475
let mut w;
@@ -716,7 +716,7 @@ fn into_cata_cached_body<'a, Z, V: 'a, W, E, AlgF, Cache, const JUMPING: bool>(
716716
) -> Result<W, E>
717717
where
718718
Cache: CacheStrategy<W>,
719-
Z: Zipper + ZipperReadOnlyValues<'a, V> + ZipperConcrete + ZipperAbsolutePath,
719+
Z: Zipper + ZipperReadOnlyValues<'a, V> + ZipperConcrete + ZipperAbsolutePath + ZipperPathBuffer,
720720
AlgF: FnMut(&ByteMask, &mut [W], usize, Option<&V>, &[u8]) -> Result<W, E>
721721
{
722722
use gxhash::HashMapExt;

src/product_zipper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<V: Clone + Send + Sync + Unpin> zipper_priv::ZipperPriv for ProductZipper<'
293293
fn try_borrow_focus(&self) -> Option<&dyn TrieNode<Self::V>> { self.z.try_borrow_focus() }
294294
}
295295

296-
impl<V: Clone + Send + Sync + Unpin> zipper_priv::ZipperMovingPriv for ProductZipper<'_, '_, V> {
296+
impl<V: Clone + Send + Sync + Unpin + Unpin> ZipperPathBuffer for ProductZipper<'_, '_, V> {
297297
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] { unsafe{ self.z.origin_path_assert_len(len) } }
298298
fn prepare_buffers(&mut self) { self.z.prepare_buffers() }
299299
fn reserve_buffers(&mut self, path_len: usize, stack_depth: usize) { self.z.reserve_buffers(path_len, stack_depth) }

src/write_zipper.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<'a, 'path, V: Clone + Send + Sync> zipper_priv::ZipperPriv for WriteZipperT
277277
fn try_borrow_focus(&self) -> Option<&dyn TrieNode<Self::V>> { self.z.try_borrow_focus() }
278278
}
279279

280-
impl<'a, 'path, V: Clone + Send + Sync> zipper_priv::ZipperMovingPriv for WriteZipperTracked<'a, 'path, V> {
280+
impl<'a, 'path, V: Clone + Send + Sync + Unpin> ZipperPathBuffer for WriteZipperTracked<'a, 'path, V> {
281281
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] { unsafe{ self.z.origin_path_assert_len(len) } }
282282
fn prepare_buffers(&mut self) { self.z.prepare_buffers() }
283283
fn reserve_buffers(&mut self, path_len: usize, stack_depth: usize) { self.z.reserve_buffers(path_len, stack_depth) }
@@ -414,7 +414,7 @@ impl<'a, 'k, V: Clone + Send + Sync> zipper_priv::ZipperPriv for WriteZipperUntr
414414
fn try_borrow_focus(&self) -> Option<&dyn TrieNode<Self::V>> { self.z.try_borrow_focus() }
415415
}
416416

417-
impl<'a, 'k, V: Clone + Send + Sync> zipper_priv::ZipperMovingPriv for WriteZipperUntracked<'a, 'k, V> {
417+
impl<'a, 'k, V: Clone + Send + Sync + Unpin> ZipperPathBuffer for WriteZipperUntracked<'a, 'k, V> {
418418
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] { unsafe{ self.z.origin_path_assert_len(len) } }
419419
fn prepare_buffers(&mut self) { self.z.prepare_buffers() }
420420
fn reserve_buffers(&mut self, path_len: usize, stack_depth: usize) { self.z.reserve_buffers(path_len, stack_depth) }
@@ -575,7 +575,7 @@ impl<V: Clone + Send + Sync> zipper_priv::ZipperPriv for WriteZipperOwned<V> {
575575
fn try_borrow_focus(&self) -> Option<&dyn TrieNode<Self::V>> { self.z.try_borrow_focus() }
576576
}
577577

578-
impl<V: Clone + Send + Sync> zipper_priv::ZipperMovingPriv for WriteZipperOwned<V> {
578+
impl<V: Clone + Send + Sync + Unpin> ZipperPathBuffer for WriteZipperOwned<V> {
579579
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] { unsafe{ self.z.origin_path_assert_len(len) } }
580580
fn prepare_buffers(&mut self) { self.z.prepare_buffers() }
581581
fn reserve_buffers(&mut self, path_len: usize, stack_depth: usize) { self.z.reserve_buffers(path_len, stack_depth) }
@@ -872,7 +872,7 @@ impl<V: Clone + Send + Sync + Unpin> ZipperMoving for WriteZipperCore<'_, '_, V>
872872
}
873873
}
874874

875-
impl<'a, 'k, V: Clone + Send + Sync> zipper_priv::ZipperPriv for WriteZipperCore<'a, 'k, V> {
875+
impl<'a, 'k, V: Clone + Send + Sync > zipper_priv::ZipperPriv for WriteZipperCore<'a, 'k, V> {
876876
type V = V;
877877

878878
fn get_focus(&self) -> AbstractNodeRef<Self::V> {
@@ -895,7 +895,7 @@ impl<'a, 'k, V: Clone + Send + Sync> zipper_priv::ZipperPriv for WriteZipperCore
895895
}
896896
}
897897

898-
impl<'a, 'k, V: Clone + Send + Sync> zipper_priv::ZipperMovingPriv for WriteZipperCore<'a, 'k, V> {
898+
impl<'a, 'k, V: Clone + Send + Sync + Unpin> ZipperPathBuffer for WriteZipperCore<'a, 'k, V> {
899899
unsafe fn origin_path_assert_len(&self, _len: usize) -> &[u8] {
900900
unimplemented!()
901901
}

src/zipper.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub trait ZipperSubtries<V: Clone + Send + Sync>: ZipperValues<V> + zipper_priv:
113113
/// A zipper's **origin** is always equal-to-or-above the zipper's root. The position of the origin depends
114114
/// on how the zipper was created, and the origin will never be below the root. The origin of a given zipper
115115
/// will never change.
116-
pub trait ZipperMoving: Zipper + ZipperMovingPriv {
116+
pub trait ZipperMoving: Zipper {
117117
/// Returns `true` if the zipper's focus is at its root, and it cannot ascend further, otherwise returns `false`
118118
fn at_root(&self) -> bool {
119119
self.path().len() == 0
@@ -501,6 +501,24 @@ pub trait ZipperConcrete: zipper_priv::ZipperConcretePriv {
501501
fn is_shared(&self) -> bool;
502502
}
503503

504+
/// Provides more direct control over a [ZipperMoving] zipper's path buffer
505+
pub trait ZipperPathBuffer: ZipperMoving {
506+
/// Internal method to get the path, beyond its length. Panics if `len` > the path's capacity, or
507+
/// if the zipper is relative and doesn't have an `origin_path`
508+
///
509+
/// This method is unsafe because it relies on the caller to not read uninitialized memory, even if
510+
/// the memory has been allocated.
511+
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8];
512+
513+
/// Make sure the path buffer is allocated, to facilitate zipper movement
514+
fn prepare_buffers(&mut self);
515+
516+
/// Reserve buffer space within the zipper's path buffer and node stack
517+
///
518+
/// This method will only grow the buffers and will never shrink them.
519+
fn reserve_buffers(&mut self, path_len: usize, stack_depth: usize);
520+
}
521+
504522
pub(crate) mod zipper_priv {
505523
use super::*;
506524

@@ -547,23 +565,6 @@ pub(crate) mod zipper_priv {
547565
fn try_borrow_focus(&self) -> Option<&dyn TrieNode<Self::V>>;
548566
}
549567

550-
pub trait ZipperMovingPriv {
551-
/// Internal method to get the path, beyond its length. Panics if `len` > the path's capacity, or
552-
/// if the zipper is relative and doesn't have an `origin_path`
553-
///
554-
/// This method is unsafe because it relies on the caller to not read uninitialized memory, even if
555-
/// the memory has been allocated.
556-
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8];
557-
558-
/// Make sure the path buffer is allocated, to facilitate zipper movement
559-
fn prepare_buffers(&mut self);
560-
561-
/// Reserve buffer space within the zipper's path buffer and node stack
562-
///
563-
/// This method will only grow the buffers and will never shrink them.
564-
fn reserve_buffers(&mut self, path_len: usize, stack_depth: usize);
565-
}
566-
567568
pub trait ZipperReadOnlyPriv<'a, V: Clone + Send + Sync> {
568569
/// Internal method returns the minimal components that compose the zipper, which are:
569570
///
@@ -595,7 +596,7 @@ pub(crate) mod zipper_priv {
595596
}
596597
}
597598
use zipper_priv::*;
598-
pub use zipper_priv::{ZipperMovingPriv, ZipperConcretePriv};
599+
pub use zipper_priv::ZipperConcretePriv;
599600

600601
impl<Z> Zipper for &mut Z where Z: Zipper {
601602
fn path_exists(&self) -> bool { (**self).path_exists() }
@@ -671,7 +672,7 @@ impl<V: Clone + Send + Sync, Z> ZipperPriv for &mut Z where Z: ZipperPriv<V=V> {
671672
fn try_borrow_focus(&self) -> Option<&dyn TrieNode<Self::V>> { (**self).try_borrow_focus() }
672673
}
673674

674-
impl<Z> ZipperMovingPriv for &mut Z where Z: ZipperMovingPriv {
675+
impl<Z> ZipperPathBuffer for &mut Z where Z: ZipperPathBuffer {
675676
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] { (**self).origin_path_assert_len(len) }
676677
fn prepare_buffers(&mut self) { (**self).prepare_buffers() }
677678
fn reserve_buffers(&mut self, path_len: usize, stack_depth: usize) { (**self).reserve_buffers(path_len, stack_depth) }
@@ -781,7 +782,7 @@ impl<V: Clone + Send + Sync + Unpin> zipper_priv::ZipperPriv for ReadZipperTrack
781782
fn try_borrow_focus(&self) -> Option<&dyn TrieNode<Self::V>> { self.z.try_borrow_focus() }
782783
}
783784

784-
impl<V: Clone + Send + Sync + Unpin> zipper_priv::ZipperMovingPriv for ReadZipperTracked<'_, '_, V> {
785+
impl<V: Clone + Send + Sync + Unpin> ZipperPathBuffer for ReadZipperTracked<'_, '_, V> {
785786
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] { unsafe{ self.z.origin_path_assert_len(len) } }
786787
fn prepare_buffers(&mut self) { self.z.prepare_buffers() }
787788
fn reserve_buffers(&mut self, path_len: usize, stack_depth: usize) { self.z.reserve_buffers(path_len, stack_depth) }
@@ -931,7 +932,7 @@ impl<V: Clone + Send + Sync + Unpin> zipper_priv::ZipperPriv for ReadZipperUntra
931932
fn try_borrow_focus(&self) -> Option<&dyn TrieNode<Self::V>> { self.z.try_borrow_focus() }
932933
}
933934

934-
impl<V: Clone + Send + Sync + Unpin> zipper_priv::ZipperMovingPriv for ReadZipperUntracked<'_, '_, V> {
935+
impl<V: Clone + Send + Sync + Unpin> ZipperPathBuffer for ReadZipperUntracked<'_, '_, V> {
935936
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] { unsafe{ self.z.origin_path_assert_len(len) } }
936937
fn prepare_buffers(&mut self) { self.z.prepare_buffers() }
937938
fn reserve_buffers(&mut self, path_len: usize, stack_depth: usize) { self.z.reserve_buffers(path_len, stack_depth) }
@@ -1130,7 +1131,7 @@ impl<V: Clone + Send + Sync + Unpin> zipper_priv::ZipperPriv for ReadZipperOwned
11301131
fn try_borrow_focus(&self) -> Option<&dyn TrieNode<Self::V>> { self.z.try_borrow_focus() }
11311132
}
11321133

1133-
impl<V: Clone + Send + Sync + Unpin> zipper_priv::ZipperMovingPriv for ReadZipperOwned<V> {
1134+
impl<V: Clone + Send + Sync + Unpin> ZipperPathBuffer for ReadZipperOwned<V> {
11341135
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] { unsafe{ self.z.origin_path_assert_len(len) } }
11351136
fn prepare_buffers(&mut self) { self.z.prepare_buffers() }
11361137
fn reserve_buffers(&mut self, path_len: usize, stack_depth: usize) { self.z.reserve_buffers(path_len, stack_depth) }
@@ -1617,7 +1618,7 @@ pub(crate) mod read_zipper_core {
16171618
}
16181619
}
16191620

1620-
impl<V: Clone + Send + Sync + Unpin> zipper_priv::ZipperMovingPriv for ReadZipperCore<'_, '_, V> {
1621+
impl<V: Clone + Send + Sync + Unpin> ZipperPathBuffer for ReadZipperCore<'_, '_, V> {
16211622
unsafe fn origin_path_assert_len(&self, len: usize) -> &[u8] {
16221623
if self.prefix_buf.capacity() > 0 {
16231624
assert!(len <= self.prefix_buf.capacity());

0 commit comments

Comments
 (0)