Class ml_int_array
[Modules]

An integer array convenience class for use with matrices. More...

Functions

 ml_int_array::ml_int_array ()
 Default constructor.

 ml_int_array::ml_int_array (int msize, const int *v=NULL)
 Creates a ml_int_array of a given size and loads the values from array v.

 ml_int_array::ml_int_array (const ml_int_array &a)
 Copy constructor.

 ml_int_array::ml_int_array (int start, int finish)
 Creates a ml_int_array sequence ranging from start to finish.

 ml_int_array::ml_int_array (char *s)
 Constructs a ml_int_array from a string format as used in MATLAB.

 ml_int_array::ml_int_array (void *bf)
 Constructs a ml_int_array from a binary buffer.

int ml_int_array::get (int index) const
 Accesses an element. Will not resize the ml_int_array.

int & ml_int_array::operator() (int index)
 Accesses an element by its index. Resizes for out of bounds access.

void ml_int_array::operator= (int *vals)
 Reassigns the values of the ml_int_array to those in the given array.

void ml_int_array::operator= (int val)
 Sets the ml_int_array equal to an integer changes the size to 1.

ml_int_arrayml_int_array::operator= (const ml_int_array &a)
 Sets the ml_int_array equal to the given ml_int_array.

int ml_int_array::length () const
 Returns the length of the ml_int_array.

int ml_int_array::is_empty () const
 Checks the size of the array, returns 1 unless the ml_int_array is empty.

ml_int_array ml_int_array::find (ml_comparison op, int target) const
 Returns a ml_int_array of all indices in the ml_int_array for which the given operator and operand is true.

void ml_int_array::display (char *s=NULL) const
 Display function. Formats the ml_int_array in a human readable fashion and prints to standard out.

char * ml_int_array::to_string ()
 Returns a string representations of the data structure.

void * ml_int_array::to_binary (unsigned short *size=NULL) const
 Creates a binary form of the ml_int_array for interprocess communication.

int ml_int_array::is_unique () const
 Determines whether the all the elements in the ml_int_array are unique.

int ml_int_array::sum () const
 Returns the sum of all the values in the ml_int_array.

int * ml_int_array::get_c_arr (int &s) const
 Converts the ml_int_array into a standard C array.

int ml_int_array::operator== (const ml_int_array &a)
 Tests two int_arrays for equality.

int ml_int_array::operator!= (const ml_int_array &a)
 Tests two int_arrays for in-equality.

ml_int_array ml_int_array::subset (int start, int end)
 Returns an int array of the specified subset of the original array.

ml_int_array ml_int_array::subset (const ml_int_array &indices)
 Returns an int array of the elements in the passed ml_int_array, in the specified order.

void ml_int_array::sort (int direction=0)
 Sorts all the elements of the ml_int_array. Ascending order is the default, pass a non-zero value for descending sort.

void ml_int_array::remove (const ml_int_array &indices)
 Removes the indices in the given ml_int_array and resizes the ml_int_array downwards.

void ml_int_array::remove (int index)
 Removes the element at the specified index and resizes the ml_int_array downwards.

void ml_int_array::append (ml_int_array b)
 Appends the given ml_int_array to the end of the "this" array.

void ml_int_array::append (int val)
 Appends the given integer to the end of the ml_int_array.

void ml_int_array::insert (int index, int val)
 Inserts a value at an arbitrary location in the ml_int_array.

void ml_int_array::zero ()
 Sets all elements of the ml_int_array to zero.

void ml_int_array::ones ()
 Sets all elements of the ml_int_array to one.

void ml_int_array::fliplr ()
 Flips the elements of the array.

void ml_int_array::setdiff (const ml_int_array &b)
 Removes the elements in B from the array, then sorts the remainder.


Detailed Description


Function Documentation

ml_int_array::ml_int_array  )  [inherited]
 

Default Constructor. Creates an int_array of size zero.

ml_int_array::ml_int_array int  msize,
const int *  v = NULL
[inherited]
 

Creates an integer array of a given size and loads the values from array v.

Parameters:
msize Number of elements in the new int_array.
v A standard C array from which to create the new int_array, NULL to initialize the elements to 0.

ml_int_array::ml_int_array const ml_int_array a  )  [inherited]
 

Copy constructor.

ml_int_array::ml_int_array int  start,
int  finish
[inherited]
 

Creates an integer array sequence. May be ascending or descending.

Parameters:
start Starting point of the sequence.
finish End point of the sequence.

ml_int_array::ml_int_array char *  s  )  [inherited]
 

Constructs an integer array from a string format as used in MATLAB.

Parameters:
s Character string used to build the array.

int ml_int_array::get int  index  )  const [inherited]
 

Accesses an element. Will not resize the int_array.

Parameters:
index The int_array index to access.
Returns:
Returns the value of element of the int_array.

int & ml_int_array::operator() int  index  )  [inherited]
 

Accesses an element by its index. Resizes for out of bounds access.

Parameters:
index The int_array index to access.
Returns:
Returns the element of the int_array.

void ml_int_array::operator= int *  vals  )  [inherited]
 

Reassigns the values of the int_array to those in the given array. NOTE: Passing an array with fewer elements than the int_array can cause the program to crash.

Parameters:
vals Array of int values to be placed in the int_array

void ml_int_array::operator= int  val  )  [inherited]
 

Changes the length of the ml_int_array to 1 and sets the value of the element to the specified integer.

Parameters:
val The integer value to assign the first element of the ml_int_array to.

ml_int_array & ml_int_array::operator= const ml_int_array a  )  [inherited]
 

Sets the int_array equal to the given int_array.

Parameters:
a The int_array to assign the "this" int_array to.
Returns:
Returns the orginal array with its values reassigned.

int ml_int_array::length  )  const [inherited]
 

Returns the length of the int_array.

Returns:
Returns the length of the int_array.

int ml_int_array::is_empty  )  const [inherited]
 

Checks the size of the array, returns 1 unless the int_array is empty.

Returns:
Returns 1 for and "empty" array, 0 otherwise.

ml_int_array ml_int_array::find ml_comparison  op,
int  target
const [inherited]
 

Returns an int_array of all indices in the int_array for which the given operator and operand is true.

Parameters:
op One the the enumerated comparison operators.
target The operand to compare with each int_array value.
Returns:
Returns an int_array of indices.

void ml_int_array::display char *  s = NULL  )  const [inherited]
 

Display function. Formats the int_array in a human readable fashion and prints to standard out.

Parameters:
s A message to be included in the display.

char * ml_int_array::to_string  )  [inherited]
 

Converts data structure to a string representation. THIS FUNCTION IS NOT THREAD SAFE. to_string() may be called without any action to release memory on the part of the user, i.e. the pointer that is returned does not point to a buffer that needs to be freed. This buffer is freed internally each time to_string is called as well as when the destructor is called, so the data should be copied to a new buffer if the user needs to store it for future use.

Returns:
Returns a char *

int ml_int_array::is_unique  )  const [inherited]
 

Determines whether the all the elements in the int_array are unique.

Returns:
Returns 1 if all elements are unique, 0 if they are not.

int ml_int_array::sum  )  const [inherited]
 

Returns the sum of all the values in the int_array.

Returns:
The sum of all the values in the int_array.

int * ml_int_array::get_c_arr int &  s  )  const [inherited]
 

Converts the int_array into a standard C array.

Parameters:
s The size of the array will be returned through this parameter.
Returns:
Returns a standard C array of integers.

int ml_int_array::operator== const ml_int_array a  )  [inherited]
 

Tests two int_arrays for equality.

Parameters:
a int_array for comparison.

int ml_int_array::operator!= const ml_int_array a  )  [inherited]
 

Tests two int_arrays for in-equality.

Parameters:
a int_array for comparison.

ml_int_array ml_int_array::subset int  start,
int  end
[inherited]
 

Returns an int array of the specified subset of the original array.

Parameters:
start The first index to include in the subset
end The last index to include in the subset. This must be at least one greater than start, and must not be greater than the length of the current array.
Returns:
The subset of the array

ml_int_array ml_int_array::subset const ml_int_array indices  )  [inherited]
 

Returns an int array containing the specifed elements, in the given order, of the original array.

Parameters:
indices The elements indices to include in the new array. Indices that are out of bounds will result in zeroes in the appropriate places in the returned array. An empty indices array will result in the original array being returned unchanged.
Returns:
the subset of the array.

void ml_int_array::sort int  direction = 0  )  [inherited]
 

Sorts all the elements of the int_array. Ascending order is the default, pass a non-zero value for descending sort.

Parameters:
direction The sort direction: 0 (default) for ascending, non-zero for descending.

void ml_int_array::remove const ml_int_array indices  )  [inherited]
 

Removes the indices in the given int_array and resizes the int_array downwards.

Parameters:
indices Int_array of indices to be removed from the int_array.

void ml_int_array::remove int  index  )  [inherited]
 

Removes the element at the specified index and resizes the int_array downwards.

Parameters:
index The index of the element to be removed.

void ml_int_array::append ml_int_array  b  )  [inherited]
 

Appends the given int_array to the end of the "this" array.

Parameters:
b The int_array to be appended to the end of the int_array.

void ml_int_array::append int  val  )  [inherited]
 

Appends the given integer to the end of the int_array.

Parameters:
val The integer value to be appended to the end of the int_array.

void ml_int_array::insert int  index,
int  val
[inherited]
 

Inserts a new element into the array, at the specified index.

Parameters:
index The position at which to place the new item. The inserted item will then be addressable by that index, and other elements will be moved down to accomodate it if necessary. An index beyond the current array bounds will cause the array to be resized.
val The integer value to be inserted into the int_array.

void ml_int_array::zero  )  [inherited]
 

Sets all elements of the int_array to zero

void ml_int_array::ones  )  [inherited]
 

Sets all elements of the int_array to zero

void ml_int_array::fliplr  )  [inherited]
 

Flips the elements of the array (an array {1,2,3} would become {3,2,1})

void ml_int_array::setdiff const ml_int_array b  )  [inherited]
 

Removes the elements that exist in B from the array, and then sorts the array.

Parameters:
b the array of elements to remove from this one.