2008-10-04 22:59:11 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
2009-04-14 23:40:48 +02:00
|
|
|
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
2008-10-04 22:59:11 +02:00
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This file is part of the SourceMod/SourcePawn SDK.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
2019-09-27 13:14:44 +02:00
|
|
|
*
|
2008-10-04 22:59:11 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
2009-04-14 23:40:48 +02:00
|
|
|
* Version: $Id$
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#if defined _sorting_included
|
2019-09-27 13:14:44 +02:00
|
|
|
#endinput
|
2008-10-04 22:59:11 +02:00
|
|
|
#endif
|
|
|
|
#define _sorting_included
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains sorting orders.
|
|
|
|
*/
|
|
|
|
enum SortOrder
|
|
|
|
{
|
2019-09-27 13:14:44 +02:00
|
|
|
Sort_Ascending = 0, /**< Ascending order */
|
|
|
|
Sort_Descending = 1, /**< Descending order */
|
|
|
|
Sort_Random = 2 /**< Random order */
|
2008-10-04 22:59:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data types for ADT Array Sorts
|
|
|
|
*/
|
|
|
|
enum SortType
|
|
|
|
{
|
2019-09-27 13:14:44 +02:00
|
|
|
Sort_Integer = 0,
|
|
|
|
Sort_Float,
|
|
|
|
Sort_String
|
2008-10-04 22:59:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sorts an array of integers.
|
|
|
|
*
|
2019-09-27 13:14:44 +02:00
|
|
|
* @param array Array of integers to sort in-place.
|
|
|
|
* @param array_size Size of the array.
|
|
|
|
* @param order Sorting order to use.
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native void SortIntegers(int[] array, int array_size, SortOrder order = Sort_Ascending);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sorts an array of float point numbers.
|
|
|
|
*
|
2019-09-27 13:14:44 +02:00
|
|
|
* @param array Array of floating point numbers to sort in-place.
|
|
|
|
* @param array_size Size of the array.
|
|
|
|
* @param order Sorting order to use.
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native void SortFloats(float[] array, int array_size, SortOrder order = Sort_Ascending);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sorts an array of strings.
|
|
|
|
*
|
2019-09-27 13:14:44 +02:00
|
|
|
* @param array Array of strings to sort in-place.
|
|
|
|
* @param array_size Size of the array.
|
|
|
|
* @param order Sorting order to use.
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native void SortStrings(char[][] array, int array_size, SortOrder order = Sort_Ascending);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort comparison function for 1D array elements.
|
|
|
|
* @note You may need to use explicit tags in order to use data properly.
|
|
|
|
*
|
2019-09-27 13:14:44 +02:00
|
|
|
* @param elem1 First element to compare.
|
|
|
|
* @param elem2 Second element to compare.
|
|
|
|
* @param array Array that is being sorted (order is undefined).
|
|
|
|
* @param hndl Handle optionally passed in while sorting.
|
|
|
|
* @return -1 if first should go before second
|
|
|
|
* 0 if first is equal to second
|
|
|
|
* 1 if first should go after second
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
2015-03-21 15:43:24 +01:00
|
|
|
typedef SortFunc1D = function int (int elem1, int elem2, const int[] array, Handle hndl);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2019-09-27 13:14:44 +02:00
|
|
|
/**
|
2008-10-04 22:59:11 +02:00
|
|
|
* Sorts a custom 1D array. You must pass in a comparison function.
|
|
|
|
*
|
2019-09-27 13:14:44 +02:00
|
|
|
* @param array Array to sort.
|
|
|
|
* @param array_size Size of the array to sort.
|
|
|
|
* @param sortfunc Sort function.
|
|
|
|
* @param hndl Optional Handle to pass through the comparison calls.
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native void SortCustom1D(int[] array, int array_size, SortFunc1D sortfunc, Handle hndl=INVALID_HANDLE);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort comparison function for 2D array elements (sub-arrays).
|
|
|
|
* @note You may need to use explicit tags in order to use data properly.
|
|
|
|
*
|
2019-09-27 13:14:44 +02:00
|
|
|
* @param elem1 First array to compare.
|
|
|
|
* @param elem2 Second array to compare.
|
|
|
|
* @param array Array that is being sorted (order is undefined).
|
|
|
|
* @param hndl Handle optionally passed in while sorting.
|
|
|
|
* @return -1 if first should go before second
|
|
|
|
* 0 if first is equal to second
|
|
|
|
* 1 if first should go after second
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
2015-03-21 15:43:24 +01:00
|
|
|
typeset SortFunc2D
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2015-03-21 15:43:24 +01:00
|
|
|
function int (int[] elem1, int[] elem2, const int[][] array, Handle hndl);
|
|
|
|
function int (char[] elem1, char[] elem2, const char[][] array, Handle hndl);
|
2008-10-04 22:59:11 +02:00
|
|
|
};
|
|
|
|
|
2019-09-27 13:14:44 +02:00
|
|
|
/**
|
2008-10-04 22:59:11 +02:00
|
|
|
* Sorts a custom 2D array. You must pass in a comparison function.
|
|
|
|
*
|
2019-09-27 13:14:44 +02:00
|
|
|
* @param array Array to sort.
|
|
|
|
* @param array_size Size of the major array to sort (first index, outermost).
|
|
|
|
* @param sortfunc Sort comparison function to use.
|
|
|
|
* @param hndl Optional Handle to pass through the comparison calls.
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native void SortCustom2D(any[][] array, int array_size, SortFunc2D sortfunc, Handle hndl=INVALID_HANDLE);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort an ADT Array. Specify the type as Integer, Float, or String.
|
|
|
|
*
|
2019-09-27 13:14:44 +02:00
|
|
|
* @param array Array Handle to sort
|
|
|
|
* @param order Sort order to use, same as other sorts.
|
|
|
|
* @param type Data type stored in the ADT Array
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native void SortADTArray(Handle array, SortOrder order, SortType type);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort comparison function for ADT Array elements. Function provides you with
|
|
|
|
* indexes currently being sorted, use ADT Array functions to retrieve the
|
|
|
|
* index values and compare.
|
|
|
|
*
|
2019-09-27 13:14:44 +02:00
|
|
|
* @param index1 First index to compare.
|
|
|
|
* @param index2 Second index to compare.
|
|
|
|
* @param array Array that is being sorted (order is undefined).
|
|
|
|
* @param hndl Handle optionally passed in while sorting.
|
|
|
|
* @return -1 if first should go before second
|
|
|
|
* 0 if first is equal to second
|
|
|
|
* 1 if first should go after second
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
2015-03-21 15:43:24 +01:00
|
|
|
typedef SortFuncADTArray = function int (int index1, int index2, Handle array, Handle hndl);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom sorts an ADT Array. You must pass in a comparison function.
|
|
|
|
*
|
2019-09-27 13:14:44 +02:00
|
|
|
* @param array Array Handle to sort
|
|
|
|
* @param sortfunc Sort comparison function to use
|
|
|
|
* @param hndl Optional Handle to pass through the comparison calls.
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
2019-09-27 13:14:44 +02:00
|
|
|
native void SortADTArrayCustom(Handle array, SortFuncADTArray sortfunc, Handle hndl=INVALID_HANDLE);
|