plugins/include/sorting.inc
author David Anderson <dvander@alliedmods.net>
Sun Oct 14 21:51:30 2007 +0000 (2007-10-14)
changeset 1559 bb3fd890699d
parent 1330 ab94316bb52b
child 1701 9cf7f48da853
permissions -rw-r--r--
fixed bug in build tool
     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  * Sorts an array of integers.
    50  *
    51  * @param array			Array of integers to sort in-place.
    52  * @param array_size	Size of the array.
    53  * @param order			Sorting order to use.
    54  * @noreturn
    55  */
    56 native SortIntegers(array[], array_size, SortOrder:order = Sort_Ascending);
    57 
    58 /**
    59  * Sorts an array of float point numbers.
    60  *
    61  * @param array			Array of floating point numbers to sort in-place.
    62  * @param array_size	Size of the array.
    63  * @param order			Sorting order to use.
    64  * @noreturn
    65  */
    66 native SortFloats(Float:array[], array_size, SortOrder:order = Sort_Ascending);
    67 
    68 /**
    69  * Sorts an array of strings.
    70  *
    71  * @param array			Array of strings to sort in-place.
    72  * @param array_size	Size of the array.
    73  * @param order			Sorting order to use.
    74  * @noreturn
    75  */
    76 native SortStrings(String:array[][], num_strings, SortOrder:order = Sort_Ascending);
    77 
    78 /**
    79  * Sort comparison function for 1D array elements.
    80  * @note You may need to use explicit tags in order to use data properly.
    81  *
    82  * @param elem1			First element to compare.
    83  * @param elem2			Second element to compare.
    84  * @param array			Array that is being sorted (order is undefined).
    85  * @param hndl			Handle optionally passed in while sorting.
    86  * @return				-1 if first should go before second
    87  *						0 if first is equal to second
    88  *						1 if first should go after second
    89  */
    90 functag SortFunc1D public(elem1, elem2, const array[], Handle:hndl);
    91 
    92 /** 
    93  * Sorts a custom 1D array.  You must pass in a comparison function.
    94  *
    95  * @param array			Array to sort.
    96  * @param array_size	Size of the array to sort.
    97  * @param sortfunc		Sort function.
    98  * @param hndl			Optional Handle to pass through the comparison calls.
    99  * @noreturn
   100  */
   101 native SortCustom1D(array[], array_size, SortFunc1D:sortfunc, Handle:hndl=INVALID_HANDLE);
   102 
   103 /**
   104  * Sort comparison function for 2D array elements (sub-arrays).
   105  * @note You may need to use explicit tags in order to use data properly.
   106  *
   107  * @param elem1			First array to compare.
   108  * @param elem2			Second array to compare.
   109  * @param array			Array that is being sorted (order is undefined).
   110  * @param hndl			Handle optionally passed in while sorting.
   111  * @return				-1 if first should go before second
   112  *						0 if first is equal to second
   113  *						1 if first should go after second
   114  */
   115 funcenum SortFunc2D
   116 {
   117 	public(array[], array[], const array[][], Handle:hndl),
   118 	public(String:array[], String:array[], const String:array[][], Handle:hndl),
   119 };
   120 
   121 /** 
   122  * Sorts a custom 2D array.  You must pass in a comparison function.
   123  *
   124  * @param array			Array to sort.
   125  * @param array_size	Size of the major array to sort (first index, outermost).
   126  * @param sortfunc		Sort comparison function to use.
   127  * @param hndl			Optional Handle to pass through the comparison calls.
   128  * @noreturn
   129  */
   130 native SortCustom2D(array[][], array_size, SortFunc2D:sortfunc, Handle:hndl=INVALID_HANDLE);