annotate liboctave/oct-sort.h @ 6469:a848b846cb3a ss-2-9-10

[project @ 2007-03-27 18:42:11 by jwe]
author jwe
date Tue, 27 Mar 2007 18:42:11 +0000
parents 4c16f3104aa5
children 93c65f2a5668
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4851
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
1 /*
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
2 Copyright (C) 2003 David Bateman
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
3
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
4 This file is part of Octave.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
5
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
6 Octave is free software; you can redistribute it and/or modify it
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
9 later version.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
10
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
11 Octave is distributed in the hope that it will be useful, but WITHOUT
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
14 for more details.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
15
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
17 along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 4998
diff changeset
18 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 4998
diff changeset
19 02110-1301, USA.
4851
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
20
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
21 Code stolen in large part from Python's, listobject.c, which itself had
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
22 no license header. However, thanks to Tim Peters for the parts of the
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
23 code I ripped-off.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
24
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
25 As required in the Python license the short description of the changes
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
26 made are
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
27
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
28 * convert the sorting code in listobject.cc into a generic class,
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
29 replacing PyObject* with the type of the class T.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
30
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
31 The Python license is
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
32
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
33 PSF LICENSE AGREEMENT FOR PYTHON 2.3
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
34 --------------------------------------
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
35
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
36 1. This LICENSE AGREEMENT is between the Python Software Foundation
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
37 ("PSF"), and the Individual or Organization ("Licensee") accessing and
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
38 otherwise using Python 2.3 software in source or binary form and its
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
39 associated documentation.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
40
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
41 2. Subject to the terms and conditions of this License Agreement, PSF
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
42 hereby grants Licensee a nonexclusive, royalty-free, world-wide
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
43 license to reproduce, analyze, test, perform and/or display publicly,
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
44 prepare derivative works, distribute, and otherwise use Python 2.3
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
45 alone or in any derivative version, provided, however, that PSF's
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
46 License Agreement and PSF's notice of copyright, i.e., "Copyright (c)
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
47 2001, 2002, 2003 Python Software Foundation; All Rights Reserved" are
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
48 retained in Python 2.3 alone or in any derivative version prepared by
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
49 Licensee.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
50
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
51 3. In the event Licensee prepares a derivative work that is based on
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
52 or incorporates Python 2.3 or any part thereof, and wants to make
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
53 the derivative work available to others as provided herein, then
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
54 Licensee hereby agrees to include in any such work a brief summary of
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
55 the changes made to Python 2.3.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
56
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
57 4. PSF is making Python 2.3 available to Licensee on an "AS IS"
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
58 basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
59 IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
60 DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
61 FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 2.3 WILL NOT
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
62 INFRINGE ANY THIRD PARTY RIGHTS.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
63
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
64 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
65 2.3 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
66 A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 2.3,
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
67 OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
68
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
69 6. This License Agreement will automatically terminate upon a material
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
70 breach of its terms and conditions.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
71
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
72 7. Nothing in this License Agreement shall be deemed to create any
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
73 relationship of agency, partnership, or joint venture between PSF and
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
74 Licensee. This License Agreement does not grant permission to use PSF
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
75 trademarks or trade name in a trademark sense to endorse or promote
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
76 products or services of Licensee, or any third party.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
77
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
78 8. By copying, installing or otherwise using Python 2.3, Licensee
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
79 agrees to be bound by the terms and conditions of this License
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
80 Agreement.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
81 */
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
82
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
83 #if !defined (octave_sort_h)
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
84 #define octave_sort_h 1
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
85
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
86 /* The maximum number of entries in a MergeState's pending-runs stack.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
87 * This is enough to sort arrays of size up to about
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
88 * 32 * phi ** MAX_MERGE_PENDING
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
89 * where phi ~= 1.618. 85 is ridiculously large enough, good for an array
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
90 * with 2**64 elements.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
91 */
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
92 #define MAX_MERGE_PENDING 85
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
93
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
94 /* When we get into galloping mode, we stay there until both runs win less
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
95 * often than MIN_GALLOP consecutive times. See listsort.txt for more info.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
96 */
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
97 #define MIN_GALLOP 7
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
98
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
99 /* Avoid malloc for small temp arrays. */
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
100 #define MERGESTATE_TEMP_SIZE 1024
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
101
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
102 template <class T>
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
103 class
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
104 octave_sort
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
105 {
4998
3f3d6eec0a2c [project @ 2004-09-15 21:00:01 by jwe]
jwe
parents: 4911
diff changeset
106 public:
3f3d6eec0a2c [project @ 2004-09-15 21:00:01 by jwe]
jwe
parents: 4911
diff changeset
107
4851
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
108 octave_sort (void);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
109
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
110 octave_sort (bool (*comp) (T, T));
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
111
4998
3f3d6eec0a2c [project @ 2004-09-15 21:00:01 by jwe]
jwe
parents: 4911
diff changeset
112 ~octave_sort (void) { merge_freemem (); }
3f3d6eec0a2c [project @ 2004-09-15 21:00:01 by jwe]
jwe
parents: 4911
diff changeset
113
3f3d6eec0a2c [project @ 2004-09-15 21:00:01 by jwe]
jwe
parents: 4911
diff changeset
114 void set_compare (bool (*comp) (T, T)) { compare = comp; }
4851
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
115
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
116 void sort (T *v, int elements);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
117
4998
3f3d6eec0a2c [project @ 2004-09-15 21:00:01 by jwe]
jwe
parents: 4911
diff changeset
118 private:
3f3d6eec0a2c [project @ 2004-09-15 21:00:01 by jwe]
jwe
parents: 4911
diff changeset
119
4851
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
120 /* One MergeState exists on the stack per invocation of mergesort. It's just
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
121 * a convenient way to pass state around among the helper functions.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
122 *
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
123 * DGB: This isn't needed with mergesort in a class, but it doesn't slow
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
124 * things up, and it is likely to make my life easier for any potential
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
125 * backporting of changes in the Python code.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
126 */
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
127
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
128 struct s_slice
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
129 {
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
130 T *base;
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
131 int len;
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
132 };
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
133
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
134 typedef struct s_MergeState
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
135 {
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
136 /* This controls when we get *into* galloping mode. It's initialized
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
137 * to MIN_GALLOP. merge_lo and merge_hi tend to nudge it higher for
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
138 * random data, and lower for highly structured data.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
139 */
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
140 int min_gallop;
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
141
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
142 /* 'a' is temp storage to help with merges. It contains room for
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
143 * alloced entries.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
144 */
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
145 T *a; /* may point to temparray below */
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
146 int alloced;
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
147
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
148 /* A stack of n pending runs yet to be merged. Run #i starts at
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
149 * address base[i] and extends for len[i] elements. It's always
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
150 * true (so long as the indices are in bounds) that
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
151 *
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
152 * pending[i].base + pending[i].len == pending[i+1].base
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
153 *
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
154 * so we could cut the storage for this, but it's a minor amount,
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
155 * and keeping all the info explicit simplifies the code.
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
156 */
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
157 int n;
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
158 struct s_slice pending[MAX_MERGE_PENDING];
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
159 } MergeState;
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
160
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
161 bool (*compare)(T, T);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
162
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
163 MergeState ms;
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
164
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
165 void reverse_slice (T *lo, T *hi);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
166
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
167 void binarysort (T *lo, T *hi, T *start);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
168
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
169 int count_run(T *lo, T *hi, int *descending);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
170
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
171 int gallop_left(T key, T *a, int n, int hint);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
172
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
173 int gallop_right(T key, T *a, int n, int hint);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
174
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
175 void merge_init(void);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
176
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
177 void merge_freemem(void);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
178
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
179 int merge_getmem(int need);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
180
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
181 int merge_lo(T *pa, int na, T *pb, int nb);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
182
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
183 int merge_hi(T *pa, int na, T *pb, int nb);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
184
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
185 int merge_at(int i);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
186
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
187 int merge_collapse(void);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
188
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
189 int merge_force_collapse(void);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
190
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
191 int merge_compute_minrun(int n);
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
192 };
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
193
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
194 #endif
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
195
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
196 /*
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
197 ;;; Local Variables: ***
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
198 ;;; mode: C++ ***
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
199 ;;; End: ***
047ff938b0d9 [project @ 2004-04-06 17:12:14 by jwe]
jwe
parents:
diff changeset
200 */