Functional, extendible arrays. Arrays can have fixed size, or can grow automatically as needed. A default value is used for entries that have not been explicitly set.
Arrays uses zero based indexing. This is a deliberate design choice and differs from other erlang datastructures, e.g. tuples.
Unless specified by the user when the array is created, the default
value is the atom
The array never shrinks automatically; if an index
Examples:
%% Create a fixed-size array with entries 0-9 set to 'undefined' A0 = array:new(10). 10 = array:size(A0). %% Create an extendible array and set entry 17 to 'true', %% causing the array to grow automatically A1 = array:set(17, true, array:new()). 18 = array:size(A1). %% Read back a stored value true = array:get(17, A1). %% Accessing an unset entry returns the default value undefined = array:get(3, A1). %% Accessing an entry beyond the last set entry also returns the %% default value, if the array does not have fixed size undefined = array:get(18, A1). %% "sparse" functions ignore default-valued entries A2 = array:set(4, false, A1). [{4, false}, {17, true}] = array:sparse_to_orddict(A2). %% An extendible array can be made fixed-size later A3 = array:fix(A2). %% A fixed-size array does not grow automatically and does not %% allow accesses beyond the last set entry {'EXIT',{badarg,_}} = (catch array:set(18, true, A3)). {'EXIT',{badarg,_}} = (catch array:get(18, A3)).
A functional, extendible array. The representation is not documented and is subject to change without notice. Note that arrays cannot be directly compared for equality.
Get the value used for uninitialized entries.
See also:
Fix the size of the array. This prevents it from growing
automatically upon insertion; see also
See also:
Fold 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
See also:
Fold 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
See also:
Equivalent to
Convert a list to an extendible array.
See also:
Equivalent to
Convert an ordered list of pairs
See also:
Get the value of entry
If the array does not have fixed size, this function will return the
default value for any index
See also:
Returns
Check if the array has fixed size.
Returns
See also:
Map the given function onto each element of the array. The
elements are visited in order from the lowest index to the highest.
If
See also:
Create a new, extendible array with initial size zero.
See also:
Create a new array according to the given options. By default, the array is extendible and has initial size zero. Array indices start at 0.
Specifies the initial size of the array; this also implies
Creates a fixed-size array; see also
Creates an extendible (non fixed-size) array.
Sets the default value for the array to
Options are processed in the order they occur in the list, i.e., later options have higher precedence.
The default value is used as the value of uninitialized entries, and cannot be changed once the array has been created.
Examples:
array:new(100)
creates a fixed-size array of size 100.
array:new({default,0})
creates an empty, extendible array whose default value is 0.
array:new([{size,10},{fixed,false},{default,-1}])
creates an extendible array with initial size 10 whose default value is -1.
See also:
Create a new array according to the given size and options. If
If
Example:
array:new(100, {default,0})
creates a fixed-size array of size 100, whose default value is 0.
See also:
Make the array resizable. (Reverses the effects of
See also:
Reset entry
If
See also:
Change the size of the array to that reported by
See also:
Change the size of the array. If
Set entry
If the array does not have fixed size, and
See also:
Get the number of entries in the array. Entries are numbered
from 0 to
See also:
Fold 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
See also:
Fold 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
See also:
Map 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
See also:
Get the number of entries in the array up until the last
non-default valued entry. In other words, returns
See also:
Converts the array to a list, skipping default-valued entries.
See also:
Convert the array to an ordered list of pairs
See also:
Converts the array to a list.
See also:
Convert the array to an ordered list of pairs
See also: