CArray Class


The CArray class manages a 1-dimensional array of values. The class implements a traditional vector as a Lua table of (index, value) pairs. The values may be any supported type of thing (number, string, object) and indexing starts at 1. Values may have different types at different indices. However, some class methods such as Init and Dot, work only with values that are numbers. The purpose of the CArray is to allow a set of values to be referenced using numeric indices like [1] or [10000].

A CArray is sparse, meaning that there may be "holes" at indices where no value is defined. For example, you might define only one value at index 10000. Being sparse, this CArray requires storing only 1 value in memory, rather than 10000 elements with one defined value following 9999 zeros. See also the CMatrix class and the CSet class.

Usage

Construction

Object = CArray:new()

Destruction

Object:delete()

Data Members

There are no data members.

Construction

new

Creates a new instance of the CArray class. There are 3 constructor formats.

delete

Deletes the instance of the CArray object.

Copy

Copies this CArray to a new CArray

Operations

Count

Returns the number of members actually initialized.

Dot

Returns the dot product with another CArray.

Empty

Empties the contents of the CArray but does not delete it.

Exists

Returns true if a member exists at the index.

Get

Returns the member value at an array index.

Init

Initializes all members to a value.

MaxIndex

Returns the maximum member index.

Remove

Removes the member at an index.

Set

Sets the member value at an index.

Related Topics

Script Classes, CMatrix , CSet