## ./

# vector__define.pro

These routines define a vector data type. This vector class differs from an array in that it grows as necessary to accomodate new data. This enhancement comes at some expense of convenience: -- The vector carries the baggage associated with objects (they must be created with obj_new, and destroyed with obj_destroy) -- Manipulating the data inside a vector is more cumbersome (it must be done through the vector methods, instead of simple syntax like array[3:5] = 10. Adding data is also less flexible; data must be added in contiguous chunks (as opposed to operations like array[[1,2,5,7]] = [9,8,7,6] This vector class is distinct from the stack class, in that data can be accessed and modified anywhere in a vector. In a stack, objects can only be added to and retrieved from the top of the stack.

## Class description for vector

## Routines

`vector::insertAt, vals, ind`

This procedure adds a set of values at a specified starting index in the vector.

`vector::fill, value [, first] [, last] [, firstInd=firstInd] [, lastInd=lastInd]`

This procedure sets a subset of the vector to a specified value

`vector::append, vals`

This procedure adds a set of values to the end of the vector

`vector::delete`

`vector::ensureCapacity, vals, ind`

This procedure updates the size of the vector to accommodate adding new data.

`result = vector::getValues(ind)`

This function retrieves the data from the specified indices of a vector

`result = vector::toArray()`

This function returns the vector as an array

`vector::cleanup`

This procedure is called automatically when the object is destroyed.

`result = vector::init()`

This function is called automatically by obj_new.

`vector__define`

## Routine details

## topvector::insertAt

This procedure adds a set of values at a specified starting index in the vector. Any old values in overlapping indices will be overwritten. The vector expands as necessary to accomodate the insertion.

### Parameters

- vals in required
A scalar or array of values to add

- ind in required
The first index into which vals should be inserted.

### Examples

```
Assume an initial vector of [1,2,3]
vector->insertAt, [4,5], 3 would produce [1,2,3,4,5]
vector->insertAt, [9], 1 would produce [1, 9, 3]
vector->insertAt, 10, 5 would produce [1,2,3,?,10]
(the ? value will be some random number)
```

## topvector::fill

`vector::fill, value [, first] [, last] [, firstInd=firstInd] [, lastInd=lastInd]`

This procedure sets a subset of the vector to a specified value

### Parameters

- value in required
The value to set the specified vector elements to

- first in optional
The first index of the vector to set to value. Defaults to zero.

- last in optional
The last index of the vector to set to value. Defaults to self.top.

### Keywords

- firstInd in optional
The same as the first argument. If both are present, the keyword overrides the value of the argument

- lastInd in optional
The same as the last argument. If both are present, the keyword overrides the value of the argument

### Examples

```
Assume an inital vector of [1,2,3,4,5]
vector->fill, 0 would yield [0,0,0,0,0]
vector->fill, 9, 2,3 would yield [1,2,9,9,5]
vector->fill, -1, lastInd = 3 would yield [-1, -1, -1, 4, 5]
vector->fill, -1, firstInd = 1 would yield [1, -1, -1, -1, -1]
```

## topvector::append

`vector::append, vals`

This procedure adds a set of values to the end of the vector

### Parameters

- vals in required
The values to add

### Examples

```
Assume an initial vector of [1,2,3]
vector->append, 10 would yield [1,2,3,10]
vector->append, [4,5,6] would yield [1,2,3,4,5,6]
```

## topvector::delete

`vector::delete`

## topvector::ensureCapacity

`vector::ensureCapacity, vals, ind`

This procedure updates the size of the vector to accommodate adding new data. It also updates the value of top

### Parameters

- vals in required
A scalar or array of values to be added to the vector

- ind in required
The starting index at which vals are to be added

## topvector::getValues

`result = vector::getValues(ind)`

This function retrieves the data from the specified indices of a vector

### Parameters

- ind in required
The index or indices of the vector from which data should be fetched.

## topvector::cleanup

`vector::cleanup`

This procedure is called automatically when the object is destroyed. It deletes the data pointer

## topvector::init

`result = vector::init()`

This function is called automatically by obj_new. It sets the initial values of the class structure

## topvector__define

`vector__define`

## File attributes

Modifcation date: | Mon Dec 13 17:55:57 2010 |

Lines: | 263 |