plugins/include/sorting.inc
author Borja Ferrer <faluco@alliedmods.net>
Mon Oct 01 21:20:30 2007 +0000 (2007-10-01)
changeset 1515 3e112467aacd
parent 1330 ab94316bb52b
child 1701 9cf7f48da853
permissions -rw-r--r--
fixed amb991, dispatchkeyvalue natives had wrong offsets
dvander@535
     1
/**
dvander@535
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@535
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@1330
     5
 * =============================================================================
ds@1330
     6
 *
ds@1330
     7
 * This file is part of the SourceMod/SourcePawn SDK.
dvander@535
     8
 *
ds@1330
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    11
 * Free Software Foundation.
ds@1330
    12
 * 
ds@1330
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    16
 * details.
ds@1330
    17
 *
ds@1330
    18
 * You should have received a copy of the GNU General Public License along with
ds@1330
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1330
    20
 *
ds@1330
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    28
 * or <http://www.sourcemod.net/license.php>.
dvander@535
    29
 *
dvander@535
    30
 * Version: $Id$
dvander@535
    31
 */
dvander@535
    32
dvander@535
    33
dvander@535
    34
#if defined _sorting_included
dvander@535
    35
  #endinput
dvander@535
    36
#endif
dvander@535
    37
#define _sorting_included
dvander@535
    38
dvander@535
    39
/**
dvander@619
    40
 * Contains sorting orders.
dvander@535
    41
 */
dvander@535
    42
enum SortOrder
dvander@535
    43
{
dvander@535
    44
	Sort_Ascending = 0,		/**< Ascending order */
dvander@535
    45
	Sort_Descending = 1,	/**< Descending order */
dvander@535
    46
};
dvander@535
    47
dvander@535
    48
/**
dvander@535
    49
 * Sorts an array of integers.
dvander@535
    50
 *
dvander@535
    51
 * @param array			Array of integers to sort in-place.
dvander@535
    52
 * @param array_size	Size of the array.
dvander@535
    53
 * @param order			Sorting order to use.
dvander@535
    54
 * @noreturn
dvander@535
    55
 */
dvander@535
    56
native SortIntegers(array[], array_size, SortOrder:order = Sort_Ascending);
dvander@535
    57
dvander@535
    58
/**
dvander@535
    59
 * Sorts an array of float point numbers.
dvander@535
    60
 *
dvander@535
    61
 * @param array			Array of floating point numbers to sort in-place.
dvander@535
    62
 * @param array_size	Size of the array.
dvander@535
    63
 * @param order			Sorting order to use.
dvander@535
    64
 * @noreturn
dvander@535
    65
 */
dvander@535
    66
native SortFloats(Float:array[], array_size, SortOrder:order = Sort_Ascending);
dvander@535
    67
dvander@535
    68
/**
dvander@535
    69
 * Sorts an array of strings.
dvander@535
    70
 *
dvander@535
    71
 * @param array			Array of strings to sort in-place.
dvander@535
    72
 * @param array_size	Size of the array.
dvander@535
    73
 * @param order			Sorting order to use.
dvander@535
    74
 * @noreturn
dvander@535
    75
 */
dvander@535
    76
native SortStrings(String:array[][], num_strings, SortOrder:order = Sort_Ascending);
dvander@535
    77
dvander@535
    78
/**
dvander@535
    79
 * Sort comparison function for 1D array elements.
dvander@535
    80
 * @note You may need to use explicit tags in order to use data properly.
dvander@535
    81
 *
dvander@535
    82
 * @param elem1			First element to compare.
dvander@535
    83
 * @param elem2			Second element to compare.
dvander@535
    84
 * @param array			Array that is being sorted (order is undefined).
dvander@535
    85
 * @param hndl			Handle optionally passed in while sorting.
dvander@535
    86
 * @return				-1 if first should go before second
dvander@535
    87
 *						0 if first is equal to second
dvander@535
    88
 *						1 if first should go after second
dvander@535
    89
 */
dvander@535
    90
functag SortFunc1D public(elem1, elem2, const array[], Handle:hndl);
dvander@535
    91
dvander@535
    92
/** 
dvander@535
    93
 * Sorts a custom 1D array.  You must pass in a comparison function.
dvander@535
    94
 *
dvander@535
    95
 * @param array			Array to sort.
dvander@535
    96
 * @param array_size	Size of the array to sort.
dvander@535
    97
 * @param sortfunc		Sort function.
dvander@535
    98
 * @param hndl			Optional Handle to pass through the comparison calls.
dvander@535
    99
 * @noreturn
dvander@535
   100
 */
dvander@535
   101
native SortCustom1D(array[], array_size, SortFunc1D:sortfunc, Handle:hndl=INVALID_HANDLE);
dvander@535
   102
dvander@535
   103
/**
dvander@535
   104
 * Sort comparison function for 2D array elements (sub-arrays).
dvander@535
   105
 * @note You may need to use explicit tags in order to use data properly.
dvander@535
   106
 *
dvander@535
   107
 * @param elem1			First array to compare.
dvander@535
   108
 * @param elem2			Second array to compare.
dvander@535
   109
 * @param array			Array that is being sorted (order is undefined).
dvander@535
   110
 * @param hndl			Handle optionally passed in while sorting.
dvander@535
   111
 * @return				-1 if first should go before second
dvander@535
   112
 *						0 if first is equal to second
dvander@535
   113
 *						1 if first should go after second
dvander@535
   114
 */
dvander@535
   115
funcenum SortFunc2D
dvander@535
   116
{
dvander@535
   117
	public(array[], array[], const array[][], Handle:hndl),
dvander@535
   118
	public(String:array[], String:array[], const String:array[][], Handle:hndl),
dvander@535
   119
};
dvander@535
   120
dvander@535
   121
/** 
dvander@535
   122
 * Sorts a custom 2D array.  You must pass in a comparison function.
dvander@535
   123
 *
dvander@535
   124
 * @param array			Array to sort.
dvander@535
   125
 * @param array_size	Size of the major array to sort (first index, outermost).
dvander@535
   126
 * @param sortfunc		Sort comparison function to use.
dvander@535
   127
 * @param hndl			Optional Handle to pass through the comparison calls.
dvander@535
   128
 * @noreturn
dvander@535
   129
 */
ds@634
   130
native SortCustom2D(array[][], array_size, SortFunc2D:sortfunc, Handle:hndl=INVALID_HANDLE);