Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2.6 KiB
LibBitmap
Library for storage of packed unsigned booleans.
Constants
NOT_FOUND
uint256 internal constant NOT_FOUND = type(uint256).max
The constant returned when a bitmap scan does not find a result.
Structs
Bitmap
struct Bitmap {
mapping(uint256 => uint256) map;
}
A bitmap in storage.
Operations
get(Bitmap,uint256)
function get(Bitmap storage bitmap, uint256 index)
internal
view
returns (bool isSet)
Returns the boolean value of the bit at index in bitmap.
set(Bitmap,uint256)
function set(Bitmap storage bitmap, uint256 index) internal
Updates the bit at index in bitmap to true.
unset(Bitmap,uint256)
function unset(Bitmap storage bitmap, uint256 index) internal
Updates the bit at index in bitmap to false.
toggle(Bitmap,uint256)
function toggle(Bitmap storage bitmap, uint256 index)
internal
returns (bool newIsSet)
Flips the bit at index in bitmap.
Returns the boolean result of the flipped bit.
setTo(Bitmap,uint256,bool)
function setTo(Bitmap storage bitmap, uint256 index, bool shouldSet)
internal
Updates the bit at index in bitmap to shouldSet.
setBatch(Bitmap,uint256,uint256)
function setBatch(Bitmap storage bitmap, uint256 start, uint256 amount)
internal
Consecutively sets amount of bits starting from the bit at start.
unsetBatch(Bitmap,uint256,uint256)
function unsetBatch(Bitmap storage bitmap, uint256 start, uint256 amount)
internal
Consecutively unsets amount of bits starting from the bit at start.
popCount(Bitmap,uint256,uint256)
function popCount(Bitmap storage bitmap, uint256 start, uint256 amount)
internal
view
returns (uint256 count)
Returns number of set bits within a range by
scanning amount of bits starting from the bit at start.
findLastSet(Bitmap,uint256)
function findLastSet(Bitmap storage bitmap, uint256 upTo)
internal
view
returns (uint256 setBitIndex)
Returns the index of the most significant set bit in [0..upTo].
If no set bit is found, returns NOT_FOUND.
findFirstUnset(Bitmap,uint256,uint256)
function findFirstUnset(Bitmap storage bitmap, uint256 begin, uint256 upTo)
internal
view
returns (uint256 unsetBitIndex)
Returns the index of the least significant unset bit in [begin..upTo].
If no unset bit is found, returns NOT_FOUND.