#include <array.h>
|
int | array () |
| allocate new memory of array More...
|
|
int | array (int start_count) |
| Constructs an array and allocates an initial chunk of memory. More...
|
|
int | push_back (int id, const T &element) |
|
int | push_front (int id, const T &element) |
|
void | reallocate (int id, int new_size) |
| Reallocates the array, make it bigger or smaller. More...
|
|
void | set_used (int id, int usedNow) |
| Sets the size of the array and allocates new elements if necessary. More...
|
|
const T & | get (int id, int index) |
| Direct const access operator. More...
|
|
int | size (int id) |
| Get number of occupied elements of the array. More...
|
|
int | erase (int id, int index) |
|
void | clear (int id) |
| Clears the array and deletes all allocated memory. More...
|
|
bool | close (int id) |
| free memory of array More...
|
|
int | insert (int id, const T &element, int index) |
|
int | search (int id, const T &element) |
|
int | search_array (int id, const T &element) |
|
bool | sort (int id) |
|
void | for (int id, void *function) |
| get element from array with for loop.
More...
|
|
bool | set (int id, int index, const T &new_element) |
| update element in specific slot.
More...
|
|
void | log (int id) |
| print all elements in log window More...
|
|
bool | save (int id, const char *filename, const char *option="xml") |
| save all elements to file as xml or json More...
|
|
const char * | tostring (int id, const char *option="xml") |
| save all elements and value to string buffer as xml or json More...
|
|
Definition at line 8 of file array.h.
◆ array() [1/2]
allocate new memory of array
- Returns
- id >= 0 is successed, -1 is failed.
Must call array.close() for free memory.
◆ array() [2/2]
int array::array |
( |
int |
start_count | ) |
|
Constructs an array and allocates an initial chunk of memory.
- Parameters
-
start_count | Amount of elements to pre-allocate. |
- Returns
- id >= 0 is successed, -1 is failed.
Must call array.close() for free memory.
◆ clear()
void array::clear |
( |
int |
id | ) |
|
Clears the array and deletes all allocated memory.
- Parameters
-
◆ close()
bool array::close |
( |
int |
id | ) |
|
free memory of array
- Parameters
-
- Returns
- true is successed, false is failed.
◆ erase()
Erases an element from the array.
May be slow, because all elements following after the erased element have to be copied.
- Parameters
-
id | array id. |
index | Index of element to be operate. |
- Returns
- new size of array is successed, 0 is empty, -1 is failed.
◆ for()
void array::for |
( |
int |
id, |
|
|
void * |
function |
|
) |
| |
get element from array with for loop.
- Parameters
-
id | array id. |
function | call the function until end loop.
Automatic built-in index loop each, can using "null" with function: array.get() array.set()
Using break() or return() to stop them. |
◆ get()
const T& array::get |
( |
int |
id, |
|
|
int |
index |
|
) |
| |
Direct const access operator.
- Parameters
-
id | array id. |
index | Index of element to be operate. |
- Returns
- Element of array from index is successed, empty string is failed.
◆ insert()
int array::insert |
( |
int |
id, |
|
|
const T & |
element, |
|
|
int |
index |
|
) |
| |
Insert item into array at specified position.
Please use this only if you know what you are doing(possible performance loss).The preferred method of adding elements should be array.push_back().
- Parameters
-
id | array id. |
element | Element to be inserted. |
index | Where position to insert the new element. |
- Returns
- new size of array is successed, 0 or -1 is failed.
◆ log()
void array::log |
( |
int |
id | ) |
|
print all elements in log window
- Parameters
-
◆ push_back()
int array::push_back |
( |
int |
id, |
|
|
const T & |
element |
|
) |
| |
Adds an element at back of array.
If the array is too small to add this new element it is made bigger.
- Parameters
-
id | array id. |
element | Element to add at the back of the array. |
- Returns
- new size of array is successed, 0 or -1 is failed.
◆ push_front()
int array::push_front |
( |
int |
id, |
|
|
const T & |
element |
|
) |
| |
Adds an element at the front of the array.
If the array is to small to add this new element, the array is made bigger.Please note that this is slow, because the whole array needs to be copied for this.
- Parameters
-
id | array id. |
element | Element to add at the front of the array. |
- Returns
- new size of array is successed, 0 or -1 is failed.
◆ reallocate()
void array::reallocate |
( |
int |
id, |
|
|
int |
new_size |
|
) |
| |
Reallocates the array, make it bigger or smaller.
- Parameters
-
id | array id. |
new_size | New size of array. |
◆ save()
bool array::save |
( |
int |
id, |
|
|
const char * |
filename, |
|
|
const char * |
option = "xml" |
|
) |
| |
save all elements to file as xml or json
- Parameters
-
id | array id. |
option | file type xml or json. default: xml |
- Returns
- true is successed, false is failed.
◆ search()
int array::search |
( |
int |
id, |
|
|
const T & |
element |
|
) |
| |
Finds an element in linear time, which is very slow.
Only works if == operator is implemented.
- Parameters
-
id | array id. |
element | Element to search for. |
- Returns
- index of array is successed, -1 is failed.
◆ search_array()
int array::search_array |
( |
int |
id, |
|
|
const T & |
element |
|
) |
| |
Finds an element in linear time, which is very slow.
also return new array include a set of data founded if.
- Parameters
-
id | array id. |
element | Element to search for. |
- Returns
- id of new array is successed, -1 is failed.
Must call array.close() for free memory.
◆ set()
bool array::set |
( |
int |
id, |
|
|
int |
index, |
|
|
const T & |
new_element |
|
) |
| |
update element in specific slot.
- Parameters
-
id | array id. |
index | Where position to insert the new element. |
new_element | Element to update. |
- Returns
- true is successed, false is failed.
◆ set_used()
void array::set_used |
( |
int |
id, |
|
|
int |
usedNow |
|
) |
| |
Sets the size of the array and allocates new elements if necessary.
- Parameters
-
id | array id. |
usedNow | Amount of elements now used. |
◆ size()
Get number of occupied elements of the array.
- Parameters
-
- Returns
- Size of elements in the array which are actually occupied. empty is 0.
◆ sort()
bool array::sort |
( |
int |
id | ) |
|
Sorts the array using heapsort.
There is no additional memory waste and the algorithm performs O(n*log n) in worst case.
- Parameters
-
- Returns
- true is successed, false is failed.
◆ tostring()
const char* array::tostring |
( |
int |
id, |
|
|
const char * |
option = "xml" |
|
) |
| |
save all elements and value to string buffer as xml or json
- Parameters
-
id | array id. |
option | file type xml or json. default: xml |
- Returns
- successed return array buffer in string format, otherwise is empty string
The documentation for this class was generated from the following file: