Fixed betting bugs.

This commit is contained in:
2021-09-27 14:27:13 -07:00
parent fff60c5768
commit d04c5f6505
22 changed files with 169 additions and 62 deletions

View File

@ -123,4 +123,17 @@ void arraySplice(
// Now copy it back into the original array
arrayCopy(size, temporary, takeLength, arrayGet(size, array, start));
free(temporary);
}
int32_t arraySum(
size_t size, void *array, int32_t length, arraysumcallback_t *callback
) {
int32_t i, count;
count = 0;
for(i = 0; i < length; i++) {
if(!callback(arrayGet(size, array, i))) continue;
count++;
}
return count;
}

View File

@ -18,6 +18,13 @@
*/
typedef int32_t arraysort_t(const void*, const void*);
/**
* Callback used when calculating the sum of an array that match a state.
* @param item Item within the array.
* @return True if counted, otherwise false.
*/
typedef bool arraysumcallback_t(void*);
/**
* Retreive the pointer to an elment within the array of unknown type.
*
@ -149,4 +156,18 @@ void arrayRewind(size_t size, void *source, int32_t length, int32_t start,
*/
void arraySplice(
size_t size, void *array, int32_t start, int32_t count, int32_t length
);
/**
* Sums the count of items that match a given filter in an array. The filter
* is a callback method that the user can define.
*
* @param size Size of each element within the array.
* @param array Array itself.
* @param length Length of the array.
* @param callback Callback that will return true/false when called.
* @return The count of items that matched the callback invokation.
*/
int32_t arraySum(
size_t size, void *array, int32_t length, arraysumcallback_t *callback
);

View File

@ -73,4 +73,11 @@
* @param n Number to sign.
* @returns The signed number.
*/
#define mathSign(n) (n>=0 ? 1.0f : -1.0f)
#define mathSign(n) (n>=0 ? 1.0f : -1.0f)
/**
* Round a number down to the nearest whole number.
* @param n Floating number to round down.
* @returns The floor of the input.
*/
#define mathFloor(n) (floorf(n))