Mojo module
bitset
Provides a compact, grow-only set of non-negative integers.
Optimized for space (1 bit per element) and speed (O(1) operations).
Offers set/clear/test/toggle and fast population count. The underlying
storage grows automatically but does not shrink unless shrink_to_fit
is called (not implemented yet).
Example:
var bs = BitSet[128]() # 128-bit set, all clear
bs.set(42) # Mark value 42 as present.
if bs.test(42): # Check membership.
print("hit") # Prints "hit".
bs.clear(42) # Remove 42.
print(bs.count()) # Prints 0.
var bs = BitSet[128]() # 128-bit set, all clear
bs.set(42) # Mark value 42 as present.
if bs.test(42): # Check membership.
print("hit") # Prints "hit".
bs.clear(42) # Remove 42.
print(bs.count()) # Prints 0.
Structs
-
BitSet
: A grow-only set storing non-negative integers efficiently using bits.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!