mirror of
https://github.com/th30d4y/OpenLearnX.git
synced 2026-05-27 03:36:32 +00:00
Fix .gitignore: stop tracking ignored files
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/BitMaps.sol)
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
/**
|
||||
* @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential.
|
||||
* Largely inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor].
|
||||
*/
|
||||
library BitMaps {
|
||||
struct BitMap {
|
||||
mapping(uint256 => uint256) _data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns whether the bit at `index` is set.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets the bit at `index` to the boolean `value`.
|
||||
*/
|
||||
function setTo(BitMap storage bitmap, uint256 index, bool value) internal {
|
||||
if (value) {
|
||||
set(bitmap, index);
|
||||
} else {
|
||||
unset(bitmap, index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets the bit at `index`.
|
||||
*/
|
||||
function set(BitMap storage bitmap, uint256 index) internal {
|
||||
uint256 bucket = index >> 8;
|
||||
uint256 mask = 1 << (index & 0xff);
|
||||
bitmap._data[bucket] |= mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Unsets the bit at `index`.
|
||||
*/
|
||||
function unset(BitMap storage bitmap, uint256 index) internal {
|
||||
uint256 bucket = index >> 8;
|
||||
uint256 mask = 1 << (index & 0xff);
|
||||
bitmap._data[bucket] &= ~mask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user