Skip to content

Commit

Permalink
bidirectional reference insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
fominok committed Dec 27, 2024
1 parent dd43d6f commit fe66ee7
Show file tree
Hide file tree
Showing 15 changed files with 2,286 additions and 66 deletions.
55 changes: 47 additions & 8 deletions grovedb/src/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub use crate::batch::batch_structure::{OpsByLevelPath, OpsByPath};
use crate::batch::estimated_costs::EstimatedCostsType;
use crate::{
batch::{batch_structure::BatchStructure, mode::BatchRunMode},
bidirectional_references::BidirectionalReference,
element::{MaxReferenceHop, SUM_ITEM_COST_SIZE, SUM_TREE_COST_SIZE, TREE_COST_SIZE},
operations::{get::MAX_REFERENCE_HOPS, proof::util::hex_to_ascii},
reference_path::{
Expand Down Expand Up @@ -1005,13 +1006,23 @@ where
};

match element {
Element::Item(..) | Element::SumItem(..) => {
Element::Item(..)
| Element::SumItem(..)
| Element::ItemWithBackwardsReferences(..)
| Element::SumItemWithBackwardsReferences(..) => {
let serialized =
cost_return_on_error_no_add!(cost, element.serialize(grove_version));
let val_hash = value_hash(&serialized).unwrap_add_cost(&mut cost);
Ok(val_hash).wrap_with_cost(cost)
}
Element::Reference(path, ..) => {
Element::Reference(path, ..)
| Element::BidirectionalReference(
BidirectionalReference {
forward_reference_path: path,
..
},
..,
) => {
let path = cost_return_on_error_no_add!(
cost,
path_from_reference_qualified_path_type(path, qualified_path)
Expand Down Expand Up @@ -1079,7 +1090,10 @@ where
| GroveOp::Replace { element }
| GroveOp::Patch { element, .. } => {
match element {
Element::Item(..) | Element::SumItem(..) => {
Element::Item(..)
| Element::SumItem(..)
| Element::ItemWithBackwardsReferences(..)
| Element::SumItemWithBackwardsReferences(..) => {
let serialized = cost_return_on_error_no_add!(
cost,
element.serialize(grove_version)
Expand Down Expand Up @@ -1126,7 +1140,14 @@ where
}
}
}
Element::Reference(path, ..) => {
Element::Reference(path, ..)
| Element::BidirectionalReference(
BidirectionalReference {
forward_reference_path: path,
..
},
..,
) => {
let path = cost_return_on_error_no_add!(
cost,
path_from_reference_qualified_path_type(
Expand All @@ -1152,13 +1173,23 @@ where
}
}
GroveOp::InsertOnly { element } => match element {
Element::Item(..) | Element::SumItem(..) => {
Element::Item(..)
| Element::SumItem(..)
| Element::ItemWithBackwardsReferences(..)
| Element::SumItemWithBackwardsReferences(..) => {
let serialized =
cost_return_on_error_no_add!(cost, element.serialize(grove_version));
let val_hash = value_hash(&serialized).unwrap_add_cost(&mut cost);
Ok(val_hash).wrap_with_cost(cost)
}
Element::Reference(path, ..) => {
Element::Reference(path, ..)
| Element::BidirectionalReference(
BidirectionalReference {
forward_reference_path: path,
..
},
..,
) => {
let path = cost_return_on_error_no_add!(
cost,
path_from_reference_qualified_path_type(path.clone(), qualified_path)
Expand Down Expand Up @@ -1300,7 +1331,12 @@ where
| GroveOp::InsertOrReplace { element }
| GroveOp::Replace { element }
| GroveOp::Patch { element, .. } => match &element {
Element::Reference(path_reference, element_max_reference_hop, _) => {
Element::Reference(path_reference, element_max_reference_hop, _)
| Element::BidirectionalReference(BidirectionalReference {
forward_reference_path: path_reference,
max_hop: element_max_reference_hop,
..
}) => {
let merk_feature_type = cost_return_on_error!(
&mut cost,
element
Expand Down Expand Up @@ -1365,7 +1401,10 @@ where
)
);
}
Element::Item(..) | Element::SumItem(..) => {
Element::Item(..)
| Element::SumItem(..)
| Element::ItemWithBackwardsReferences(..)
| Element::SumItemWithBackwardsReferences(..) => {
let merk_feature_type = cost_return_on_error!(
&mut cost,
element
Expand Down
Loading

0 comments on commit fe66ee7

Please sign in to comment.