View Source hyper_register behaviour (hyper v1.0.1)

If you wish to implement your own backend for storing registers, your module needs to implement these interfaces. The backend modules have quite a lot of responsibility (detailed below) to allow for backend-specific optimizations.

Link to this section Summary

Functions

Size in bytes used to represent the registers in memory.
Compact is always called before any attempt at reading (sum, zero count, etc) or merging. It is intended to give backends that buffer the writes a chance to flush the buffer before the registers are needed.
Encode and decode are called to convert the in-memory representation of the backend to the serialized format. Must return one binary where each register is encoded as an 8-bit integer.
Merge any number of registers, used to calculate the union. For two register values at the same index, the max value must be in the resulting register.
Same as max_merge/1 but used when we know only two filters are merged.
Creates a new instance of the backend. The return value of this function will be passed to all functions in this module.
Reduce the precision of the registers. Used for mixed-precision union by first reducing the precision to the lowest of all filters.
A map with key the values possible for the register and values the number of register with that value.
Sum of 2^-R where R is the value in each register.
Set the register to the given value, *only* if the value already stored is lower than the new value. The backend needs to ensure the register value is only allowed to increase.
Count of registers set to 0.

Link to this section Types

-type t() :: module().

Link to this section Callbacks

-callback bytes(hyper:registers()) -> integer().
-callback compact(hyper:registers()) -> hyper:registers().
-callback decode_registers(binary(), hyper:precision()) -> hyper:registers().
-callback encode_registers(hyper:registers()) -> binary().
-callback max_merge([hyper:registers()]) -> hyper:registers().
-callback max_merge(hyper:registers(), hyper:registers()) -> hyper:registers().
-callback new(P :: hyper:precision()) -> hyper:registers().
-callback precision(hyper:registers()) -> integer().
-callback reduce_precision(hyper:precision(), hyper:registers()) -> hyper:registers().
-callback register_histogram(hyper:registers()) -> map().
-callback register_sum(hyper:registers()) -> float().
-callback set(Index :: integer(), Value :: integer(), hyper:registers()) -> hyper:registers().
-callback zero_count(hyper:registers()) -> integer().

Link to this section Functions

Link to this function

bytes(RegisterImpl, Registers)

View Source
-spec bytes(t(), hyper:registers()) -> integer().
Size in bytes used to represent the registers in memory.
Link to this function

compact(RegisterImpl, Registers)

View Source
-spec compact(t(), hyper:registers()) -> hyper:registers().
Compact is always called before any attempt at reading (sum, zero count, etc) or merging. It is intended to give backends that buffer the writes a chance to flush the buffer before the registers are needed.
Link to this function

decode_registers(RegisterImpl, Encoded, Precision)

View Source
-spec decode_registers(t(), binary(), hyper:precision()) -> hyper:registers().
Link to this function

encode_registers(RegisterImpl, Registers)

View Source
-spec encode_registers(t(), hyper:registers()) -> binary().
Encode and decode are called to convert the in-memory representation of the backend to the serialized format. Must return one binary where each register is encoded as an 8-bit integer.
Link to this function

max_merge(RegisterImpl, RegisterLists)

View Source
-spec max_merge(t(), [hyper:registers()]) -> hyper:registers().
Merge any number of registers, used to calculate the union. For two register values at the same index, the max value must be in the resulting register.
Link to this function

max_merge(RegisterImpl, Registers1, Registers2)

View Source
-spec max_merge(t(), hyper:registers(), hyper:registers()) -> hyper:registers().
Same as max_merge/1 but used when we know only two filters are merged.
-spec new(t(), P :: hyper:precision()) -> hyper:registers().
Creates a new instance of the backend. The return value of this function will be passed to all functions in this module.
Link to this function

precision(RegisterImpl, Registers)

View Source
-spec precision(t(), hyper:registers()) -> integer().
Link to this function

reduce_precision(RegisterImpl, Precision, Registers)

View Source
-spec reduce_precision(t(), hyper:precision(), hyper:registers()) -> hyper:registers().
Reduce the precision of the registers. Used for mixed-precision union by first reducing the precision to the lowest of all filters.
Link to this function

register_histogram(RegisterImpl, Registers)

View Source
-spec register_histogram(t(), hyper:registers()) -> map().
A map with key the values possible for the register and values the number of register with that value.
Link to this function

register_sum(RegisterImpl, Registers)

View Source
-spec register_sum(t(), hyper:registers()) -> float().
Sum of 2^-R where R is the value in each register.
Link to this function

set(RegisterImpl, Index, Value, Registers)

View Source
-spec set(t(), Index :: integer(), Value :: integer(), hyper:registers()) -> hyper:registers().
Set the register to the given value, *only* if the value already stored is lower than the new value. The backend needs to ensure the register value is only allowed to increase.
Link to this function

zero_count(RegisterImpl, Registers)

View Source
-spec zero_count(t(), hyper:registers()) -> integer().
Count of registers set to 0.