Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/sorting.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1959 - (show annotations) (download) (as text)
Tue Oct 23 18:06:35 2018 UTC (6 years, 4 months ago) by amb
File MIME type: text/x-chdr
File size: 2262 byte(s)
Add extra checks to ensure that the FILESORT_VARINT integer type does
not overflow.

1 /***************************************
2 Header file for sorting function prototypes
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2012, 2018 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #ifndef SORTING_H
24 #define SORTING_H /*+ To stop multiple inclusions. +*/
25
26 #include <sys/types.h>
27
28 #include "types.h"
29
30
31 /* Constants */
32
33 /*+ The type, size and alignment of variable to store the variable length +*/
34
35 #define FILESORT_VARINT unsigned short
36
37 #define FILESORT_VARSIZE sizeof(FILESORT_VARINT)
38 #define FILESORT_MAXINT (1UL<<(8*FILESORT_VARSIZE))
39
40 #define FILESORT_VARALIGN sizeof(void*)
41
42
43 /* Macros */
44
45 /*+ A macro to use as a last resort in the comparison function to preserve
46 on the output the input order of items that compare equally. +*/
47 #define FILESORT_PRESERVE_ORDER(a,b) ( ((a)<(b)) ? -1 : +1)
48
49
50 /* Functions in sorting.c */
51
52 index_t filesort_fixed(int fd_in,int fd_out,size_t itemsize,int (*pre_sort_function)(void*,index_t),
53 int (*compare_function)(const void*,const void*),
54 int (*post_sort_function)(void*,index_t));
55
56 index_t filesort_vary(int fd_in,int fd_out,int (*pre_sort_function)(void*,index_t),
57 int (*compare_function)(const void*,const void*),
58 int (*post_sort_function)(void*,index_t));
59
60 void filesort_heapsort(void **datap,size_t nitems,int(*compare)(const void*, const void*));
61
62
63 #endif /* SORTING_H */