Bedrock.Internal.Atomics (bedrock v0.5.2)
View SourceCentralized atomic operations for variable-length little-endian binary values.
This module implements atomic operations that mirror FoundationDB's semantics, operating on variable-length binary values interpreted as little-endian integers. All operations handle missing values (empty binaries) according to their specific semantics.
Value Interpretation
- Empty binary (
<<>>) represents missing/unset values - All other binaries are interpreted as little-endian unsigned integers
- Operations automatically handle size differences through padding/truncation
Operation Semantics
- Addition: Little-endian carry propagation, missing = 0
- Bitwise operations: Byte-by-byte operations with appropriate defaults
- Min/Max: Little-endian integer comparison with V2 semantics
- Byte min/max: Lexicographic comparison
- Append: Concatenation with size limit
- Compare and clear: Clear if values match
Summary
Functions
Addition with little-endian carry propagation
Append if fits within size limit
Apply an atomic operation to an existing value with an operand.
Bitwise AND - V2 version (missing existing = return operand)
Bitwise OR operation
Bitwise XOR operation
Byte-wise maximum (lexicographic comparison)
Byte-wise minimum (lexicographic comparison)
Compare and clear - clear if values match
Maximum operation (little-endian integer comparison)
Minimum operation - V2 version (missing existing = return operand)
Functions
@spec add(Bedrock.value(), Bedrock.value()) :: Bedrock.value()
Addition with little-endian carry propagation
@spec append_if_fits(Bedrock.value(), Bedrock.value()) :: Bedrock.value()
Append if fits within size limit
Apply an atomic operation to an existing value with an operand.
Returns the result of the operation, or nil for compare_and_clear when cleared.
Examples
iex> Atomics.apply_operation(:add, <<5>>, <<3>>)
<<8>>
iex> Atomics.apply_operation(:min, <<10>>, <<5>>)
<<5>>
iex> Atomics.apply_operation(:compare_and_clear, <<5>>, <<5>>)
nil
@spec bit_and(Bedrock.value(), Bedrock.value()) :: Bedrock.value()
Bitwise AND - V2 version (missing existing = return operand)
@spec bit_or(Bedrock.value(), Bedrock.value()) :: Bedrock.value()
Bitwise OR operation
@spec bit_xor(Bedrock.value(), Bedrock.value()) :: Bedrock.value()
Bitwise XOR operation
@spec byte_max(Bedrock.value(), Bedrock.value()) :: Bedrock.value()
Byte-wise maximum (lexicographic comparison)
@spec byte_min(Bedrock.value(), Bedrock.value()) :: Bedrock.value()
Byte-wise minimum (lexicographic comparison)
@spec compare_and_clear(Bedrock.value(), Bedrock.value()) :: Bedrock.value()
Compare and clear - clear if values match
@spec max(Bedrock.value(), Bedrock.value()) :: Bedrock.value()
Maximum operation (little-endian integer comparison)
@spec min(Bedrock.value(), Bedrock.value()) :: Bedrock.value()
Minimum operation - V2 version (missing existing = return operand)