This package provides an implementation of extendible arrays with logarithmic access time.
Beware: the atom $
is used to indicate an unset element, and the
functor $ /4
is used to indicate a subtree. In general, array
elements whose principal function symbol is $
will not work.
To load the package, enter the query
| ?- use_module(library(arrays)).
new_array(
-Array)
Binds Array to a new empty array. Example:
| ?- new_array(A). A = array($($,$,$,$),2) ? yes
is_array(
+Array)
Is true when Array actually is an array.
aref(
+Index,
+Array,
?Element)
Element is the element at position Index in Array. It
fails if Array
[
Index]
is undefined.
arefa(
+Index,
+Array,
?Element)
Is like aref/3
except that Element is a new array if
Array
[
Index]
is undefined. Example:
| ?- arefa(3, array($($,$,$,$),2), E). E = array($($,$,$,$),2) ? yes
arefl(
+Index,
+Array,
?Element)
Is as aref/3
except that Element is []
for undefined
cells. Example:
| ?- arefl(3, array($($,$,$,$),2), E). E = [] ? yes
array_to_list(
+Array,
-List)
List is a list with the pairs Index-Element of all the elements of Array. Example:
| ?- array_to_list(array($(a,b,c,d),2), List). List = [0-a,1-b,2-c,3-d] ? yes
aset(
+Index,
+Array,
+Element,
-NewArray)
NewArray is the result of setting Array
[
Index]
to Element. Example:
| ?- aset(3,array($($,$,$,$),2), a, Newarr). Newarr = array($($,$,$,a),2) ? yes