clj_vector
Clojure's persistent vector implementation in Erlang.
This is an implementation of the persistent vector data structure found in Clojure JVM. A very nice series of posts explaining in detail the Clojure vector implementation can be found here.
The goal of implementing this data structure in Erlang was to compare its performance to the one provided by thearray
module.
The results of the comparison can be found here.
Summary
Types
Functions
-
cons(Value, Clj_vector)
Adds an item at the end of the vector.
-
empty()
Returns an empty vector.
-
get(Index, Clj_vector)
Returns the item at the
Index
position in the vector. -
new()
Creates a new empty vector.
-
new(Items)
Creates a new vector containing the items.
-
pop(Clj_vector)
Remove the item at the end of the vector.
-
reduce(F, Clj_vector)
Reduces over the items in the vector.
-
reduce(F, Init, Clj_vector)
Reduces over the items in the vector using an initial value.
-
set(Index, Value, Clj_vector)
Sets the item at the
Index
position in the vector. -
size(Clj_vector)
Returns the size of the vector.
-
to_list(Clj_vector)
Returns an Erlang list containing all items in the vector.
Types
index()
-type index() :: non_neg_integer().
offset()
-type offset() :: non_neg_integer().
shift()
-type shift() :: non_neg_integer().
size()
-type size() :: non_neg_integer().
tree_node()
-type tree_node() :: tuple().
vector()
-type vector() :: #clj_vector{}.
Functions
cons(Value, Clj_vector)
-spec cons(any(), vector()) -> vector().
Adds an item at the end of the vector.
empty()
-spec empty() -> vector().
Returns an empty vector.
get(Index, Clj_vector)
-spec get(index(), vector()) -> any().
Returns the item at the Index
position in the vector.
new()
Creates a new empty vector.
new(Items)
-spec new(list()) -> vector().
Creates a new vector containing the items.
pop(Clj_vector)
-spec pop(vector()) -> vector().
Remove the item at the end of the vector.
reduce(F, Clj_vector)
-spec reduce(function(), vector()) -> any().
Reduces over the items in the vector.
The behaviour of this function is analogous toclojure.core/reduce
.
reduce(F, Init, Clj_vector)
-spec reduce(function(), any(), vector()) -> any().
Reduces over the items in the vector using an initial value.
The behaviour of this function is analogous toclojure.core/reduce
.
set(Index, Value, Clj_vector)
-spec set(index(), any(), vector()) -> vector().
Sets the item at the Index
position in the vector.
size(Clj_vector)
-spec size(vector()) -> size().
Returns the size of the vector.
to_list(Clj_vector)
-spec to_list(vector()) -> [any()].
Returns an Erlang list containing all items in the vector.