Logos. Vector
(Logos v0.2.0)
Copy Markdown
A Logos persistent vector: [1 2 3].
Backed by Erlang's built-in :array module rather than a hand-rolled
bit-partitioned trie or an external library: :array already gives
O(log n) get/set with structural sharing on "mutation" (every update
returns a new array, the old one is untouched, exactly the persistence
a Lisp vector needs), ships with the BEAM (zero extra dependency), and
is a well-worn, boring piece of the standard library rather than a new
trie implementation Logos would have to get right and maintain itself.
A real Clojure-style 32-way trie would beat it on constant factors, but
that's a performance concern for later, not something correctness
depends on today.
Summary
Functions
Returns a new vector with value appended.
Number of elements.
An empty vector.
Builds a vector from a list, in order.
Element at index (0-based). Raises if out of bounds, matching Enum.at!-style strictness.
Returns a new vector with index set to value.
Converts back to a plain Elixir list, in order.
Types
@type t() :: %Logos.Vector{arr: :array.array()}
Functions
Returns a new vector with value appended.
@spec count(t()) :: non_neg_integer()
Number of elements.
@spec empty() :: t()
An empty vector.
Builds a vector from a list, in order.
@spec nth(t(), non_neg_integer()) :: term()
Element at index (0-based). Raises if out of bounds, matching Enum.at!-style strictness.
@spec put(t(), non_neg_integer(), term()) :: t()
Returns a new vector with index set to value.
Converts back to a plain Elixir list, in order.