Skip to content

Commit

Permalink
style: feat/phase4 formatted (#185)
Browse files Browse the repository at this point in the history
Co-authored-by: metacertain <[email protected]>
Co-authored-by: Viktor Levente Tóth <[email protected]>
Co-authored-by: nugaon <[email protected]>
  • Loading branch information
4 people authored Sep 25, 2023
1 parent 7940be1 commit 0ea3cfb
Show file tree
Hide file tree
Showing 14 changed files with 1,350 additions and 1,305 deletions.
2 changes: 1 addition & 1 deletion deploy/000_deploy_test_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
});

if (process.env.TESTNET_ETHERSCAN_KEY) {
console.log('Verifying...');
log('Verifying...');
await verify(token.address, argsToken);
}
}
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const config: HardhatUserConfig = {
sources: 'src',
},
contractSizer: {
runOnCompile: true,
runOnCompile: false,
},
gasReporter: {
enabled: true,
Expand Down
42 changes: 9 additions & 33 deletions src/OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ library HitchensOrderStatisticsTreeLib {
mapping(uint => Node) nodes;
}

error ValueDoesNotExist(); // Provided value doesn't exist in the tree.
error ValueCannotBeZero(); // Value to insert cannot be zero
error ValueKeyPairExists(); // Value and Key pair exists. Cannot be inserted again.

function first(Tree storage self) internal view returns (uint _value) {
_value = self.root;
if (_value == EMPTY) return 0;
Expand All @@ -80,10 +76,7 @@ library HitchensOrderStatisticsTreeLib {
Tree storage self,
uint value
) internal view returns (uint _parent, uint _left, uint _right, bool _red, uint keyCount, uint __count) {
if (!exists(self, value)) {
revert ValueDoesNotExist();
}

require(exists(self, value), "OrderStatisticsTree(403) - Value does not exist.");
Node storage gn = self.nodes[value];
return (gn.parent, gn.left, gn.right, gn.red, gn.keys.length, gn.keys.length + gn.count);
}
Expand All @@ -94,9 +87,7 @@ library HitchensOrderStatisticsTreeLib {
}

function valueKeyAtIndex(Tree storage self, uint value, uint index) internal view returns (bytes32 _key) {
if (!exists(self, value)) {
revert ValueDoesNotExist();
}
require(exists(self, value), "OrderStatisticsTree(404) - Value does not exist.");
return self.nodes[value].keys[index];
}

Expand Down Expand Up @@ -228,12 +219,11 @@ library HitchensOrderStatisticsTreeLib {
*/

function insert(Tree storage self, bytes32 key, uint value) internal {
if (value == EMPTY) {
revert ValueCannotBeZero();
}
if (keyExists(self, key, value)) {
revert ValueKeyPairExists();
}
require(value != EMPTY, "OrderStatisticsTree(405) - Value to insert cannot be zero");
require(
!keyExists(self, key, value),
"OrderStatisticsTree(406) - Value and Key pair exists. Cannot be inserted again."
);
uint cursor;
uint probe = self.root;
while (probe != EMPTY) {
Expand Down Expand Up @@ -267,23 +257,16 @@ library HitchensOrderStatisticsTreeLib {
}

function remove(Tree storage self, bytes32 key, uint value) internal {
if (value == EMPTY) {
revert ValueCannotBeZero();
}
if (!keyExists(self, key, value)) {
revert ValueDoesNotExist();
}

require(value != EMPTY, "OrderStatisticsTree(407) - Value to delete cannot be zero");
require(keyExists(self, key, value), "OrderStatisticsTree(408) - Value to delete does not exist.");
Node storage nValue = self.nodes[value];
uint rowToDelete = nValue.keyMap[key];
bytes32 last = nValue.keys[nValue.keys.length - uint(1)];
nValue.keys[rowToDelete] = last;
nValue.keyMap[last] = rowToDelete;
nValue.keys.pop();

uint probe;
uint cursor;

if (nValue.keys.length == 0) {
if (self.nodes[value].left == EMPTY || self.nodes[value].right == EMPTY) {
cursor = value;
Expand All @@ -293,16 +276,13 @@ library HitchensOrderStatisticsTreeLib {
cursor = self.nodes[cursor].left;
}
}

if (self.nodes[cursor].left != EMPTY) {
probe = self.nodes[cursor].left;
} else {
probe = self.nodes[cursor].right;
}

uint cursorParent = self.nodes[cursor].parent;
self.nodes[probe].parent = cursorParent;

if (cursorParent != EMPTY) {
if (cursor == self.nodes[cursorParent].left) {
self.nodes[cursorParent].left = probe;
Expand All @@ -312,9 +292,7 @@ library HitchensOrderStatisticsTreeLib {
} else {
self.root = probe;
}

bool doFixup = !self.nodes[cursor].red;

if (cursor != value) {
replaceParent(self, cursor, value);
self.nodes[cursor].left = self.nodes[value].left;
Expand All @@ -325,11 +303,9 @@ library HitchensOrderStatisticsTreeLib {
(cursor, value) = (value, cursor);
fixCountRecurse(self, value);
}

if (doFixup) {
removeFixup(self, probe);
}

fixCountRecurse(self, cursorParent);
delete self.nodes[cursor];
}
Expand Down
Loading

0 comments on commit 0ea3cfb

Please sign in to comment.