From dcac13e4cbe62a50c017b9d3474cc5f2eb4280d7 Mon Sep 17 00:00:00 2001 From: Billy Rennekamp Date: Thu, 17 Oct 2024 07:22:05 +0200 Subject: [PATCH] fix rank --- contracts/HitchensOrderStatisticsTreeLib.sol | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/contracts/HitchensOrderStatisticsTreeLib.sol b/contracts/HitchensOrderStatisticsTreeLib.sol index bded16f..93baff6 100644 --- a/contracts/HitchensOrderStatisticsTreeLib.sol +++ b/contracts/HitchensOrderStatisticsTreeLib.sol @@ -161,7 +161,12 @@ library HitchensOrderStatisticsTreeLib { } else { cursor = c.left; c = self.nodes[cursor]; - smaller -= (keyCount + getNodeCount(self,c.right)); + if (smaller >= (keyCount + getNodeCount(self, c.right))) { + smaller -= (keyCount + getNodeCount(self, c.right)); + } else { + smaller = 0; + finished = true; + } } } if (!exists(self,cursor)) { @@ -191,7 +196,12 @@ library HitchensOrderStatisticsTreeLib { } else { cursor = c.left; c = self.nodes[cursor]; - smaller -= (keyCount + getNodeCount(self,c.right)); + if (smaller >= (keyCount + getNodeCount(self, c.right))) { + smaller -= (keyCount + getNodeCount(self, c.right)); + } else { + smaller = 0; + finished = true; + } } } if (!exists(self,cursor)) {