Hypex v1.1.0 Hypex.Register behaviour

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.

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

Types

t

Register implementations currently available

Callbacks

from_list(list)

Specs

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.

get_value(register, idx, width)

Specs

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.

init(width)

Specs

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.

reduce(register, width, acc, list)

Specs

reduce(register :: Register.t, width :: number, acc :: any, (number, any -> any)) :: acc :: any

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

set_value(register, idx, width, value)

Specs

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.

to_list(register)

Specs

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.