Dawn/src/util/array.h

70 lines
2.0 KiB
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
/**
* Retreive the pointer to an elment within the array of unknown type.
*
* @param size Size of each element within the array.
* @param array Array to get from.
* @param index Index to get
* @return Pointer to the item in the array.
*/
void * arrayGet(size_t size, void *array, int32_t index);
/**
* Randomizes the contents of an array.
*
* @param size Size of each element within the array.
* @param array Array to shuffle.
* @param arrayLength Length of the array.
*/
void arrayShuffle(size_t size, void *array, int32_t arrayLength);
/**
* Find the index within the array that matches the given value.
*
* @param size Size of each element within the array.
* @param array Array to get from.
* @param length Max length to check to.
* @param value Value to look for. This is a literal compare of value == value.
* @returns The index within the array that matches, or -1 if no match.
*/
int32_t arrayFind(size_t size, void *array, int32_t length, void *value);
/**
* Sort an array based on the result of an array sort callback.
*
* @param size Size of each element within the array.
* @param array Array to sort.
* @param length Max length to sort to.
* @param sort Callback to use to sort.
*/
void arraySort(size_t size, void *array, int32_t length, arraysort_t *sort);
/**
* Sort an int32 array.
*
* @param array Array to sort.
* @param length Max length to sort.
*/
void arraySortInt32(int32_t *array, int32_t length);
/** Internal int32_t array sorter. */
int32_t _arraySorterInt32(const void *left, const void* right);
/**
* Sort a uint8_t array.
*
* @param array Array to sort.
* @param length Max Length to sort.
*/
void arraySortUint8(uint8_t *array, int32_t length);
/** Internal uint8_t array sorter. */
int32_t _arraySorterUint8(const void* left, const void* right);