[Half-Life AMXX] / include / sorting.inc Repository:
ViewVC logotype

Annotation of /include/sorting.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : ian 1 /* Sorting functions.
2 :     *
3 :     * by the AMX Mod X Development Team
4 :     *
5 :     * This file is provided as is (no warranties).
6 :     *
7 :     * All sort functions are based off the qsort() function from the
8 :     * C standard library, which uses the Quick Sort algorithm.
9 :     * For more info, see: http://linux.wku.edu/~lamonml/algor/sort/sort.html
10 :     */
11 :    
12 :     #if defined _sorting_included
13 :     #endinput
14 :     #endif
15 :     #define _sorting_included
16 :    
17 :     enum SortMethod
18 :     {
19 :     Sort_Ascending = 0,
20 :     Sort_Descending = 1,
21 :     };
22 :    
23 :     /**
24 :     * Basic sorting functions below.
25 :     */
26 :    
27 :     native SortIntegers(array[], array_size, SortMethod:order = Sort_Ascending);
28 :    
29 :     native SortFloats(Float:array[], array_size, SortMethod:order = Sort_Ascending);
30 :    
31 :     native SortStrings(array[][], num_strings, SortMethod:order = Sort_Ascending);
32 :    
33 :     /**
34 :     * Custom sorting functions below.
35 :     */
36 :    
37 :     /**
38 :     * Sorts a custom 1D array. You must pass in a comparison function.
39 :     * The sorting algorithm then uses your comparison function to sort the data.
40 :     * The function is called in the following manner:
41 :     *
42 :     * public MySortFunc(elem1, elem2, const array[], const data[], data_size)
43 :     *
44 :     * elem1, elem2 - Current element pair being compared
45 :     * array[] - Array in its current mid-sorted state.
46 :     * data[] - Extra data array you passed to the sort func.
47 :     * data_size - Size of extra data you passed to the sort func.
48 :     *
49 :     * Your function should return:
50 :     * -1 if elem1 should go before elem2
51 :     * 0 if elem1 and elem2 are equal
52 :     * 1 if elem1 should go after elem2
53 :     * Note that the parameters after elem2 are all optional and you do not need to specify them.
54 :     */
55 :     native SortCustom1D(array[], array_size, const comparefunc[], data[]="", data_size=0);
56 :    
57 :    
58 :     /**
59 :     * Sorts a custom 2D array.
60 :     * The sorting algorithm then uses your comparison function to sort the data.
61 :     * The function is called in the following manner:
62 :     *
63 :     * public MySortFunc(const elem1[], const elem2[], const array[], data[], data_size)
64 :     *
65 :     * elem1[], elem2[] - Current element array pairs being compared
66 :     * array[][] - Array in its currently being sorted state.
67 :     * data[] - Extra data array you passed to the sort func.
68 :     * data_size - Size of extra data you passed to the sort func.
69 :     *
70 :     * Your function should return:
71 :     * -1 if elem1[] should go before elem2[]
72 :     * 0 if elem1[] and elem2 are equal[]
73 :     * 1 if elem1[] should go after elem2[]
74 :     * Note that the parameters after elem2[] are all optional and you do not need to specify them.
75 :     */
76 :     native SortCustom2D(array[][], array_size, const comparefunc[], data[]="", data_size=0);

Contact
ViewVC Help
Powered by ViewVC 1.0.4