Added rewind method.
This commit is contained in:
@ -86,4 +86,22 @@ int32_t arrayFindString(char **array, int32_t arrayLength, char *value) {
|
||||
if(strcmp(array[i], value) == 0) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void arrayRewind(size_t size, void *source, int32_t length, int32_t start,
|
||||
int32_t count
|
||||
) {
|
||||
if(count == -1) count = length - start;
|
||||
|
||||
// Create a temporary new array to house the data.
|
||||
void *temporary = malloc(size * count);
|
||||
|
||||
// Copy the data from the source to the temporary array.
|
||||
arrayCopy(size, arrayGet(size, source, start), count, temporary);
|
||||
|
||||
// Now copy the data back to the source array.
|
||||
arrayCopy(size, temporary, count, source);
|
||||
|
||||
// Cleanup the temporary array.
|
||||
free(temporary);
|
||||
}
|
@ -99,4 +99,19 @@ int32_t _arraySorterUint8(const void* left, const void* right);
|
||||
* @param value The value to search for.
|
||||
* @return The index that the strings exists within the array.
|
||||
*/
|
||||
int32_t arrayFindString(char **array, int32_t arrayLength, char *value);
|
||||
int32_t arrayFindString(char **array, int32_t arrayLength, char *value);
|
||||
|
||||
/**
|
||||
* Rewinds an array backwards. This is used to take an array that has some data
|
||||
* used towards the end of an array, but the data near the start is no longer
|
||||
* used. This will take the end data and put it back at the start.
|
||||
*
|
||||
* @param size The size of each element within the array.
|
||||
* @param source The array itself.
|
||||
* @param length The total length of the array.
|
||||
* @param start The first index within the array that you want to keep.
|
||||
* @param count Count of items after start to use. Use -1 to take the remaining.
|
||||
*/
|
||||
void arrayRewind(size_t size, void *source, int32_t length, int32_t start,
|
||||
int32_t end
|
||||
);
|
Reference in New Issue
Block a user