From 8608a66081d414ebfb1cc722a03da36696e622d6 Mon Sep 17 00:00:00 2001 From: Orion Yeung <11580988+orionyeung001@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:37:15 -0500 Subject: [PATCH 1/4] feat: impl `Hash` for BPlusTree NOTE: uses `::write_usize` instead of `write_length_prefix` --- src/tree/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/tree/mod.rs b/src/tree/mod.rs index fa7518a..d5de9c2 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -1,6 +1,6 @@ mod inner_node; mod slice_utils; -use std::{borrow::Borrow, mem::ManuallyDrop}; +use std::{borrow::Borrow, hash::Hash, mem::ManuallyDrop}; mod consts; @@ -822,6 +822,19 @@ impl IntoIterator for BPlusTree { } } +impl Hash for BPlusTree +where + S::K: Hash, + S::V: Hash, +{ + fn hash(&self, state: &mut H) { + state.write_usize(self.len()); // consider `state.write_length_prefix(self.len());` + for elt in self.iter() { + elt.hash(state); + } + } +} + /// Statistic data used to guide the perf tuning #[derive(Default, Debug, Clone)] pub struct Statistic { From ef1160187ee3bf1351c2f9ad882d4e7c66287172 Mon Sep 17 00:00:00 2001 From: Orion Yeung <11580988+orionyeung001@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:48:01 -0500 Subject: [PATCH 2/4] feat: derive Debug --- src/tree/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tree/mod.rs b/src/tree/mod.rs index d5de9c2..435ddfd 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -83,7 +83,7 @@ mod tree_remove; /// // now cursor_1 should retrieve the new value /// assert_eq!(cursor_1.value(&tree).unwrap().0, 100.); /// ``` -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct BPlusTree { root: NodeId, root_augmentation: S::Augmentation, From 17e3bfdd088ca61fa813e165ff93a919d0d92676 Mon Sep 17 00:00:00 2001 From: Orion Yeung <11580988+orionyeung001@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:48:30 -0500 Subject: [PATCH 3/4] feat: impl Default for BPlusTree using vec backed node store --- src/tree/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 435ddfd..30e9709 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -835,6 +835,17 @@ where } } +impl Default for BPlusTree> +where + K: Default + Key, + V: Default, + A: Augmentation, +{ + fn default() -> Self { + Self::new(NodeStoreVec::new()) + } +} + /// Statistic data used to guide the perf tuning #[derive(Default, Debug, Clone)] pub struct Statistic { From 540a668af3e2d7f83fbc93bd8ced9405856a6807 Mon Sep 17 00:00:00 2001 From: Orion Yeung <11580988+orionyeung001@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:51:40 -0500 Subject: [PATCH 4/4] feat: impl PartialEq for BPlusTree --- src/tree/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 30e9709..082b92d 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -846,6 +846,16 @@ where } } +impl PartialEq for BPlusTree +where + S::K: PartialEq, + S::V: PartialEq, +{ + fn eq(&self, other: &Self) -> bool { + self.iter().eq(other.iter()) + } +} + /// Statistic data used to guide the perf tuning #[derive(Default, Debug, Clone)] pub struct Statistic {