Hypex v1.1.0 Hypex.Bitstring
This module provides a Hypex register implementation using a Bitstring under the hood.
Using this implementation provides several guarantees about memory, in that the memory cost stays constant and falls well below that of other registers.
Unfortunately this efficiency comes at the cost of some throughput, although this module should be easily sufficient for all but the most write-intensive use cases.
Summary
Functions
Takes a list of bits and converts them to a bitstring
Returns a bit from the list of registers
Creates a new bitstring with a size of (2 ^ width) * width
with all bits initialized to 0
Converts a list of registers into a provided accumulator
Sets a bit inside the list of registers
Takes a bitstring and converts it to a list of bits
Functions
Specs
from_list([bit :: number]) :: bitstring
Takes a list of bits and converts them to a bitstring.
We can just delegate to the native Erlang implementation as it provides the functionality we need built in.
Specs
get_value(bitstring, idx :: number, width :: number) :: result :: number
Returns a bit from the list of registers.
Specs
init(number) :: bitstring
Creates a new bitstring with a size of (2 ^ width) * width
with all bits initialized to 0.
Specs
reduce(bitstring, width :: number, accumulator :: any, (number, any -> any)) :: accumulator :: any
Converts a list of registers into a provided accumulator.
Internally we pass everything to the binary reduction function in the utils module, as there’s already a native implementation for accumulation.
Specs
set_value(bitstring, idx :: number, width :: number, value :: number) :: bitstring
Sets a bit inside the list of registers.