Skip to content

Commit

Permalink
fixing small bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout authored and AbdelStark committed May 10, 2023
1 parent dbe5379 commit 46f5a93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
3 changes: 0 additions & 3 deletions quaireaux/data_structures/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Data structures

TODO Ongoing

## [Array extension](./src/array_ext.cairo)
A collection of handy functions to help with array manipulation.

Expand Down
35 changes: 15 additions & 20 deletions quaireaux/data_structures/src/merkle_tree.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,24 @@ impl MerkleTreeImpl of MerkleTreeTrait {
fn compute_root(
ref self: MerkleTree, mut current_node: felt252, mut proof: Span<felt252>
) -> felt252 {
let mut proof_len = proof.len();
let mut current_node = current_node;
let mut proof_index = 0;

// TODO We could pop_front proof and get rid of proof_len and proof_index
// But due to a bug it cannot atm.
loop {
if proof_len == 0 {
break current_node;
}
// Get the next element of the proof.
let proof_element = *proof[proof_index];

// Compute the hash of the current node and the current element of the proof.
// We need to check if the current node is smaller than the current element of the proof.
// If it is, we need to swap the order of the hash.
if current_node.into() < proof_element.into() {
current_node = LegacyHash::hash(current_node, proof_element);
} else {
current_node = LegacyHash::hash(proof_element, current_node);
}
proof_index = proof_index + 1;
proof_len = proof_len - 1;
match proof.pop_front() {
Option::Some(proof_element) => {
// Compute the hash of the current node and the current element of the proof.
// We need to check if the current node is smaller than the current element of the proof.
// If it is, we need to swap the order of the hash.
if current_node.into() < (*proof_element).into() {
current_node = LegacyHash::hash(current_node, *proof_element);
} else {
current_node = LegacyHash::hash(*proof_element, current_node);
}
},
Option::None(()) => {
break current_node;
},
};
}
}

Expand Down
4 changes: 0 additions & 4 deletions quaireaux/math/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,3 @@ Zeller's congruence algorithm is used to determine the day of the week for a giv
The purpose of the algorithm is to provide a simple and efficient way to calculate the day of the week based on the date.
It is widely used in various applications, including calendar systems, scheduling, and time management.
The algorithm takes into account the year, month, and day of the given date and performs a series of mathematical calculations to determine the day of the week. By providing an easy-to-use method for calculating the day of the week, Zeller's congruence algorithm is an important tool for many industries and organizations that rely on accurate and efficient time management systems.


## TODO To be fixed:
- [x] [Karatsuba Multiplication Algorithm](./src/karatsuba.cairo)

0 comments on commit 46f5a93

Please sign in to comment.