Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/bidirectional…
Browse files Browse the repository at this point in the history
…_references
  • Loading branch information
fominok committed Jan 23, 2025
2 parents fe66ee7 + 44c2244 commit 719b44f
Show file tree
Hide file tree
Showing 140 changed files with 9,457 additions and 4,240 deletions.
6 changes: 3 additions & 3 deletions costs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grovedb-costs"
version = "2.1.0"
version = "3.0.0"
edition = "2021"
license = "MIT"
description = "Costs extension crate for GroveDB"
Expand All @@ -10,6 +10,6 @@ repository = "https://github.com/dashpay/grovedb"


[dependencies]
thiserror = "1.0.59"
intmap = "2.0.0"
thiserror = "2.0.11"
intmap = "3.0.1"
integer-encoding = "4.0.0"
2 changes: 1 addition & 1 deletion costs/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<T> CostsExt for T {}
/// 1. Early termination on error;
/// 2. Because of 1, `Result` is removed from the equation;
/// 3. `CostContext` is removed too because it is added to external cost
/// accumulator;
/// accumulator;
/// 4. Early termination uses external cost accumulator so previous costs won't
/// be lost.
#[macro_export]
Expand Down
35 changes: 28 additions & 7 deletions costs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,29 @@ pub type ChildrenSizesWithValue = Option<(
Option<(ChildKeyLength, ChildSumLength)>,
)>;

/// The tree cost type
pub enum TreeCostType {
/// This is for sum trees and count trees
TreeFeatureUsesVarIntCostAs8Bytes,
/// This is for count sum trees
TreeFeatureUsesTwoVarIntsCostAs16Bytes,
/// This is for big sum trees
TreeFeatureUses16Bytes,
}

impl TreeCostType {
fn cost_size(&self) -> u32 {
match self {
TreeCostType::TreeFeatureUsesVarIntCostAs8Bytes => 8,
TreeCostType::TreeFeatureUsesTwoVarIntsCostAs16Bytes => 16,
TreeCostType::TreeFeatureUses16Bytes => 16,
}
}
}

/// Children sizes starting with if we are in a sum tree
pub type ChildrenSizesWithIsSumTree = Option<(
Option<FeatureSumLength>,
Option<(TreeCostType, FeatureSumLength)>,
Option<(ChildKeyLength, ChildSumLength)>,
Option<(ChildKeyLength, ChildSumLength)>,
)>;
Expand Down Expand Up @@ -199,20 +219,21 @@ impl OperationCost {
paid_value_len -= right_child_sum_len;
}

if let Some(sum_tree_len) = in_sum_tree {
let sum_tree_node_size = if let Some((tree_cost_type, sum_tree_len)) = in_sum_tree {
let cost_size = tree_cost_type.cost_size();
paid_value_len -= sum_tree_len;
paid_value_len += 8;
}
paid_value_len += cost_size;
cost_size
} else {
0
};

// This is the moment we need to add the required space (after removing
// children) but before adding the parent to child hook
paid_value_len += paid_value_len.required_space() as u32;

// Now we are the parent to child hook

// we need to add the sum tree node size
let sum_tree_node_size = if in_sum_tree.is_some() { 8 } else { 0 };

// We need to add the cost of a parent
// key_len has a hash length already in it from the key prefix
// So we need to remove it and then add a hash length
Expand Down
8 changes: 4 additions & 4 deletions costs/src/storage_cost/removal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ use crate::storage_cost::removal::StorageRemovedBytes::{
pub type Identifier = [u8; 32];

/// Unknown Epoch
pub const UNKNOWN_EPOCH: u64 = u64::MAX;
pub const UNKNOWN_EPOCH: u16 = u16::MAX;

/// A BTreeMap mapping identities to the storage they removed by epoch
pub type StorageRemovalPerEpochByIdentifier = BTreeMap<Identifier, IntMap<u32>>;
pub type StorageRemovalPerEpochByIdentifier = BTreeMap<Identifier, IntMap<u16, u32>>;

/// Removal bytes
#[derive(Debug, PartialEq, Clone, Eq, Default)]
Expand Down Expand Up @@ -122,7 +122,7 @@ impl Add for StorageRemovedBytes {
};
(k, combined)
})
.collect::<IntMap<u32>>();
.collect::<IntMap<u16, u32>>();
intersection.into_iter().chain(int_map_b).collect()
} else {
int_map_b
Expand Down Expand Up @@ -193,7 +193,7 @@ impl AddAssign for StorageRemovedBytes {
};
(k, combined)
})
.collect::<IntMap<u32>>();
.collect::<IntMap<u16, u32>>();
intersection.into_iter().chain(int_map_b).collect()
} else {
int_map_b
Expand Down
8 changes: 4 additions & 4 deletions grovedb-epoch-based-storage-flags/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
name = "grovedb-epoch-based-storage-flags"
authors = ["Samuel Westrich <sam@dash.org>"]
description = "Epoch based storage flags for GroveDB"
version = "2.1.0"
version = "3.0.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/dashpay/grovedb"

[dependencies]
grovedb-costs = { version = "2.1.0", path = "../costs" }
grovedb-costs = { version = "3.0.0", path = "../costs" }

hex = { version = "0.4.3" }
integer-encoding = { version = "4.0.0" }
intmap = { version = "2.0.0", features = ["serde"]}
thiserror = { version = "1.0.63" }
intmap = { version = "3.0.1", features = ["serde"]}
thiserror = { version = "2.0.11" }
Loading

0 comments on commit 719b44f

Please sign in to comment.