bitmap
transmissions11 opened this issue · 5 comments
transmissions11 commented
bitmap
transmissions11 commented
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/BitMaps.sol
https://github.com/gnosis/cow-token/blob/77fb012e62fbfe4d6704b27d5a26eb17d1d46aef/src/contracts/mixins/MerkleDistributor.sol
https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol
https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2797/files
transmissions11 commented
can we use custom types
transmissions11 commented
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0;
library BitmapLib {
struct Bitmap {
mapping(uint256 => uint256) map;
}
function get(Bitmap storage bitmap, uint256 index) internal view returns (bool isSet) {
uint256 value = bitmap.map[index >> 8] & (1 << (index & 0xff));
assembly {
isSet := value // Assign isSet to whether the value is non zero.
}
}
function setTo(
Bitmap storage bitmap,
uint256 index,
bool shouldSet
) internal {
shouldSet ? set(bitmap, index) : unset(bitmap, index);
}
function set(Bitmap storage bitmap, uint256 index) internal {
bitmap.map[index >> 8] |= (1 << (index & 0xff));
}
function unset(Bitmap storage bitmap, uint256 index) internal {
bitmap.map[index >> 8] &= ~(1 << (index & 0xff));
}
}
sebastiantf commented
Why is this not in the codebase?