From e4a08303c0f01bd1e66cecf6f8aaf1bc898715c7 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Thu, 24 Apr 2025 15:15:29 +0200 Subject: [PATCH 1/2] cleanup --- src/btreemap.rs | 76 ++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/src/btreemap.rs b/src/btreemap.rs index 7d7caa3a..55651cef 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -1310,10 +1310,40 @@ mod test { } } - macro_rules! verify_and_run { - ($runner:ident, $K:ty, $V:ty) => {{ + /// Asserts that the associated `BOUND` for `$ty` is _not_ `Unbounded`. + macro_rules! assert_bounded { + ($ty:ty) => { + assert_ne!(<$ty>::BOUND, StorableBound::Unbounded, "Must be Bounded"); + }; + } + + /// Asserts that the associated `BOUND` for `$ty` _is_ `Unbounded`. + macro_rules! assert_unbounded { + ($ty:ty) => { + assert_eq!(<$ty>::BOUND, StorableBound::Unbounded, "Must be Unbounded"); + }; + } + + macro_rules! run_with_key { + ($runner:ident, $K:ty) => {{ verify_monotonic::<$K>(); - $runner::<$K, $V>(); + + // Empty value. + $runner::<$K, ()>(); + + // Bounded values. + assert_bounded!(u32); + $runner::<$K, u32>(); + + assert_bounded!(Blob<20>); + $runner::<$K, Blob<20>>(); + + // Unbounded values. + assert_unbounded!(MonotonicVec32); + $runner::<$K, MonotonicVec32>(); + + assert_unbounded!(MonotonicString32); + $runner::<$K, MonotonicString32>(); }}; } @@ -1322,37 +1352,19 @@ mod test { ($name:ident, $runner:ident) => { #[test] fn $name() { - use StorableBound::Unbounded; - - // Set, empty value, bounded. - { - type Value = (); - assert_ne!(::BOUND, Unbounded, "Must be Bounded"); - verify_and_run!($runner, u32, Value); - verify_and_run!($runner, Blob<10>, Value); - verify_and_run!($runner, MonotonicVec32, Value); - verify_and_run!($runner, MonotonicString32, Value); - } + // Bounded keys. + assert_bounded!(u32); + run_with_key!($runner, u32); - // Map, bounded value. - { - type Value = u32; - assert_ne!(Value::BOUND, Unbounded, "Must be Bounded"); - verify_and_run!($runner, u32, Value); - verify_and_run!($runner, Blob<10>, Value); - verify_and_run!($runner, MonotonicVec32, Value); - verify_and_run!($runner, MonotonicString32, Value); - } + assert_bounded!(Blob<10>); + run_with_key!($runner, Blob<10>); - // Map, unbounded value. - { - type Value = MonotonicVec32; - assert_eq!(Value::BOUND, Unbounded, "Must be Unbounded"); - verify_and_run!($runner, u32, Value); - verify_and_run!($runner, Blob<10>, Value); - verify_and_run!($runner, MonotonicVec32, Value); - verify_and_run!($runner, MonotonicString32, Value); - } + // Unbounded keys. + assert_unbounded!(MonotonicVec32); + run_with_key!($runner, MonotonicVec32); + + assert_unbounded!(MonotonicString32); + run_with_key!($runner, MonotonicString32); } }; } From 394d3b64df4c86f92e9f78ff5a87e1844df1fa68 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Thu, 24 Apr 2025 15:19:45 +0200 Subject: [PATCH 2/2] . --- src/btreemap/node/v1.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/btreemap/node/v1.rs b/src/btreemap/node/v1.rs index 2dc02857..e8f533dc 100644 --- a/src/btreemap/node/v1.rs +++ b/src/btreemap/node/v1.rs @@ -14,10 +14,14 @@ //! Node type ↕ 1 byte //! ---------------------------------------- //! # Entries (k) ↕ 2 bytes -//! ---------------------------------------- <-- Entries (upto `CAPACITY` entries) -//! Key(0) +//! ---------------------------------------- <-- Entries (up to `CAPACITY` entries) +//! Key(0) size ↕ 4 bytes //! ---------------------------------------- -//! Value(0) +//! Key(0) ↕ `max_key_size` bytes +//! ---------------------------------------- +//! Value(0) size ↕ 4 bytes +//! ---------------------------------------- +//! Value(0) ↕ `max_value_size` bytes //! ---------------------------------------- //! Key(1) size ↕ 4 bytes //! ---------------------------------------- @@ -28,7 +32,7 @@ //! Value(1) ↕ `max_value_size` bytes //! ---------------------------------------- //! ... -//! ---------------------------------------- <-- Children (upto `CAPACITY + 1` children) +//! ---------------------------------------- <-- Children (up to `CAPACITY + 1` children) //! Child(0) address ↕ 8 bytes //! ---------------------------------------- //! ...