The openzeppelin provides a data structure library namely BitMaps
which can be found here -
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/BitMaps.sol
Can someone explain the logic of what exactly is going on in this library?
Like consider the function get
-
function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
return bitmap._data[bucket] & mask != 0;
}
Here, why is index>>8
done and what does 1 << (index & 0xff)
mean?
Could someone clarify this with an example by taking numbers and explaining a use case?
Also, what exactly does the struct Bitmap represents and what does it store?
struct BitMap {
mapping(uint256 => uint256) _data;
}