Public Member Functions | Protected Attributes

CDynamicArray< T > Class Template Reference


Detailed Description

template<class T>
class shogun::CDynamicArray< T >

Template Dynamic array class that creates an array that can be used like a list or an array.

It grows and shrinks dynamically, while elements can be accessed via index. It is performance tuned for simple types like float etc. and for hi-level objects only stores pointers, which are not automagically SG_REF'd/deleted.

Definition at line 27 of file DynamicArray.h.

Inheritance diagram for CDynamicArray< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CDynamicArray (int32_t p_resize_granularity=128)
virtual ~CDynamicArray ()
int32_t set_granularity (int32_t g)
int32_t get_array_size ()
int32_t get_num_elements () const
get_element (int32_t index) const
get_element_safe (int32_t index) const
bool set_element (T element, int32_t index)
bool insert_element (T element, int32_t index)
bool append_element (T element)
int32_t find_element (T element)
bool delete_element (int32_t idx)
bool resize_array (int32_t n)
T * get_array ()
void set_array (T *p_array, int32_t p_num_elements, int32_t array_size)
void clear_array ()
operator[] (int32_t index) const
CDynamicArray< T > & operator= (CDynamicArray< T > &orig)
virtual const char * get_name () const

Protected Attributes

int32_t resize_granularity
T * array
int32_t num_elements
int32_t last_element_idx

Constructor & Destructor Documentation

CDynamicArray ( int32_t  p_resize_granularity = 128  ) 

constructor

Parameters:
p_resize_granularity resize granularity

Definition at line 34 of file DynamicArray.h.

virtual ~CDynamicArray (  )  [virtual]

Definition at line 46 of file DynamicArray.h.


Member Function Documentation

bool append_element ( element  ) 

append array element to the end of array

Parameters:
element element to append
Returns:
if setting was successful

Definition at line 166 of file DynamicArray.h.

void clear_array (  ) 

clear the array (with zeros)

Definition at line 275 of file DynamicArray.h.

bool delete_element ( int32_t  idx  ) 

delete array element at idx (does not call delete[] or the like)

Parameters:
idx index
Returns:
if deleting was successful

Definition at line 200 of file DynamicArray.h.

int32_t find_element ( element  ) 

find first occurence of array element and return its index or -1 if not available

Parameters:
element element to search for
Returns:
index of element or -1

Definition at line 177 of file DynamicArray.h.

T* get_array (  ) 

get the array call get_array just before messing with it DO NOT call any [],resize/delete functions after get_array(), the pointer may become invalid !

Returns:
the array

Definition at line 255 of file DynamicArray.h.

int32_t get_array_size (  ) 

get array size (including granularity buffer)

Returns:
total array size (including granularity buffer)

Definition at line 64 of file DynamicArray.h.

T get_element ( int32_t  index  )  const

get array element at index

(does NOT do bounds checking)

Parameters:
index index
Returns:
array element at index

Definition at line 85 of file DynamicArray.h.

T get_element_safe ( int32_t  index  )  const

get array element at index

(does bounds checking)

Parameters:
index index
Returns:
array element at index

Definition at line 97 of file DynamicArray.h.

virtual const char* get_name (  )  const [virtual]
Returns:
object name

Implements CSGObject.

Definition at line 311 of file DynamicArray.h.

int32_t get_num_elements (  )  const

get number of elements

Returns:
number of elements

Definition at line 73 of file DynamicArray.h.

bool insert_element ( element,
int32_t  index 
)

insert array element at index

Parameters:
element element to insert
index index
Returns:
if setting was successful

Definition at line 145 of file DynamicArray.h.

CDynamicArray<T>& operator= ( CDynamicArray< T > &  orig  ) 

operator overload for array assignment

Parameters:
orig original array
Returns:
new array

Definition at line 300 of file DynamicArray.h.

T operator[] ( int32_t  index  )  const

operator overload for array read only access use set_element() for write access (will also make the array dynamically grow)

DOES NOT DO ANY BOUNDS CHECKING

Parameters:
index index
Returns:
element at index

Definition at line 290 of file DynamicArray.h.

bool resize_array ( int32_t  n  ) 

resize the array

Parameters:
n new size
Returns:
if resizing was successful

Definition at line 224 of file DynamicArray.h.

void set_array ( T *  p_array,
int32_t  p_num_elements,
int32_t  array_size 
)

set the array pointer and free previously allocated memory

Parameters:
p_array new array
p_num_elements last element index + 1
array_size number of elements in array

Definition at line 266 of file DynamicArray.h.

bool set_element ( element,
int32_t  index 
)

set array element at index

Parameters:
element element to set
index index
Returns:
if setting was successful

Definition at line 113 of file DynamicArray.h.

int32_t set_granularity ( int32_t  g  ) 

set the resize granularity

Parameters:
g new granularity
Returns:
what has been set (minimum is 128)

Definition at line 53 of file DynamicArray.h.


Member Data Documentation

T* array [protected]

memory for dynamic array

Definition at line 318 of file DynamicArray.h.

int32_t last_element_idx [protected]

the element in the array that has largest index

Definition at line 324 of file DynamicArray.h.

int32_t num_elements [protected]

the number of potentially used elements in array

Definition at line 321 of file DynamicArray.h.

int32_t resize_granularity [protected]

shrink/grow step size

Definition at line 315 of file DynamicArray.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation