A vector is a one-dimensional array. Vectors act as
dynamic arrays: values can be stored at any index. The initial arguments
are stored from index 1.
The amount of memory used to store a vector is determined by the difference between the lowest index and the highest index. In many applications, sparse arrays are better realised using class hash_table.
.g.
if offset equals 2, the first element is at index 3.skipped elements
are filled with @default.from and to
default to vector<-low_index
resp. vector<-high_index.
This is a common way to create a vector with a specific range.
@arg1 The current element @arg2 Index of this element
Its behaviour is undefined if the size of the vector is changed by code.
Using the from and to arguments, the range
as well as the order of visited elements can be reduced. Using only from,
the vector is enumerated starting at the given index.. Using only to,
the vector is enumerated from vector<-low_index
to the given index. Using both from and to,
the vector is enumerated in the given range. If to < from
the enumeration is executed backwards.
See also vector->for_some, vector<-find
and vector<-find_all.
@arg1 The current element @arg2 Index of this element
Its behaviour is undefined if the size of the vector is changed by code.
Using from and to, the range and order can
be defined. See
vector->for_all
for details.
Bugs: It would be useful to be able to create a vector with a specified low and high index. To create a vector [5...20] do:
new(V, vector), send(V, fill, @nil, 5, 20).
freed places
are filled with
@nil:
?- new(V, vector(gnu, gnats)), send(V, shift, 1), object(V, Term). Term = vector(@nil, gnu)
->sort. From
and To may be used to sort only part of the vector. From
defaults to vector<-low_index,
and To to
vector<-high_index.
If To <= From, vector->sort
succeeds without any side-effects.
<->offset.
The copy also is of the same class as the original, which implies that
the
vector->initialise
method of this subclass must accept the same arguments as class vector.
@arg1 The current element @arg2 Index of the element
Using from and to, the range and order can
be defined. See
vector->for_all
for details. For example, to find the last element satisfying code,
use:
find_last(Vector, Code, Element) :<-
get(Vector, high_index, End),
get(Vector, low_index, Start),
get(Vector, find, Code, End, Start, Element).
@arg1 The current element @arg2 The index
Using from and to, the range and order can
be defined. See
vector->for_all
for details.
<-element
succeeds. This is vector<-offset
+
vector<-size.
<-low_index,
returning the first index that holds the argument object.
See also chain->member
and vector<-rindex.
<-element
succeeds. This is vector<-offset
+ 1.
<-high_index
working downwards and return the highest index that contains the
argument object. See also vector<-index.