plugins/include/sorting.inc
author David Anderson <dvander@alliedmods.net>
Tue Oct 27 01:37:19 2009 -0700 (2009-10-27)
changeset 2835 c2567981deab
parent 2317 a7380514e63c
child 3967 ceafb87d38a7
permissions -rw-r--r--
Increase display lengths on custom menus (bug 3677, r=pred).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 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 	Sort_Random = 2			/**< Random order */
    47 };
    48 
    49 /**
    50  * Data types for ADT Array Sorts
    51  */
    52 enum SortType
    53 {
    54  	Sort_Integer = 0,
    55  	Sort_Float,
    56  	Sort_String,
    57 };
    58 
    59 /**
    60  * Sorts an array of integers.
    61  *
    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.
    65  * @noreturn
    66  */
    67 native SortIntegers(array[], array_size, SortOrder:order = Sort_Ascending);
    68 
    69 /**
    70  * Sorts an array of float point numbers.
    71  *
    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.
    75  * @noreturn
    76  */
    77 native SortFloats(Float:array[], array_size, SortOrder:order = Sort_Ascending);
    78 
    79 /**
    80  * Sorts an array of strings.
    81  *
    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.
    85  * @noreturn
    86  */
    87 native SortStrings(String:array[][], num_strings, SortOrder:order = Sort_Ascending);
    88 
    89 /**
    90  * Sort comparison function for 1D array elements.
    91  * @note You may need to use explicit tags in order to use data properly.
    92  *
    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
   100  */
   101 functag public SortFunc1D(elem1, elem2, const array[], Handle:hndl);
   102 
   103 /** 
   104  * Sorts a custom 1D array.  You must pass in a comparison function.
   105  *
   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.
   110  * @noreturn
   111  */
   112 native SortCustom1D(array[], array_size, SortFunc1D:sortfunc, Handle:hndl=INVALID_HANDLE);
   113 
   114 /**
   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.
   117  *
   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
   125  */
   126 funcenum SortFunc2D
   127 {
   128 	public(array[], array[], const array[][], Handle:hndl),
   129 	public(String:array[], String:array[], const String:array[][], Handle:hndl),
   130 };
   131 
   132 /** 
   133  * Sorts a custom 2D array.  You must pass in a comparison function.
   134  *
   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.
   139  * @noreturn
   140  */
   141 native SortCustom2D(array[][], array_size, SortFunc2D:sortfunc, Handle:hndl=INVALID_HANDLE);
   142 
   143 /**
   144  * Sort an ADT Array. Specify the type as Integer, Float, or String.
   145  *
   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
   149  * @noreturn
   150  */
   151 native SortADTArray(Handle:array, SortOrder:order, SortType:type);
   152 
   153 /**
   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.
   157  *
   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
   165  */
   166 functag public SortFuncADTArray(index1, index2, Handle:array, Handle:hndl);
   167 
   168 /**
   169  * Custom sorts an ADT Array. You must pass in a comparison function.
   170  *
   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.
   174  * @noreturn
   175  */
   176 native SortADTArrayCustom(Handle:array, SortFuncADTArray:sortfunc, Handle:hndl=INVALID_HANDLE);