Add ArraySortEx/SortADTArray natives and new sort method Sort_Random (bug 5494, r=Nextra)
Former-commit-id: 1ff337d9801e2fbd9ad210bc1285d31679b3029e
This commit is contained in:
@@ -252,3 +252,44 @@ native ArrayDestroy(&Array:which);
|
||||
* Note that unlike the sorting.inc versions, the array passed to the callback is not in mid-sorted state.
|
||||
*/
|
||||
native ArraySort(Array:array, const comparefunc[], data[]="", data_size=0);
|
||||
|
||||
/**
|
||||
* A faster version of ArraySort.
|
||||
* The sorting algorithm then uses your comparison function to sort the data.
|
||||
*
|
||||
* The advantage of this native is that the Array elements being compared are
|
||||
* directly passed into your function, instead of the item indexes that are passed by ArraySort.
|
||||
* This removes the need for calling ArrayGet[Cell|String|Array] every time before being
|
||||
* able to compare the elements.
|
||||
*
|
||||
* For Arrays with a cellsize of 1 (used for storing integers and floats),
|
||||
* the function is called in the following manner:
|
||||
*
|
||||
* public MySortFunc(Array:array, elem1, elem2, const data[], data_size)
|
||||
*
|
||||
* array - Array handle in its current un-sorted state.
|
||||
* elem1, elem2 - Current element pair being compared
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
*
|
||||
* For Arrays with a cellsize larger than 1 (used for storing arrays and strings),
|
||||
* the function is called in the following manner:
|
||||
*
|
||||
* public MySortFunc(Array:array, elem1[], elem2[], const data[], data_size)
|
||||
*
|
||||
* array - Array handle in its current un-sorted state.
|
||||
* elem1[], elem2[] - Current element pair being compared
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
*
|
||||
*
|
||||
* In both cases your function should return:
|
||||
* -1 if elem1 should go before elem2
|
||||
* 0 if elem1 and elem2 are equal
|
||||
* 1 if elem1 should go after elem2
|
||||
*
|
||||
* Note that the parameters after elem2 are all optional and you do not need to specify them.
|
||||
*
|
||||
* Note that unlike the sorting.inc versions, the array passed to the callback is not in mid-sorted state.
|
||||
*/
|
||||
native ArraySortEx(Array:array, const comparefunc[], data[]="", data_size=0);
|
||||
|
Reference in New Issue
Block a user