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 data structures, for example, 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
A0 = array:new(10). 10 = array:size(A0).
Create an extendible array and set entry 17 to
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 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. Notice that arrays cannot be directly compared for equality.
Gets the value used for uninitialized entries.
See also
Fixes the array size. This prevents it from growing automatically upon insertion.
See also
Folds the array elements using the specified function and initial
accumulator value. The elements are visited in order from the lowest
index to the highest. If
See also
Folds the array elements right-to-left using the specified function
and initial accumulator value. The elements are visited in order from
the highest index to the lowest. If
See also
Equivalent to
Converts a list to an extendible array.
See also
Equivalent to
Converts an ordered list of pairs
See also
Gets the value of entry
If the array does not have fixed size, the default value for any
index
See also
Returns
Checks if the array has fixed size. Returns
See also
Maps the specified function onto each array element. The elements are
visited in order from the lowest index to the highest. If
See also
Creates a new, extendible array with initial size zero.
See also
Creates a new array according to the specified otions. By default,
the array is extendible and has initial size zero. Array indices
start at
Specifies the initial array size; 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, that is, 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
array:new([{size,10},{fixed,false},{default,-1}])
creates an extendible array with initial size 10 whose default value
is
See also
Creates a new array according to the specified size and options. If
If
Example:
array:new(100, {default,0})
creates a fixed-size array of size 100, whose default value is
See also
Makes the array resizable. (Reverses the effects of
See also
Resets entry
If
See also
Changes the array size to that reported by
See also
Change the array size. If
Sets entry
If the array does not have fixed size, and
See also
Gets the number of entries in the array. Entries are numbered from
See also
Folds the array elements using the specified 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
Folds the array elements right-to-left using the specified
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
Maps the specified function onto each array element, skipping
default-valued entries. The elements are visited in order from the
lowest index to the highest. If
See also
Gets the number of entries in the array up until the last
non-default-valued entry. That is, returns
See also
Converts the array to a list, skipping default-valued entries.
See also
Converts the array to an ordered list of pairs
See also
Converts the array to a list.
See also
Converts the array to an ordered list of pairs
See also