diff --git a/contracts/HitchensOrderStatisticsTreeLib.sol b/contracts/HitchensOrderStatisticsTreeLib.sol index bded16f..91188b6 100644 --- a/contracts/HitchensOrderStatisticsTreeLib.sol +++ b/contracts/HitchensOrderStatisticsTreeLib.sol @@ -236,8 +236,9 @@ library HitchensOrderStatisticsTreeLib { require(keyExists(self,key,value), "OrderStatisticsTree(408) - Value to delete does not exist."); Node storage nValue = self.nodes[value]; uint rowToDelete = nValue.keyMap[key]; - nValue.keys[rowToDelete] = nValue.keys[nValue.keys.length - uint(1)]; - nValue.keyMap[key]=rowToDelete; + bytes32 last = nValue.keys[nValue.keys.length - uint(1)]; + nValue.keys[rowToDelete] = last; + nValue.keyMap[last] = rowToDelete; nValue.keys.length--; uint probe; uint cursor;