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