plugins/include/sorting.inc
author Matt Woodrow <pred@alliedmods.net>
Fri Aug 08 00:17:37 2008 +0000 (2008-08-08)
changeset 2224 676c3b826f13
parent 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Initial Import of beta structs extension.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     5
 * =============================================================================
ds@1952
     6
 *
ds@1952
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@1952
     8
 *
ds@1952
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    11
 * Free Software Foundation.
ds@1952
    12
 * 
ds@1952
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    16
 * details.
ds@1952
    17
 *
ds@1952
    18
 * You should have received a copy of the GNU General Public License along with
ds@1952
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    20
 *
ds@1952
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    28
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    29
 *
ds@1952
    30
 * Version: $Id$
ds@1952
    31
 */
ds@1952
    32
ds@1952
    33
ds@1952
    34
#if defined _sorting_included
ds@1952
    35
  #endinput
ds@1952
    36
#endif
ds@1952
    37
#define _sorting_included
ds@1952
    38
ds@1952
    39
/**
ds@1952
    40
 * Contains sorting orders.
ds@1952
    41
 */
ds@1952
    42
enum SortOrder
ds@1952
    43
{
ds@1952
    44
	Sort_Ascending = 0,		/**< Ascending order */
ds@1952
    45
	Sort_Descending = 1,	/**< Descending order */
ds@1952
    46
	Sort_Random = 2			/**< Random order */
ds@1952
    47
};
ds@1952
    48
ds@1952
    49
/**
ds@1952
    50
 * Data types for ADT Array Sorts
ds@1952
    51
 */
ds@1952
    52
enum SortType
ds@1952
    53
{
ds@1952
    54
 	Sort_Integer = 0,
ds@1952
    55
 	Sort_Float,
ds@1952
    56
 	Sort_String,
ds@1952
    57
};
ds@1952
    58
ds@1952
    59
/**
ds@1952
    60
 * Sorts an array of integers.
ds@1952
    61
 *
ds@1952
    62
 * @param array			Array of integers to sort in-place.
ds@1952
    63
 * @param array_size	Size of the array.
ds@1952
    64
 * @param order			Sorting order to use.
ds@1952
    65
 * @noreturn
ds@1952
    66
 */
ds@1952
    67
native SortIntegers(array[], array_size, SortOrder:order = Sort_Ascending);
ds@1952
    68
ds@1952
    69
/**
ds@1952
    70
 * Sorts an array of float point numbers.
ds@1952
    71
 *
ds@1952
    72
 * @param array			Array of floating point numbers to sort in-place.
ds@1952
    73
 * @param array_size	Size of the array.
ds@1952
    74
 * @param order			Sorting order to use.
ds@1952
    75
 * @noreturn
ds@1952
    76
 */
ds@1952
    77
native SortFloats(Float:array[], array_size, SortOrder:order = Sort_Ascending);
ds@1952
    78
ds@1952
    79
/**
ds@1952
    80
 * Sorts an array of strings.
ds@1952
    81
 *
ds@1952
    82
 * @param array			Array of strings to sort in-place.
ds@1952
    83
 * @param array_size	Size of the array.
ds@1952
    84
 * @param order			Sorting order to use.
ds@1952
    85
 * @noreturn
ds@1952
    86
 */
ds@1952
    87
native SortStrings(String:array[][], num_strings, SortOrder:order = Sort_Ascending);
ds@1952
    88
ds@1952
    89
/**
ds@1952
    90
 * Sort comparison function for 1D array elements.
ds@1952
    91
 * @note You may need to use explicit tags in order to use data properly.
ds@1952
    92
 *
ds@1952
    93
 * @param elem1			First element to compare.
ds@1952
    94
 * @param elem2			Second element to compare.
ds@1952
    95
 * @param array			Array that is being sorted (order is undefined).
ds@1952
    96
 * @param hndl			Handle optionally passed in while sorting.
ds@1952
    97
 * @return				-1 if first should go before second
ds@1952
    98
 *						0 if first is equal to second
ds@1952
    99
 *						1 if first should go after second
ds@1952
   100
 */
ds@1952
   101
functag SortFunc1D public(elem1, elem2, const array[], Handle:hndl);
ds@1952
   102
ds@1952
   103
/** 
ds@1952
   104
 * Sorts a custom 1D array.  You must pass in a comparison function.
ds@1952
   105
 *
ds@1952
   106
 * @param array			Array to sort.
ds@1952
   107
 * @param array_size	Size of the array to sort.
ds@1952
   108
 * @param sortfunc		Sort function.
ds@1952
   109
 * @param hndl			Optional Handle to pass through the comparison calls.
ds@1952
   110
 * @noreturn
ds@1952
   111
 */
ds@1952
   112
native SortCustom1D(array[], array_size, SortFunc1D:sortfunc, Handle:hndl=INVALID_HANDLE);
ds@1952
   113
ds@1952
   114
/**
ds@1952
   115
 * Sort comparison function for 2D array elements (sub-arrays).
ds@1952
   116
 * @note You may need to use explicit tags in order to use data properly.
ds@1952
   117
 *
ds@1952
   118
 * @param elem1			First array to compare.
ds@1952
   119
 * @param elem2			Second array to compare.
ds@1952
   120
 * @param array			Array that is being sorted (order is undefined).
ds@1952
   121
 * @param hndl			Handle optionally passed in while sorting.
ds@1952
   122
 * @return				-1 if first should go before second
ds@1952
   123
 *						0 if first is equal to second
ds@1952
   124
 *						1 if first should go after second
ds@1952
   125
 */
ds@1952
   126
funcenum SortFunc2D
ds@1952
   127
{
ds@1952
   128
	public(array[], array[], const array[][], Handle:hndl),
ds@1952
   129
	public(String:array[], String:array[], const String:array[][], Handle:hndl),
ds@1952
   130
};
ds@1952
   131
ds@1952
   132
/** 
ds@1952
   133
 * Sorts a custom 2D array.  You must pass in a comparison function.
ds@1952
   134
 *
ds@1952
   135
 * @param array			Array to sort.
ds@1952
   136
 * @param array_size	Size of the major array to sort (first index, outermost).
ds@1952
   137
 * @param sortfunc		Sort comparison function to use.
ds@1952
   138
 * @param hndl			Optional Handle to pass through the comparison calls.
ds@1952
   139
 * @noreturn
ds@1952
   140
 */
ds@1952
   141
native SortCustom2D(array[][], array_size, SortFunc2D:sortfunc, Handle:hndl=INVALID_HANDLE);
ds@1952
   142
ds@1952
   143
/**
ds@1952
   144
 * Sort an ADT Array. Specify the type as Integer, Float, or String.
ds@1952
   145
 *
ds@1952
   146
 * @param array			Array Handle to sort
ds@1952
   147
 * @param order			Sort order to use, same as other sorts.
ds@1952
   148
 * @param type			Data type stored in the ADT Array
ds@1952
   149
 * @noreturn
ds@1952
   150
 */
ds@1952
   151
native SortADTArray(Handle:array, SortOrder:order, SortType:type);
ds@1952
   152
ds@1952
   153
/**
ds@1952
   154
 * Sort comparison function for ADT Array elements. Function provides you with
ds@1952
   155
 * indexes currently being sorted, use ADT Array functions to retrieve the
ds@1952
   156
 * index values and compare.
ds@1952
   157
 *
ds@1952
   158
 * @param index1		First index to compare.
ds@1952
   159
 * @param index2		Second index to compare.
ds@1952
   160
 * @param array			Array that is being sorted (order is undefined).
ds@1952
   161
 * @param hndl			Handle optionally passed in while sorting.
ds@1952
   162
 * @return				-1 if first should go before second
ds@1952
   163
 *					0 if first is equal to second
ds@1952
   164
 *					1 if first should go after second
ds@1952
   165
 */
ds@1952
   166
functag SortFuncADTArray public(index1, index2, Handle:array, Handle:hndl);
ds@1952
   167
ds@1952
   168
/**
ds@1952
   169
 * Custom sorts an ADT Array. You must pass in a comparison function.
ds@1952
   170
 *
ds@1952
   171
 * @param array			Array Handle to sort
ds@1952
   172
 * @param sortfunc		Sort comparision function to use
ds@1952
   173
 * @param hndl			Optional Handle to pass through the comparison calls.
ds@1952
   174
 * @noreturn
ds@1952
   175
 */
ds@1952
   176
native SortADTArrayCustom(Handle:array, SortFuncADTArray:sortfunc, Handle:hndl=INVALID_HANDLE);