plugins/include/sorting.inc
author David Anderson <dvander@alliedmods.net>
Sun Dec 02 04:31:28 2007 +0000 (2007-12-02)
changeset 1741 72857b1fc5d3
parent 1738 cb3be0b31d99
child 1917 3b9449e1cb98
permissions -rw-r--r--
fixed the build
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     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.
    12  * 
    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
    16  * details.
    17  *
    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/>.
    20  *
    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>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 
    34 #if defined _sorting_included
    35   #endinput
    36 #endif
    37 #define _sorting_included
    38 
    39 /**
    40  * Contains sorting orders.
    41  */
    42 enum SortOrder
    43 {
    44 	Sort_Ascending = 0,		/**< Ascending order */
    45 	Sort_Descending = 1,	/**< Descending order */
    46 };
    47 
    48 /**
    49  * Data types for ADT Array Sorts
    50  */
    51 enum SortType
    52 {
    53  	Sort_Integer = 0,
    54  	Sort_Float,
    55  	Sort_String,
    56 };
    57 
    58 /**
    59  * Sorts an array of integers.
    60  *
    61  * @param array			Array of integers to sort in-place.
    62  * @param array_size	Size of the array.
    63  * @param order			Sorting order to use.
    64  * @noreturn
    65  */
    66 native SortIntegers(array[], array_size, SortOrder:order = Sort_Ascending);
    67 
    68 /**
    69  * Sorts an array of float point numbers.
    70  *
    71  * @param array			Array of floating point numbers to sort in-place.
    72  * @param array_size	Size of the array.
    73  * @param order			Sorting order to use.
    74  * @noreturn
    75  */
    76 native SortFloats(Float:array[], array_size, SortOrder:order = Sort_Ascending);
    77 
    78 /**
    79  * Sorts an array of strings.
    80  *
    81  * @param array			Array of strings to sort in-place.
    82  * @param array_size	Size of the array.
    83  * @param order			Sorting order to use.
    84  * @noreturn
    85  */
    86 native SortStrings(String:array[][], num_strings, SortOrder:order = Sort_Ascending);
    87 
    88 /**
    89  * Sort comparison function for 1D array elements.
    90  * @note You may need to use explicit tags in order to use data properly.
    91  *
    92  * @param elem1			First element to compare.
    93  * @param elem2			Second element to compare.
    94  * @param array			Array that is being sorted (order is undefined).
    95  * @param hndl			Handle optionally passed in while sorting.
    96  * @return				-1 if first should go before second
    97  *						0 if first is equal to second
    98  *						1 if first should go after second
    99  */
   100 functag SortFunc1D public(elem1, elem2, const array[], Handle:hndl);
   101 
   102 /** 
   103  * Sorts a custom 1D array.  You must pass in a comparison function.
   104  *
   105  * @param array			Array to sort.
   106  * @param array_size	Size of the array to sort.
   107  * @param sortfunc		Sort function.
   108  * @param hndl			Optional Handle to pass through the comparison calls.
   109  * @noreturn
   110  */
   111 native SortCustom1D(array[], array_size, SortFunc1D:sortfunc, Handle:hndl=INVALID_HANDLE);
   112 
   113 /**
   114  * Sort comparison function for 2D array elements (sub-arrays).
   115  * @note You may need to use explicit tags in order to use data properly.
   116  *
   117  * @param elem1			First array to compare.
   118  * @param elem2			Second array to compare.
   119  * @param array			Array that is being sorted (order is undefined).
   120  * @param hndl			Handle optionally passed in while sorting.
   121  * @return				-1 if first should go before second
   122  *						0 if first is equal to second
   123  *						1 if first should go after second
   124  */
   125 funcenum SortFunc2D
   126 {
   127 	public(array[], array[], const array[][], Handle:hndl),
   128 	public(String:array[], String:array[], const String:array[][], Handle:hndl),
   129 };
   130 
   131 /** 
   132  * Sorts a custom 2D array.  You must pass in a comparison function.
   133  *
   134  * @param array			Array to sort.
   135  * @param array_size	Size of the major array to sort (first index, outermost).
   136  * @param sortfunc		Sort comparison function to use.
   137  * @param hndl			Optional Handle to pass through the comparison calls.
   138  * @noreturn
   139  */
   140 native SortCustom2D(array[][], array_size, SortFunc2D:sortfunc, Handle:hndl=INVALID_HANDLE);
   141 
   142 /**
   143  * Sort an ADT Array. Specify the type as Integer, Float, or String.
   144  *
   145  * @param array			Array Handle to sort
   146  * @param order			Sort order to use, same as other sorts.
   147  * @param type			Data type stored in the ADT Array
   148  * @noreturn
   149  */
   150 native SortADTArray(Handle:array, SortOrder:order, SortType:type);
   151 
   152 /**
   153  * Sort comparison function for ADT Array elements. Function provides you with
   154  * indexes currently being sorted, use ADT Array functions to retrieve the
   155  * index values and compare.
   156  *
   157  * @param index1		First index to compare.
   158  * @param index2		Second index to compare.
   159  * @param array			Array that is being sorted (order is undefined).
   160  * @param hndl			Handle optionally passed in while sorting.
   161  * @return				-1 if first should go before second
   162  *					0 if first is equal to second
   163  *					1 if first should go after second
   164  */
   165 functag SortFuncADTArray public(index1, index2, Handle:array, Handle:hndl);
   166 
   167 /**
   168  * Custom sorts an ADT Array. You must pass in a comparison function.
   169  *
   170  * @param array			Array Handle to sort
   171  * @param sortfunc		Sort comparision function to use
   172  * @param hndl			Optional Handle to pass through the comparison calls.
   173  * @noreturn
   174  */
   175 native SortADTArrayCustom(Handle:array, SortFuncADTArray:sortfunc, Handle:hndl=INVALID_HANDLE);