Skip to content

Commit

Permalink
Renamed "recalculate_values" to "sync_range_and_value"
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbarr93 committed Mar 16, 2024
1 parent 66d08a8 commit f69a8dc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions contracts/sumtree-orderbook/src/sumtree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ impl TreeNode {
self.set_value(self.get_value().checked_add(value)?)
}

// TODO: This can likely be optimized
/// Recalculates the range and accumulated value for a node and propagates it up the tree
pub fn recalculate_values(&mut self, storage: &mut dyn Storage) -> ContractResult<()> {
///
/// Must be an internal node
pub fn sync_range_and_value(&mut self, storage: &mut dyn Storage) -> ContractResult<()> {
ensure!(self.is_internal(), ContractError::InvalidNodeType);
let maybe_left = self.get_left(storage)?;
let maybe_right = self.get_right(storage)?;
Expand Down Expand Up @@ -240,7 +241,7 @@ impl TreeNode {
self.save(storage)?;

if let Some(mut parent) = self.get_parent(storage)? {
parent.recalculate_values(storage)?;
parent.sync_range_and_value(storage)?;
}

Ok(())
Expand Down Expand Up @@ -449,7 +450,7 @@ impl TreeNode {
parent.delete(storage)?;
} else {
// Update parents values after removing node
parent.recalculate_values(storage)?;
parent.sync_range_and_value(storage)?;
}
}

Expand Down

0 comments on commit f69a8dc

Please sign in to comment.