INGOR
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ytArray Class Reference

Expandable array. More...

#include <ytArray.h>

Public Member Functions

#define YTLIB__ARRAY_DEFAULT_EXPAND_SIZE   16
 Expandable ytObject * Array.
 
ytArrayytArray_new ()
 Creates a new ytArray instance.
 
void ytArray_deleteAll (ytArray *this)
 Releases the array and all the elements in the array.
 
ytArrayytArray_clone (const ytArray *this)
 Returns the clone of this ytArray instance.
 
ytObjectytArray_cloneI (const ytObject *this)
 Returns the clone of this ytArray instance.
 
ytArrayytArray_arrayNew (size_t size)
 Creates the array of ytArray instances.
 
void ytArray_arrayDelete (ytArray *this, size_t size)
 Deletes the array of ytArray instances.
 
size_t ytArray_buffSize (const ytArray *this)
 Returns the current buffer size allocated.
 
ytArrayytArray_setBuffSize (ytArray *this, size_t new_size)
 Changes the size of buffer.
 
size_t ytArray_memSize (const ytArray *this)
 Returns the size of memory where the specified instance occupies.
 
size_t ytArray_arrayMemSize (const ytArray *this, size_t n)
 Returns the total size of memory used by the array of the array.
 
void ytArray_clear (ytArray *this)
 Removes all the elements in the array.
 
void ytArray_add (ytArray *this, ytObject *value)
 Adds a value.
 
void ytArray_set (ytArray *this, size_t index, ytObject *value)
 Sets a value at the specified position.
 
void ytArray_setSize (ytArray *this, size_t size)
 Changes the size of the array.
 
void ytArray_insert (ytArray *this, size_t index, ytObject *value)
 Inserts a value at the specified position.
 
ytObjectytArray_remove (ytArray *this, size_t index)
 
void ytArray_copy (ytArray *this, const ytArray *src)
 Copies values in another array into this.
 
void ytArray_copyArray (ytArray *this, size_t index, const ytObject **array, size_t size)
 Copies values in an array into this array.
 
ytObjectytArray_pop (ytArray *this)
 Returns the last element.
 
void ytArray_sort (ytArray *this)
 Sorts the elements in ascending order.
 
size_t ytArray_find (const ytArray *this, const ytObject *v)
 Returns the index of the value identical to the given one.
 
void ytArray_print (const ytArray *this, FILE *fp, char *delim)
 Prints the elements in the array.
 
void ytArray_MPI_Bcast (ytArray **pObject, int root, MPI_Comm comm)
 Broadcasts the array with MPI.
 

Detailed Description

Expandable array.

Member Function Documentation

◆ ytArray_add()

void ytArray_add ( ytArray this,
ytObject value 
)

Adds a value.

Parameters
this
value

◆ ytArray_arrayDelete()

void ytArray_arrayDelete ( ytArray this,
size_t  size 
)

Deletes the array of ytArray instances.

This deletes the array of the instances allocated by ytArray_arrayNew(). The users have to specify the same number to the size parameter as specified to ytArray_arrayNew().

Parameters
thispointer returned by ytArray_arrayNew().
sizethe size of the array.

◆ ytArray_arrayNew()

ytArray * ytArray_arrayNew ( size_t  size)

Creates the array of ytArray instances.

The i -th istance can be accecced by p + i where p is the pointer returned by this. For example:

;
ytArray_add(ar + i, value);
...
Expandable array.
ytArray * ytArray_arrayNew(size_t size)
Creates the array of ytArray instances.
Definition ytArray.c:154
void ytArray_add(ytArray *this, ytObject *value)
Adds a value.
Definition ytArray.c:262

Use ytArray_arrayDelete() to delete the allocated instances.

Parameters
sizethe number of instances to allocate.
See also
ytArray_arrayDelete()

◆ ytArray_buffSize()

size_t ytArray_buffSize ( const ytArray this)

Returns the current buffer size allocated.

Parameters
thispointer to the ytArray instance.
Returns
the size of allocated buffer in bytes.

◆ ytArray_clear()

void ytArray_clear ( ytArray this)

Removes all the elements in the array.

This does not remove the element but set the number of elements in the array to be zero. No memory de-allocation occurs.

◆ ytArray_copy()

void ytArray_copy ( ytArray this,
const ytArray src 
)

Copies values in another array into this.

Parameters
this
src

◆ ytArray_copyArray()

void ytArray_copyArray ( ytArray this,
size_t  index,
const ytObject **  array,
size_t  size 
)

Copies values in an array into this array.

Parameters
this
index
array
size

◆ ytArray_find()

size_t ytArray_find ( const ytArray this,
const ytObject v 
)

Returns the index of the value identical to the given one.

Parameters
this
vValue to find.
Returns
index, or ytArray_ERROR_VALUE if not found.

◆ ytArray_insert()

void ytArray_insert ( ytArray this,
size_t  index,
ytObject value 
)

Inserts a value at the specified position.

Parameters
this
index
value

◆ ytArray_memSize()

size_t ytArray_memSize ( const ytArray this)

Returns the size of memory where the specified instance occupies.

Parameters
thispointer to the ytArray instance.
Returns
the size of occupied memory size by the instance.

◆ ytArray_MPI_Bcast()

void ytArray_MPI_Bcast ( ytArray **  pObject,
int  root,
MPI_Comm  comm 
)

Broadcasts the array with MPI.

This is available only for the MPI-enabled ytLib.

This allocates working memory whose size is the same as the total memory required for storing all the elements in the array.

This calls MPI_Ibcast() three times internally.

Parameters
pObjectpointer to the array instance. in receiving ranks, the new instance is generated and set to the original pointer (*pObject).

◆ ytArray_new()

ytArray * ytArray_new ( )

Creates a new ytArray instance.

Returns
pointer to the newly created ytArray instance.

◆ ytArray_pop()

ytObject * ytArray_pop ( ytArray this)

Returns the last element.

The last element is returned and removed from the array.

Parameters
this
Returns
value at the end of the array.

◆ ytArray_print()

void ytArray_print ( const ytArray this,
FILE *  fp,
char *  delim 
)

Prints the elements in the array.

Parameters
this
fpFILE pointer to output.
delimdelimitor

◆ ytArray_remove()

ytObject * ytArray_remove ( ytArray this,
size_t  index 
)

\breif Removes the value at the specified position.

Returns
element to be deleted from the array.

◆ ytArray_set()

void ytArray_set ( ytArray this,
size_t  index,
ytObject value 
)

Sets a value at the specified position.

Parameters
this
index
value

◆ ytArray_setBuffSize()

ytArray * ytArray_setBuffSize ( ytArray this,
size_t  new_size 
)

Changes the size of buffer.

Parameters
this
new_size
Returns
this, or NULL if failed.

◆ ytArray_setSize()

void ytArray_setSize ( ytArray this,
size_t  size 
)

Changes the size of the array.

If the specified size is larger than the current size, new elements are not initialized.

If the specified size is less than the current size, this does not free the allocated memory. Instead, this simply changes the current size without changing any elements in the array.

Parameters
this
size===================================================

◆ ytArray_sort()

void ytArray_sort ( ytArray this)

Sorts the elements in ascending order.

Parameters
this

The documentation for this class was generated from the following files: