Skip to content
Closed
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
10 changes: 6 additions & 4 deletions durable-storage/benches/avl_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use criterion::Criterion;
use criterion::criterion_group;
use criterion::criterion_main;
use octez_riscv_durable_storage::avl::Tree;
use octez_riscv_durable_storage::avl::resolver::ArcResolver;
use octez_riscv_durable_storage::key::Key;
use octez_riscv_durable_storage::random::generate_keys;
use octez_riscv_durable_storage::random::generate_random_bytes_in_range;
Expand Down Expand Up @@ -47,12 +48,13 @@ fn get_operations_batch(mut rng: &mut impl Rng, keys: &[Key], batch_size: usize)
fn bench_avl_tree_operations(c: &mut Criterion) {
let mut rng = rand::rng();
let keys = generate_keys(&mut rng, KEY_COUNT);
let mut resolver = ArcResolver;

// Setting up the tree
let mut tree = Tree::default();
for key in &keys[..keys.len() / 2] {
let random_data = generate_random_bytes_in_range(&mut rng, 1..20);
tree.set(key, &random_data);
tree.set(key, &random_data, &mut resolver);
}

c.bench_function("Bench AVL tree with operations", |b| {
Expand All @@ -62,13 +64,13 @@ fn bench_avl_tree_operations(c: &mut Criterion) {
for operation in operations {
match operation {
Operation::Get(key) => {
tree.get(&key);
tree.get(&key, &resolver);
}
Operation::Upsert(key, value) => {
tree.set(&key, &value);
tree.set(&key, &value, &mut resolver);
}
Operation::Delete(key) => {
tree.delete(&key);
tree.delete(&key, &mut resolver);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion durable-storage/src/avl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Implementation of a Merkleisable AVL tree.

pub(crate) mod node;
pub(crate) mod resolver;
pub mod resolver;

cfg_if::cfg_if! {
if #[cfg(feature = "bench")] {
Expand Down
2 changes: 1 addition & 1 deletion durable-storage/src/avl/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub type Value = Bytes<Normal>;

/// A node that supports rebalancing and Merklisation.
#[derive(Clone, Default, Debug)]
pub(crate) struct Node {
pub struct Node {
key: Key,
data: Value,
left: Tree,
Expand Down
4 changes: 2 additions & 2 deletions durable-storage/src/avl/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use std::sync::Arc;

/// Trait for resolving identifiers to values.
pub(crate) trait Resolver<Id, Value> {
pub trait Resolver<Id, Value> {
/// Resolve an identifier to a value.
fn resolve<'a>(&self, id: &'a Id) -> &'a Value;

Expand All @@ -20,7 +20,7 @@ pub(crate) trait Resolver<Id, Value> {

/// Provide values identified by an [`Arc`].
#[derive(Clone, Debug)]
pub(crate) struct ArcResolver;
pub struct ArcResolver;

impl<T: Clone> Resolver<Arc<T>, T> for ArcResolver {
fn resolve<'a>(&self, id: &'a Arc<T>) -> &'a T {
Expand Down
3 changes: 1 addition & 2 deletions durable-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@

cfg_if::cfg_if! {
if #[cfg(feature = "bench")] {
pub mod avl;
pub mod merkle_layer;
pub mod merkle_worker;
pub mod persistence_layer;
pub mod repo;
pub mod random;
} else {
mod avl;
mod merkle_layer;
mod merkle_worker;
#[cfg_attr(not(test), expect(dead_code, reason = "Incomplete"))]
Expand All @@ -46,6 +44,7 @@ cfg_if::cfg_if! {
}
}

pub mod avl;
pub mod commit;
pub mod database;
pub mod key;
Expand Down
Loading