Skip to content

Commit

Permalink
refactor: rename MinBitMap to Heap
Browse files Browse the repository at this point in the history
  • Loading branch information
detectivekim committed Jan 11, 2024
1 parent ec6d219 commit a26b7e9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions contracts/MinBitMap.sol → contracts/Heap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ pragma solidity ^0.8.0;

import "./SignificantBit.sol";

library MinBitMap {
library Heap {
using SignificantBit for uint256;

error MinBitMapError(uint256 errorCode);
error HeapError(uint256 errorCode);
uint256 public constant EMPTY_ERROR = 0;
uint256 public constant ALREADY_EXISTS_ERROR = 1;

Expand Down Expand Up @@ -53,7 +53,7 @@ library MinBitMap {
uint256 mask = 1 << bitIndex;
uint256 word = core.bitmapMapping[wordIndex];
if (word & mask > 0) {
revert MinBitMapError(ALREADY_EXISTS_ERROR);
revert HeapError(ALREADY_EXISTS_ERROR);
}

core.bitmapMapping[wordIndex] = word | mask;
Expand All @@ -67,7 +67,7 @@ library MinBitMap {
}

function pop(Core storage core) internal {
if (isEmpty(core)) revert MinBitMapError(EMPTY_ERROR);
if (isEmpty(core)) revert HeapError(EMPTY_ERROR);

(uint256 wordIndex, uint256 bitIndex) = _root(core);
uint256 mask = 1 << bitIndex;
Expand Down Expand Up @@ -97,7 +97,7 @@ library MinBitMap {
if (word == 0) {
word = ((type(uint256).max >> head) << head) & core.bitmap;
if (word == 0) {
revert MinBitMapError(EMPTY_ERROR);
revert HeapError(EMPTY_ERROR);
}
head = word.leastSignificantBit();
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/CloberMinBitMap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pragma solidity ^0.8.0;
* Each value is stored by having the quotient divided by 2^8 added to the heap,
* and the remainder expressed as a flag on a bitmap.
*/
interface CloberMinBitMap {
interface CloberHeap {
/**
* @notice Checks if the specified value is present in the heap.
* @param value The value to check for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

pragma solidity ^0.8.0;

import "../MinBitMap.sol";
import "../Heap.sol";
import "../interfaces/CloberMinBitMap.sol";

contract MinBitMapWrapper is CloberMinBitMap {
using MinBitMap for MinBitMap.Core;
contract HeapWrapper is CloberHeap {
using Heap for Heap.Core;

MinBitMap.Core private _heap;

Expand Down
14 changes: 7 additions & 7 deletions test/foundry/MinBitMap.t.sol → test/foundry/Heap.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import "../../contracts/mocks/MinBitMapWrapper.sol";
import "../../contracts/mocks/HeapWrapper.sol";

contract MinBitMapTest is Test {
contract HeapTest is Test {
uint16 private constant _MAX_HEAP_SIZE = type(uint16).max;

uint24 private _min;

MinBitMapWrapper testWrapper;
HeapWrapper testWrapper;

function setUp() public {
testWrapper = new MinBitMapWrapper();
testWrapper = new HeapWrapper();
_min = type(uint24).max;
}

Expand Down Expand Up @@ -48,15 +48,15 @@ contract MinBitMapTest is Test {

function testPushExistNumber(uint24 number) public {
testWrapper.push(number);
vm.expectRevert(abi.encodeWithSelector(MinBitMap.MinBitMapError.selector, MinBitMap.ALREADY_EXISTS_ERROR));
vm.expectRevert(abi.encodeWithSelector(Heap.HeapError.selector, Heap.ALREADY_EXISTS_ERROR));
testWrapper.push(number);
}

function testPopWhenEmpty() public {
vm.expectRevert(abi.encodeWithSelector(MinBitMap.MinBitMapError.selector, MinBitMap.EMPTY_ERROR));
vm.expectRevert(abi.encodeWithSelector(Heap.HeapError.selector, Heap.EMPTY_ERROR));
testWrapper.pop();

vm.expectRevert(abi.encodeWithSelector(MinBitMap.MinBitMapError.selector, MinBitMap.EMPTY_ERROR));
vm.expectRevert(abi.encodeWithSelector(Heap.HeapError.selector, Heap.EMPTY_ERROR));
testWrapper.root();
}
}

0 comments on commit a26b7e9

Please sign in to comment.