Hypex v1.1.1 Hypex.Bitstring View Source

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.

Link to this section 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

Link to this section Functions

Link to this function from_list(bit_list) View Source
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.

Link to this function get_value(registers, idx, width) View Source
get_value(bitstring(), idx :: number(), width :: number()) :: result :: number()

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.

Link to this function reduce(registers, width, acc, fun) View Source
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.

Link to this function set_value(registers, idx, width, value) View Source
set_value(bitstring(), idx :: number(), width :: number(), value :: number()) ::
  bitstring()

Sets a bit inside the list of registers.

Link to this function to_list(registers) View Source
to_list(bitstring()) :: [bit :: number()]

Takes a bitstring and converts it to a list of bits.

We can just delegate to the native Erlang implementation as it provides the functionality we need built in.