3 * =============================================================================
4 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
34 #if defined _sorting_included
37 #define _sorting_included
40 * Contains sorting orders.
44 Sort_Ascending = 0, /**< Ascending order */
45 Sort_Descending = 1, /**< Descending order */
46 Sort_Random = 2 /**< Random order */
50 * Data types for ADT Array Sorts
60 * Sorts an array of integers.
62 * @param array Array of integers to sort in-place.
63 * @param array_size Size of the array.
64 * @param order Sorting order to use.
67 native SortIntegers(array[], array_size, SortOrder:order = Sort_Ascending);
70 * Sorts an array of float point numbers.
72 * @param array Array of floating point numbers to sort in-place.
73 * @param array_size Size of the array.
74 * @param order Sorting order to use.
77 native SortFloats(Float:array[], array_size, SortOrder:order = Sort_Ascending);
80 * Sorts an array of strings.
82 * @param array Array of strings to sort in-place.
83 * @param array_size Size of the array.
84 * @param order Sorting order to use.
87 native SortStrings(String:array[][], array_size, SortOrder:order = Sort_Ascending);
90 * Sort comparison function for 1D array elements.
91 * @note You may need to use explicit tags in order to use data properly.
93 * @param elem1 First element to compare.
94 * @param elem2 Second element to compare.
95 * @param array Array that is being sorted (order is undefined).
96 * @param hndl Handle optionally passed in while sorting.
97 * @return -1 if first should go before second
98 * 0 if first is equal to second
99 * 1 if first should go after second
101 functag public SortFunc1D(elem1, elem2, const array[], Handle:hndl);
104 * Sorts a custom 1D array. You must pass in a comparison function.
106 * @param array Array to sort.
107 * @param array_size Size of the array to sort.
108 * @param sortfunc Sort function.
109 * @param hndl Optional Handle to pass through the comparison calls.
112 native SortCustom1D(array[], array_size, SortFunc1D:sortfunc, Handle:hndl=INVALID_HANDLE);
115 * Sort comparison function for 2D array elements (sub-arrays).
116 * @note You may need to use explicit tags in order to use data properly.
118 * @param elem1 First array to compare.
119 * @param elem2 Second array to compare.
120 * @param array Array that is being sorted (order is undefined).
121 * @param hndl Handle optionally passed in while sorting.
122 * @return -1 if first should go before second
123 * 0 if first is equal to second
124 * 1 if first should go after second
128 public(array[], array[], const array[][], Handle:hndl),
129 public(String:array[], String:array[], const String:array[][], Handle:hndl),
133 * Sorts a custom 2D array. You must pass in a comparison function.
135 * @param array Array to sort.
136 * @param array_size Size of the major array to sort (first index, outermost).
137 * @param sortfunc Sort comparison function to use.
138 * @param hndl Optional Handle to pass through the comparison calls.
141 native SortCustom2D(array[][], array_size, SortFunc2D:sortfunc, Handle:hndl=INVALID_HANDLE);
144 * Sort an ADT Array. Specify the type as Integer, Float, or String.
146 * @param array Array Handle to sort
147 * @param order Sort order to use, same as other sorts.
148 * @param type Data type stored in the ADT Array
151 native SortADTArray(Handle:array, SortOrder:order, SortType:type);
154 * Sort comparison function for ADT Array elements. Function provides you with
155 * indexes currently being sorted, use ADT Array functions to retrieve the
156 * index values and compare.
158 * @param index1 First index to compare.
159 * @param index2 Second index to compare.
160 * @param array Array that is being sorted (order is undefined).
161 * @param hndl Handle optionally passed in while sorting.
162 * @return -1 if first should go before second
163 * 0 if first is equal to second
164 * 1 if first should go after second
166 functag public SortFuncADTArray(index1, index2, Handle:array, Handle:hndl);
169 * Custom sorts an ADT Array. You must pass in a comparison function.
171 * @param array Array Handle to sort
172 * @param sortfunc Sort comparision function to use
173 * @param hndl Optional Handle to pass through the comparison calls.
176 native SortADTArrayCustom(Handle:array, SortFuncADTArray:sortfunc, Handle:hndl=INVALID_HANDLE);