A dynamic bitset for fast membership checks on integers.
This is useful for tracking which clients are in a solution, which routes have been visited, etc. The bitset is immutable - all operations return a new bitset.
The size is rounded up to the nearest multiple of 64 bits.
Example
bitset = ExVrp.DynamicBitset.new(128)
bitset = ExVrp.DynamicBitset.set(bitset, 0, true)
bitset = ExVrp.DynamicBitset.set(bitset, 64, true)
ExVrp.DynamicBitset.count(bitset) # => 2
Summary
Functions
Returns true if all bits are set.
Returns true if any bit is set.
Bitwise AND of two bitsets. Returns a new bitset.
Bitwise NOT of a bitset. Returns a new bitset.
Bitwise OR of two bitsets. Returns a new bitset.
Bitwise XOR of two bitsets. Returns a new bitset.
Returns the number of set bits.
Checks if two bitsets are equal.
Gets the bit at the given index.
Creates a new bitset with the given number of bits.
Returns true if no bits are set.
Resets all bits to 0. Returns a new bitset.
Sets the bit at the given index. Returns a new bitset.
Sets all bits to 1. Returns a new bitset.
Returns the size (length) of the bitset.
Types
@type t() :: reference()
Functions
Returns true if all bits are set.
Returns true if any bit is set.
Bitwise AND of two bitsets. Returns a new bitset.
Bitwise NOT of a bitset. Returns a new bitset.
Bitwise OR of two bitsets. Returns a new bitset.
Example
result = ExVrp.DynamicBitset.bit_or(bitset1, bitset2)
Bitwise XOR of two bitsets. Returns a new bitset.
@spec count(t()) :: non_neg_integer()
Returns the number of set bits.
Checks if two bitsets are equal.
@spec get(t(), non_neg_integer()) :: boolean()
Gets the bit at the given index.
Example
ExVrp.DynamicBitset.get(bitset, 0) # => false
@spec new(non_neg_integer()) :: t()
Creates a new bitset with the given number of bits.
The actual size is rounded up to the nearest multiple of 64.
Example
bitset = ExVrp.DynamicBitset.new(128)
Returns true if no bits are set.
Resets all bits to 0. Returns a new bitset.
@spec set(t(), non_neg_integer(), boolean()) :: t()
Sets the bit at the given index. Returns a new bitset.
Example
bitset = ExVrp.DynamicBitset.set(bitset, 0, true)
Sets all bits to 1. Returns a new bitset.
@spec size(t()) :: non_neg_integer()
Returns the size (length) of the bitset.
This is the actual allocated size (rounded up to 64-bit blocks).