Growable array of xarray_data_t * entries. Supports copied payloads, ownership transfer, pool-backed allocation, sorting and key-based search.
xarray_data_t: one array slot containingpData,nSize,nKeyand pool pointer.xarray_t: array runtime state, optional pool owner, cleanup callback and capacity/usage counters.
- Args:
pArr: destination array context; its pool is used.pData: source pointer.nSize: payload size; when> 0the payload is copied, when0the pointer is stored directly.nKey: key stored in the entry.
- Returns:
- new entry on success.
NULLon allocation failure.
- Frees one entry and, when
nSize > 0, frees its payload too. - No return value.
- Runs
pArr->clearCbfirst if set, then frees the entry. - No return value.
- Args:
pArr: array to initialize.pPool/nPoolSize: external or internal pool source.nSize: initial capacity.nFixed: whether realloc/shrink is disabled.
- Does:
- zeroes runtime state and optionally allocates slot storage.
InitPoolalso creates and owns a pool.
- Returns:
pArr->pDatawhen initial storage exists.- non-
NULLsuccess even with zero initial size. NULLon allocation failure.
- Heap/pool allocate the
xarray_titself and then initialize it. - Return allocated array or
NULL.
- Grows when full and shrinks when usage drops below 25%, unless fixed.
- Returns new capacity.
- Returns
0on failure.
- Clears every slot via
XArray_ClearData. - Resets owned pool when
nHasPoolis true.
- Clears entries, frees slot array, destroys owned pool and optionally frees
pArritself.
- Destroys the array and nulls the caller pointer.
- Appends a ready-made entry.
- Returns appended index on success.
- Returns
XARRAY_FAILUREon failure and clearspNewData.
- Creates a new entry with
XArray_NewDataand appends it. - Returns appended index or
XARRAY_FAILURE.
- Stores the raw pointer without copying and then records
nSize. - Use this as ownership transfer.
- Returns appended index or
XARRAY_FAILURE.
- Same as
AddDatabut storesnKey. - Returns appended index or
XARRAY_FAILURE.
- Replaces the slot at
nIndex. - Returns the old entry pointer.
- Returns
NULLwhen index is outside capacity.
- Creates a new entry from data and replaces the slot.
- Returns old entry pointer or
NULL.
- Inserts one entry at
nIndexand shifts later entries right. - Returns the element now located at
nIndex + 1after insertion. - Returns
NULLon allocation/space failure or when insert point had no previous entry.
- Creates an entry and inserts it.
- Returns same semantics as
XArray_Insert.
- Returns slot pointer or
NULL.
- Returns payload pointer or
NULL.
- Returns payload pointer or fallback
pRet.
- Returns payload size or
0.
- Returns entry key or
0.
- Returns
1when slot exists and is non-NULL, otherwise0.
- Return used slots / total capacity.
- Return
0for null array.
- Removes one slot, shifts later entries left and may shrink capacity.
- Returns removed entry pointer for caller-owned cleanup.
- Returns
NULLwhen index is invalid.
- Same removal path as
Remove, but also clears/frees the removed entry.
- Swaps two used entries in place.
- Quick-sorts used entries with the provided comparator.
- Bubble-sorts used entries.
void XArray_QuickSort(xarray_t *pArr, xarray_comparator_t compare, void *pCtx, int nStart, int nFinish)
- Recursive quicksort over an explicit range.
- Sorts by
XARRAY_SORTBY_SIZEorXARRAY_SORTBY_KEY.
- Args:
- array and search key.
- Returns:
- matching index on success.
XARRAY_FAILURE(-1) when not found or array is unusable.
- Notes:
BinarySearchassumes entries are already sorted bynKey.