fsort.h revision 1.11 1 /* $NetBSD: fsort.h,v 1.11 2003/08/07 11:15:54 agc Exp $ */
2
3 /*-
4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Peter McIlroy.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)fsort.h 8.1 (Berkeley) 6/6/93
35 */
36
37 #define BUFSIZE (1<<20)
38 #define MAXNUM 131072 /* low guess at average record count */
39 #define BUFFEND (EOF-2)
40 #define MAXFCT 1000
41 #define DEFLLEN 65536
42
43 /*
44 * Default (initial) and maximum size of record buffer for fsort().
45 * Note that no more than MAXNUM records are stored in the buffer,
46 * even if the buffer is not full yet.
47 */
48 #define DEFBUFSIZE (1 << 20) /* 1MB */
49 #define MAXBUFSIZE (8 << 20) /* 10 MB */
50
51 /*
52 * Number of files merge() can merge in one pass.
53 * This should be power of two so that it's possible to use this value
54 * for rouding.
55 */
56 #define MERGE_FNUM 16
57
58 extern u_char *buffer, *linebuf;
59 extern size_t bufsize, linebuf_size;
60
61 /* temp files in the stack have a file descriptor, a largest bin (maxb)
62 * which becomes the last non-empty bin (lastb) when the actual largest
63 * bin is smaller than max(half the total file, BUFSIZE)
64 * Max_o is the offset of maxb so it can be sought after the other bins
65 * are sorted.
66 */
67 struct tempfile {
68 FILE *fp;
69 u_char maxb;
70 u_char lastb;
71 off_t max_o;
72 };
73 extern struct tempfile fstack[MAXFCT];
74