Group PJ_ARRAY

group PJ_ARRAY

This module provides helper to manipulate array of elements of any size. It provides most used array operations such as insert, erase, and search.

Functions

void pj_array_insert(void *array, unsigned elem_size, unsigned count, unsigned pos, const void *value)

Insert value to the array at the given position, and rearrange the remaining nodes after the position.

Parameters:
  • array – the array.

  • elem_size – the size of the individual element.

  • count – the CURRENT number of elements in the array.

  • pos – the position where the new element is put.

  • value – the value to copy to the new element.

void pj_array_erase(void *array, unsigned elem_size, unsigned count, unsigned pos)

Erase a value from the array at given position, and rearrange the remaining elements post the erased element.

Parameters:
  • array – the array.

  • elem_size – the size of the individual element.

  • count – the current number of elements in the array.

  • pos – the index/position to delete.

pj_status_t pj_array_find(const void *array, unsigned elem_size, unsigned count, pj_status_t (*matching)(const void *value), void **result)

Search the first value in the array according to matching function.

Parameters:
  • array – the array.

  • elem_size – the individual size of the element.

  • count – the number of elements.

  • matching – the matching function, which MUST return PJ_SUCCESS if the specified element match.

  • result – the pointer to the value found.

Returns:

PJ_SUCCESS if value is found, otherwise the error code.