View Source ExArray (ex_array v0.1.0)

A wrapper module for Erlang's array.

Link to this section Summary

Functions

Gets the value used for uninitialized entries.

Check if two arrays are equal using ===.

Fixes the size of the array. This prevents it from growing automatically upon insertion.

Folds the elements of the array using the given function and initial accumulator value. The elements are visited in order from the lowest index to the highest.

Folds the elements of the array right-to-left using the given function and initial accumulator value. The elements are visited in order from the highest index to the lowest.

Converts an Erlang's array to an array. All properties (size, elements, default value, fixedness) of the original array are preserved.

Equivalent to from_list(list, nil).

Converts a list to an extendible array. default is used as the value for uninitialized entries of the array.

Equivalent to from_orddict(orddict, nil).

Converts an ordered list of pairs {index, value} to a corresponding extendible array. default is used as the value for uninitialized entries of the array.

Gets the value of entry idx. If idx is not a nonnegative integer, or if the array has fixed size and idx is larger than the maximum index, the call raises ArgumentError.

Returns true if arr appears to be an array, otherwise false. Note that the check is only shallow; there is no guarantee that arr is a well-formed array representation even if this function returns true.

Checks if the array has fixed size. Returns true if the array is fixed, otherwise false.

Maps the given function onto each element of the array. The elements are visited in order from the lowest index to the highest.

Creates a new, extendible array with initial size zero. The default value is the atom nil, not undefined.

Creates a new fixed array according to the given options. By default, the array is extendible and has initial size zero. The default value is the atom nil, if not specified.

Makes the array resizable.

Resets entry idx to the default value for the array. If the value of entry idx is the default value the array will be returned unchanged. Reset will never change size of the array. Shrinking can be done explicitly by calling resize/2.

Changes the size of the array to that reported by sparse_size/1. If the given array has fixed size, the resulting array will also have fixed size.

Changes the size of the array. If size is not a nonnegative integer, the call raises ArgumentError. If the given array has fixed size, the resulting array will also have fixed size.

Sets entry idx of the array to val. If idx is not a nonnegative integer, or if the array has fixed size and idx is larger than the maximum index, the call raises ArgumentError.

Gets the number of entries in the array. Entries are numbered from 0 to size(array)-1; hence, this is also the index of the first entry that is guaranteed to not have been previously set.

Folds the elements of the array using the given function and initial accumulator value, skipping default-valued entries. The elements are visited in order from the lowest index to the highest.

Folds the elements of the array right-to-left using the given function and initial accumulator value, skipping default-valued entries. The elements are visited in order from the highest index to the lowest.

Maps the given function onto each element of the array, skipping default-valued entries. The elements are visited in order from the lowest index to the highest.

Gets the number of entries in the array up until the last non-default valued entry. In other words, returns idx+1 if idx is the last non-default valued entry in the array, or zero if no such entry exists.

Converts the array to a list, skipping default-valued entries.

Converts the array to an ordered list of pairs {index, value}, skipping default-valued entries.

Converts the array to its underlying Erlang's array.

Converts the array to a list.

Converts the array to an ordered list of pairs {index, value}.

Link to this section Types

@type element() :: term()
@type index() :: non_neg_integer()
@type opt() ::
  {:fixed, boolean()}
  | :fixed
  | {:default, any()}
  | {:size, non_neg_integer()}
  | non_neg_integer()
@type opts() :: opt() | [opt()]
@type orddict() :: [{index(), element()}]
@type t() :: %ExArray{content: :array.array()}

Link to this section Functions

@spec default(t()) :: any()

Gets the value used for uninitialized entries.

Link to this function

equal?(ex_array1, ex_array2)

View Source
@spec equal?(t(), t()) :: boolean()

Check if two arrays are equal using ===.

@spec fix(t()) :: t()

Fixes the size of the array. This prevents it from growing automatically upon insertion.

Link to this function

foldl(ex_array, acc, fun)

View Source
@spec foldl(t(), acc, (index(), element(), acc -> acc)) :: acc when acc: var

Folds the elements of the array using the given function and initial accumulator value. The elements are visited in order from the lowest index to the highest.

If fun is not a function, the call raises ArgumentError.

Link to this function

foldr(ex_array, acc, fun)

View Source
@spec foldr(t(), acc, (index(), element(), acc -> acc)) :: acc when acc: var

Folds the elements of the array right-to-left using the given function and initial accumulator value. The elements are visited in order from the highest index to the lowest.

If fun is not a function, the call raises ArgumentError.

Link to this function

from_erlang_array(erl_arr)

View Source
@spec from_erlang_array(:array.array()) :: t()

Converts an Erlang's array to an array. All properties (size, elements, default value, fixedness) of the original array are preserved.

If erl_arr is not an Erlang's array, the call raises ArgumentError.

@spec from_list(list()) :: t()

Equivalent to from_list(list, nil).

Link to this function

from_list(list, default)

View Source
@spec from_list(list(), any()) :: t()

Converts a list to an extendible array. default is used as the value for uninitialized entries of the array.

If list is not a proper list, the call raises ArgumentError.

@spec from_orddict(orddict()) :: t()

Equivalent to from_orddict(orddict, nil).

Link to this function

from_orddict(orddict, default)

View Source
@spec from_orddict(orddict(), any()) :: t()

Converts an ordered list of pairs {index, value} to a corresponding extendible array. default is used as the value for uninitialized entries of the array.

If orddict is not a proper, ordered list of pairs whose first elements are nonnegative integers, the call raises ArgumentError.

@spec get(t(), index()) :: element()

Gets the value of entry idx. If idx is not a nonnegative integer, or if the array has fixed size and idx is larger than the maximum index, the call raises ArgumentError.

@spec is_array(t()) :: boolean()

Returns true if arr appears to be an array, otherwise false. Note that the check is only shallow; there is no guarantee that arr is a well-formed array representation even if this function returns true.

@spec is_fix(t()) :: boolean()

Checks if the array has fixed size. Returns true if the array is fixed, otherwise false.

@spec map(t(), (index(), element() -> any())) :: t()

Maps the given function onto each element of the array. The elements are visited in order from the lowest index to the highest.

If fun is not a function, the call raises ArgumentError.

@spec new() :: t()

Creates a new, extendible array with initial size zero. The default value is the atom nil, not undefined.

@spec new(opts()) :: t()

Creates a new fixed array according to the given options. By default, the array is extendible and has initial size zero. The default value is the atom nil, if not specified.

options is a single term or a list of terms, selected from the following:

  • n : non_neg_integer or {:size, n : non_neg_integer}
    • Specifies the initial size of the array; this also implies {:fixed, true}. If n is not a nonnegative integer, the call raises ArgumentError.
  • :fixed or {:fixed, true}
    • Creates a fixed-size array.
  • {:fixed, false}
    • Creates an extendible (non fixed-size) array.
  • {:default, value}
    • Sets the default value for the array to value.
@spec relax(t()) :: t()

Makes the array resizable.

@spec reset(t(), index()) :: t()

Resets entry idx to the default value for the array. If the value of entry idx is the default value the array will be returned unchanged. Reset will never change size of the array. Shrinking can be done explicitly by calling resize/2.

If idx is not a nonnegative integer, or if the array has fixed size and idx is larger than the maximum index, the call raises ArgumentError.

@spec resize(t()) :: t()

Changes the size of the array to that reported by sparse_size/1. If the given array has fixed size, the resulting array will also have fixed size.

@spec resize(t(), non_neg_integer()) :: t()

Changes the size of the array. If size is not a nonnegative integer, the call raises ArgumentError. If the given array has fixed size, the resulting array will also have fixed size.

@spec set(t(), index(), element()) :: t()

Sets entry idx of the array to val. If idx is not a nonnegative integer, or if the array has fixed size and idx is larger than the maximum index, the call raises ArgumentError.

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

Gets the number of entries in the array. Entries are numbered from 0 to size(array)-1; hence, this is also the index of the first entry that is guaranteed to not have been previously set.

Link to this function

sparse_foldl(ex_array, acc, fun)

View Source
@spec sparse_foldl(t(), acc, (index(), element(), acc -> acc)) :: acc when acc: var

Folds the elements of the array using the given function and initial accumulator value, skipping default-valued entries. The elements are visited in order from the lowest index to the highest.

If fun is not a function, the call raises ArgumentError.

Link to this function

sparse_foldr(ex_array, acc, fun)

View Source
@spec sparse_foldr(t(), acc, (index(), element(), acc -> acc)) :: acc when acc: var

Folds the elements of the array right-to-left using the given function and initial accumulator value, skipping default-valued entries. The elements are visited in order from the highest index to the lowest.

If fun is not a function, the call raises ArgumentError.

@spec sparse_map(t(), (non_neg_integer(), element() -> any())) :: t()

Maps the given function onto each element of the array, skipping default-valued entries. The elements are visited in order from the lowest index to the highest.

If fun is not a function, the call raises ArgumentError.

@spec sparse_size(t()) :: non_neg_integer()

Gets the number of entries in the array up until the last non-default valued entry. In other words, returns idx+1 if idx is the last non-default valued entry in the array, or zero if no such entry exists.

Link to this function

sparse_to_list(ex_array)

View Source
@spec sparse_to_list(t()) :: list()

Converts the array to a list, skipping default-valued entries.

Link to this function

sparse_to_orddict(ex_array)

View Source
@spec sparse_to_orddict(t()) :: [{index(), element()}]

Converts the array to an ordered list of pairs {index, value}, skipping default-valued entries.

Link to this function

to_erlang_array(ex_array)

View Source
@spec to_erlang_array(t()) :: :array.array()

Converts the array to its underlying Erlang's array.

@spec to_list(t()) :: list()

Converts the array to a list.

@spec to_orddict(t()) :: [{index(), element()}]

Converts the array to an ordered list of pairs {index, value}.