AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
Vector typedict
 
A Vector is an ordered heterogeneous collection of values. It is different from an Array because values can be removed, it never has a size limit, and standard subscript and pointer notation that work with arrays can not be used to access the objects stored in a vector. Yoix programs interact with vectors by reading, writing, or executing the following Vector fields:
clone A read-only field that returns a new vector that contains the same values as this vector.
contains(int index) A Builtin that returns an int that is non-zero when the object at index has been defined in this vector.
containsValue(Object value) A Builtin that returns an int that is non-zero when there is at least one index that is mapped to value in this vector.
elementcount A read-only int that is the number of elements currently stored in the vector.
elements A read-only Array that when read provides a snapshot, in a growable array, that represents the objects currently stored in the vector without preserving their positions, which means there are no uninitialized positions in that array.
find(Object value [, int last]) A Builtin that returns an int that is the first index that contains value, or -1 when value is not found. Setting the optional last argument to non-zero tells find to return the last index in this vector that is mapped to value.
findAll(Object value) A Builtin that returns an Array that contains all the indices that map to value in this vector, or NULL when value is not found.
firstvalue A field represents the object stored at index zero in this vector. Reading returns that object, or NULL when nothing has been stored at index zero. Writing inserts a new object at the front of the vector and behaves like insert when it is applied to index zero; all objects stored in the vector are shifted to the next higher position before the new value is stored at index zero.
get(int index) A Builtin that returns the value defined at index in this vector, or NULL when index is out of bounds (e.g., negative) or no value has been stored at index. Programs may need to use contains to determine whether index is actually defined, because NULL can be stored in a vector, so a NULL return from get does not always mean index is not defined.
insert(int index, Object value) A Builtin that inserts value at index, in this vector and returns an int that is non-zero if the insertion succeeded. The element formerly stored at index, if there is one, and all subsequent elements are moved to the next position before value is stored at index. Assigning value to the lastvalue field, or calling insert with index set to size appends an object to this vector.
lastvalue A field represents the object stored at the last position occupied by this vector. Reading returns that object, or NULL when nothing is stored at the last index. Writing appends a new object to the end of the vector and behaves like insert when it is applied to index size; the size of the vector is increased by 1 and the new object is stored in the last position.
put(int index, Object value) A Builtin that stores value at index in this vector and returns the previous value stored at index, or NULL if index was not defined.
putAll(Object index1, Object value1, ...) A Builtin that defines one or more index/value pairs in this vector and returns an Array that contains the previous index/value pairs for the indices that were actually redefined by putAll, or NULL if there were no redefinitions.
remove(Object index [, int preserve]) A Builtin that removes the object defined at index from this vector and returns the previous value defined at index, or NULL if there was no prior association. All objects in the vector above index are shifted down one position unless the optional preserve argument is non-zero.
removeValue(Object value, [, int preserve]) A Builtin that removes all occurrences of value from this vector and returns the number of objects removed. Objects that remain in the vector are shifted down to compensate for each removed object unless the optional preserve argument is non-zero.
size An int that represents the maximum number of objects that can currently be stored in this vector. Assigning a non-negative number to size immediately changes the size of the vector to the new value; assigning any other number to size accomplishes nothing and is silently ignored. Decreasing size automatically removes the required number of objects from the upper end of the vector; setting size to zero clears the vector.
values An Array that when read provides a snapshot, in a growable array, that preserves the positions of the objects currently stored in the vector, which means holes in the vector appear as uninitialized elements in that array. Writing clears the vector and then loads it with the objects contained in the new array. Assigning NULL to values is allowed and simply clears the vector.
Several permanent fields have not been documented and should not be used in Yoix applications.
 
 Example:   The program,
import yoix.*.*;

Vector names = {
    Array values = getDictionaryNames(yoix.awt.Color);
};

Frame f;
int   i;

fprintf(stdout, "There are %d colors\n", names.size);
names.removeValue("orange");
fprintf(stdout, "After removing \"orange\", there are %d colors\n",
    names.size);
names.size = names.size/2;
fprintf(stdout, "Removing half, there are now %d colors\n",
    names.size);

for (i = 0; i < names.size; i++) {
    f.title = "Color is: " + names.get(i);
    f.background = Color[names.get(i)];
    if (!f.visible)
        f.visible = TRUE;
    sleep(3);
}

f.visible = FALSE;
creates a vector containing the names of the colors in the yoix.awt.Color dictionary. After removing some of the names from the vector, it creates a frame and sequentially sets the frame title to each vector value and the frame background color to the corresponding color in the yoix.awt.Color dictionary. It also prints something like
There are 13 colors
After removing "orange", there are 12 colors
Removing half, there are now 6 colors
on standard output.
 
 See Also:   Array, Dictionary, Hashtable, String

 

Yoix is a registered trademark of AT&T Inc.