diff --git a/README.md b/README.md index e12c4d5..eb0abd3 100644 --- a/README.md +++ b/README.md @@ -41,35 +41,36 @@ Include in your code and begin using the library: ``` ## Usage +Version 1.2.0 changed the naming convention from `snake_case` to `PascalCase`. The snake case variant of the below functions can still be used, but the compiler will issue a warning. Snake case variants will be removed in 2.0.0. -### array_shift +### ArrayShift ```pawn -stock array_shift(array[], value, size = sizeof array) +stock ArrayShift(array[], value, size = sizeof array) ``` Appends `value` to the end of `array`. Pushes the first value off and returns it, moves everything down. -### array_unshift +### ArrayUnshift ```pawn -stock array_unshift(array[], value, size = sizeof array) +stock ArrayUnshift(array[], value, size = sizeof array) ``` Inserts `value` at the start of `array`. Pushes the last value off and returns it, moves everything up. -### array_sort +### ArraySort ```pawn -stock array_sort(arr[], left = 0, right = sizeof arr) +stock ArraySort(array[], left = 0, right = sizeof array) ``` Sorts `array` in ascending order. Implementation of the QuickSort algorithm. This function does not return any value. -### in_array +### InArray ```pawn -stock bool:in_array(needle, const haystack[], &index = 0, size = sizeof haystack) +stock bool:InArray(needle, const haystack[], &index = 0, size = sizeof haystack) ``` Returns `true` if `needle` is in `haystack`, false otherwise. Using the `index` parameter, this function can be used in a while loop to find all instances of a certain value: ```pawn new index = -1; -while(in_array(5, theArrayToSearch, index)) +while(InArray(5, theArrayToSearch, index)) { printf("found 5 at index: %d", index); } diff --git a/array_util.inc b/array_util.inc index 9da8ef5..e8b2827 100644 --- a/array_util.inc +++ b/array_util.inc @@ -37,7 +37,7 @@ * * The value at the first index. */ -stock array_shift(array[], value, size = sizeof array) +stock ArrayShift(array[], value, size = sizeof array) { new returnval = array[0]; @@ -50,6 +50,12 @@ stock array_shift(array[], value, size = sizeof array) return returnval; } +#pragma deprecated 2.0.0 +stock array_shift(array[], value, size = sizeof array) +{ + return ArrayShift(array, value, size); +} + /** * * Inserts a value at the start of array. Pushes the last value off and returns @@ -63,7 +69,7 @@ stock array_shift(array[], value, size = sizeof array) * * The value at size - 1. */ -stock array_unshift(array[], value, size = sizeof array) +stock ArrayUnshift(array[], value, size = sizeof array) { new returnval = array[size - 1]; @@ -76,6 +82,12 @@ stock array_unshift(array[], value, size = sizeof array) return returnval; } +#pragma deprecated 2.0.0 +stock array_unshift(array[], value, size = sizeof array) +{ + return ArrayUnshift(array, value, size); +} + /** * * Checks if a value exists within an array. @@ -86,7 +98,7 @@ stock array_unshift(array[], value, size = sizeof array) * Size of the array. * true if found, false otherwise. */ -stock bool:in_array(needle, const haystack[], &index = 0, size = sizeof haystack) +stock bool:InArray(needle, const haystack[], &index = 0, size = sizeof haystack) { while(index < size) { @@ -96,6 +108,12 @@ stock bool:in_array(needle, const haystack[], &index = 0, size = sizeof haystack return false; } +#pragma deprecated 2.0.0 +stock bool:in_array(needle, const haystack[], &index = 0, size = sizeof haystack) +{ + return InArray(needle, haystack, index, size); +} + /** * * Sorts array values in ascending order. Implementation of the QuickSort algorithm. @@ -104,7 +122,7 @@ stock bool:in_array(needle, const haystack[], &index = 0, size = sizeof haystack * Index of the lower bound, should normally be 0. * Index of the upper bound, should normally be the size of the array. */ -stock array_sort(array[], left = 0, right = sizeof array) +stock ArraySort(array[], left = 0, right = sizeof array) { new i = left, @@ -130,10 +148,16 @@ stock array_sort(array[], left = 0, right = sizeof array) // recursion if (left < j) - array_sort(array, left, j); + ArraySort(array, left, j); if (i < right) - array_sort(array, i, right); + ArraySort(array, i, right); +} + +#pragma deprecated 2.0.0 +stock array_sort(array[], left = 0, right = sizeof array) +{ + ArraySort(array, left, right); } // ----------------------------------------------------------------------------- diff --git a/test.pwn b/test.pwn index b603c16..dd6ebeb 100644 --- a/test.pwn +++ b/test.pwn @@ -3,82 +3,82 @@ main() { - testShift(); - testUnshift(); - testInArray(); - testSort(); + TestShift(); + TestUnshift(); + TestInArray(); + TestSort(); } -testShift() +TestShift() { - printf("\narray_shift"); + printf("\nArrayShift"); printf("-----------"); new arrayToShift[] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55}; printf("before shifting:"); - printArray(arrayToShift); + PrintArray(arrayToShift); - new firstValue = array_shift(arrayToShift, 89); + new firstValue = ArrayShift(arrayToShift, 89); printf("after shifting:"); - printArray(arrayToShift); + PrintArray(arrayToShift); printf("value that was shifted off: %d", firstValue); } -testUnshift() +TestUnshift() { - printf("\narray_unshift"); + printf("\nArrayUnshift"); printf("-------------"); new arrayToShift[] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55}; printf("before shifting:"); - printArray(arrayToShift); + PrintArray(arrayToShift); - new lastValue = array_unshift(arrayToShift, 89); + new lastValue = ArrayUnshift(arrayToShift, 89); printf("after shifting:"); - printArray(arrayToShift); + PrintArray(arrayToShift); printf("value that was shifted off: %d", lastValue); } -testInArray() +TestInArray() { - printf("\nin_array"); + printf("\nInArray"); printf("--------"); new testArray[] = {1, 3, 5, 7, 13, 5, 1, 7, 3}; printf("array to search in:"); - printArray(testArray); + PrintArray(testArray); printf("finding all the indexes that contain the number 5:"); new index = -1; - while(in_array(5, testArray, index)) + while(InArray(5, testArray, index)) { printf("found 5 at index: %d", index); } } -testSort() +TestSort() { - printf("\narray_sort"); + printf("\nArraySort"); printf("----------"); new arrayToSort[] = {13, 92, 85, 64, 17, 55, 33, 60, 58, 95}; printf("before sort:"); - printArray(arrayToSort); + PrintArray(arrayToSort); - array_sort(arrayToSort); + ArraySort(arrayToSort); printf("after sort:"); - printArray(arrayToSort); + PrintArray(arrayToSort); } -printArray(const arr[], size = sizeof arr) +PrintArray(const arr[], size = sizeof arr) { new output[128]; @@ -96,4 +96,4 @@ printArray(const arr[], size = sizeof arr) } print(output); -} \ No newline at end of file +}