dvander@535: /**
dvander@535: * vim: set ts=4 :
ds@1330: * =============================================================================
dvander@535: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
ds@1330: * =============================================================================
ds@1330: *
ds@1330: * This file is part of the SourceMod/SourcePawn SDK.
dvander@535: *
ds@1330: * This program is free software; you can redistribute it and/or modify it under
ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330: * Free Software Foundation.
ds@1330: *
ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1330: * details.
ds@1330: *
ds@1330: * You should have received a copy of the GNU General Public License along with
ds@1330: * this program. If not, see .
ds@1330: *
ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1330: * this exception to all derivative works. AlliedModders LLC defines further
ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330: * or .
dvander@535: *
dvander@535: * Version: $Id$
dvander@535: */
dvander@535:
dvander@535:
dvander@535: #if defined _sorting_included
dvander@535: #endinput
dvander@535: #endif
dvander@535: #define _sorting_included
dvander@535:
dvander@535: /**
dvander@619: * Contains sorting orders.
dvander@535: */
dvander@535: enum SortOrder
dvander@535: {
dvander@535: Sort_Ascending = 0, /**< Ascending order */
dvander@535: Sort_Descending = 1, /**< Descending order */
dvander@535: };
dvander@535:
dvander@535: /**
dvander@535: * Sorts an array of integers.
dvander@535: *
dvander@535: * @param array Array of integers to sort in-place.
dvander@535: * @param array_size Size of the array.
dvander@535: * @param order Sorting order to use.
dvander@535: * @noreturn
dvander@535: */
dvander@535: native SortIntegers(array[], array_size, SortOrder:order = Sort_Ascending);
dvander@535:
dvander@535: /**
dvander@535: * Sorts an array of float point numbers.
dvander@535: *
dvander@535: * @param array Array of floating point numbers to sort in-place.
dvander@535: * @param array_size Size of the array.
dvander@535: * @param order Sorting order to use.
dvander@535: * @noreturn
dvander@535: */
dvander@535: native SortFloats(Float:array[], array_size, SortOrder:order = Sort_Ascending);
dvander@535:
dvander@535: /**
dvander@535: * Sorts an array of strings.
dvander@535: *
dvander@535: * @param array Array of strings to sort in-place.
dvander@535: * @param array_size Size of the array.
dvander@535: * @param order Sorting order to use.
dvander@535: * @noreturn
dvander@535: */
dvander@535: native SortStrings(String:array[][], num_strings, SortOrder:order = Sort_Ascending);
dvander@535:
dvander@535: /**
dvander@535: * Sort comparison function for 1D array elements.
dvander@535: * @note You may need to use explicit tags in order to use data properly.
dvander@535: *
dvander@535: * @param elem1 First element to compare.
dvander@535: * @param elem2 Second element to compare.
dvander@535: * @param array Array that is being sorted (order is undefined).
dvander@535: * @param hndl Handle optionally passed in while sorting.
dvander@535: * @return -1 if first should go before second
dvander@535: * 0 if first is equal to second
dvander@535: * 1 if first should go after second
dvander@535: */
dvander@535: functag SortFunc1D public(elem1, elem2, const array[], Handle:hndl);
dvander@535:
dvander@535: /**
dvander@535: * Sorts a custom 1D array. You must pass in a comparison function.
dvander@535: *
dvander@535: * @param array Array to sort.
dvander@535: * @param array_size Size of the array to sort.
dvander@535: * @param sortfunc Sort function.
dvander@535: * @param hndl Optional Handle to pass through the comparison calls.
dvander@535: * @noreturn
dvander@535: */
dvander@535: native SortCustom1D(array[], array_size, SortFunc1D:sortfunc, Handle:hndl=INVALID_HANDLE);
dvander@535:
dvander@535: /**
dvander@535: * Sort comparison function for 2D array elements (sub-arrays).
dvander@535: * @note You may need to use explicit tags in order to use data properly.
dvander@535: *
dvander@535: * @param elem1 First array to compare.
dvander@535: * @param elem2 Second array to compare.
dvander@535: * @param array Array that is being sorted (order is undefined).
dvander@535: * @param hndl Handle optionally passed in while sorting.
dvander@535: * @return -1 if first should go before second
dvander@535: * 0 if first is equal to second
dvander@535: * 1 if first should go after second
dvander@535: */
dvander@535: funcenum SortFunc2D
dvander@535: {
dvander@535: public(array[], array[], const array[][], Handle:hndl),
dvander@535: public(String:array[], String:array[], const String:array[][], Handle:hndl),
dvander@535: };
dvander@535:
dvander@535: /**
dvander@535: * Sorts a custom 2D array. You must pass in a comparison function.
dvander@535: *
dvander@535: * @param array Array to sort.
dvander@535: * @param array_size Size of the major array to sort (first index, outermost).
dvander@535: * @param sortfunc Sort comparison function to use.
dvander@535: * @param hndl Optional Handle to pass through the comparison calls.
dvander@535: * @noreturn
dvander@535: */
ds@634: native SortCustom2D(array[][], array_size, SortFunc2D:sortfunc, Handle:hndl=INVALID_HANDLE);