Hypex v1.1.1 Hypex.Array View Source

This module provides a Hypex register implementation using an Erlang Array under the hood.

Using an Array switches out the memory efficiency of the Bitstring implementation for performance, operating at 10x the throughput of Bitstring on updates.

Even though this implementation uses higher amounts of memory, it’s still pretty low-cost and as such is the default register module for Hypex. Typically only those working in memory-constrained environments should consider the Bitstring register.

Link to this section Summary

Functions

Takes a list of bits and converts them to an Array

Returns a bit from the list of registers

Creates a new Array with a size of 2 ^ width with all elements initialized to 0

Converts a list of registers into a provided accumulator

Sets a bit inside the list of registers

Converts an Array register implementation to a list of bits

Link to this section Types

Link to this section Functions

Link to this function from_list(bits) View Source
from_list([bit :: number()]) :: array()

Takes a list of bits and converts them to an Array.

The Array has it’s size fixed before being returned just for some extra safety.

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

Returns a bit from the list of registers.

Link to this function init(width) View Source
init(width :: number()) :: array()

Creates a new Array with a size of 2 ^ width with all elements initialized to 0.

Link to this function reduce(registers, width, acc, fun) View Source
reduce(
  array(),
  width :: number(),
  accumulator :: any(),
  (number(), any() -> any())
) :: accumulator :: any()

Converts a list of registers into a provided accumulator.

Internally we pass everything to :array.foldl/3, as there’s already a native implementation for accumulation.

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

Sets a bit inside the list of registers.

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

Converts an Array register implementation to a list of bits.

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