Errow.Binary (errow v0.1.0)

Copy Markdown View Source

An immutable, continuous-memory binary array implementing the Apache Arrow Binary columnar format (for raw byte blobs).

Under the hood, data is organized in three buffers:

  1. Offsets buffer (offsets): a continuous binary of 32-bit signed integers in little-endian.
  2. Data buffer (data): a continuous binary containing the concatenated raw byte blobs.
  3. Validity bitmap (validity): a bitstring tracking null (nil) values (1 bit per element).

Unlike Errow.String, Errow.Binary is meant for opaque byte slices, hashes, PNG/JPEG payloads, UUIDs, Protobuf blobs, etc.

Summary

Functions

Appends a binary blob or nil to the array.

Returns the byte size of the continuous data buffer.

Deletes the element at index idx.

Fetches the element at the given index or a slice specified by a range. Supports negative indices (e.g. -1 for the last element).

Builds an Errow.Binary array from a list or enumerable of binaries and optional nils.

Gets the value at index idx or returns default if out of bounds.

Creates a new empty Errow.Binary array.

Checks if the value at the given index is null (nil).

Returns the count of null values.

Replaces the element at the given index with a new binary blob or nil.

Returns the number of elements in the array.

Converts the Errow.Binary array into a standard Elixir list.

Types

t()

@type t() :: %Errow.Binary{
  data: binary(),
  length: non_neg_integer(),
  null_count: non_neg_integer(),
  offsets: binary(),
  validity: bitstring()
}

Functions

append(arr, bin)

@spec append(t(), binary() | nil) :: t()

Appends a binary blob or nil to the array.

buffer_byte_size(binary)

@spec buffer_byte_size(t()) :: non_neg_integer()

Returns the byte size of the continuous data buffer.

delete_at(arr, idx)

@spec delete_at(t(), integer()) :: t()

Deletes the element at index idx.

fetch(arr, idx)

@spec fetch(t(), integer() | Range.t()) :: {:ok, any()} | :error

Fetches the element at the given index or a slice specified by a range. Supports negative indices (e.g. -1 for the last element).

from_list(enumerable)

@spec from_list(Enumerable.t()) :: t()

Builds an Errow.Binary array from a list or enumerable of binaries and optional nils.

get(arr, idx, default \\ nil)

@spec get(t(), integer(), any()) :: binary() | nil | any()

Gets the value at index idx or returns default if out of bounds.

new()

@spec new() :: t()

Creates a new empty Errow.Binary array.

null?(binary, idx)

@spec null?(t(), integer()) :: boolean()

Checks if the value at the given index is null (nil).

null_count(binary)

@spec null_count(t()) :: non_neg_integer()

Returns the count of null values.

replace_at(arr, idx, new_val)

@spec replace_at(t(), integer(), binary() | nil) :: t()

Replaces the element at the given index with a new binary blob or nil.

size(binary)

@spec size(t()) :: non_neg_integer()

Returns the number of elements in the array.

to_list(arr)

@spec to_list(t()) :: [binary() | nil]

Converts the Errow.Binary array into a standard Elixir list.