Hypex v1.1.1 Hypex.Register behaviour View Source

This module defines the behaviour required by all internal Hypex register structures.

Assuming all of the function callbacks defined in this module are implemented correctly, it should be possible to use as an implementation inside a Hypex. This makes it possible to provide custom implementations of the underlying register without having to modify the actual source of Hypex.

Link to this section Summary

Types

t()

Register implementations currently available

Callbacks

Invoked after operating on registers on a bit level

Invoked to retrieve a specific bit register

Invoked to initialize a set of registers

Invoked when there’s a need to iterate/accumulate a register

Invoked to set a bit register with a given value

Invoked when operating on registers on a bit level

Link to this section Types

Register implementations currently available

Link to this section Callbacks

Link to this callback from_list(list) View Source
from_list([bit :: number()]) :: register :: Register.t()

Invoked after operating on registers on a bit level.

This function will receive a list of bits as created by the to_list/1 callback. The result of calling this should return a register set in the same form as when first being initialized.

Link to this callback get_value(register, idx, width) View Source
get_value(register :: Register.t(), idx :: number(), width :: number()) ::
  result :: number()

Invoked to retrieve a specific bit register.

idx refers to the head of the hashes value, and width refers to the width of the register. The get_value/3 callback should use these values when finding the required register.

Link to this callback init(width) View Source
init(width :: number()) :: register :: Register.t()

Invoked to initialize a set of registers.

width is the desired width of the registers and should be used to determine how large the register set should be. Calls to init/1 should always return a new register set.

Link to this callback reduce(register, width, acc, function) View Source
reduce(
  register :: Register.t(),
  width :: number(),
  acc :: any(),
  (number(), any() -> any())
) :: acc :: any()

Invoked when there’s a need to iterate/accumulate a register.

Link to this callback set_value(register, idx, width, value) View Source
set_value(
  register :: Register.t(),
  idx :: number(),
  width :: number(),
  value :: number()
) :: register :: Register.t()

Invoked to set a bit register with a given value.

Similar to the get_value/3 callback, we supply idx and width to allow the callback to determine where the value should be written.

Link to this callback to_list(register) View Source
to_list(register :: Register.t()) :: [bit :: number()]

Invoked when operating on registers on a bit level.

This function should operate in tandem with from_list/1 to convert between a register set and a list of bits.