-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_seq.h
173 lines (138 loc) · 3.86 KB
/
select_seq.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* tab:8
*
* select_seq.h - Sequential Selection Algorithm
*
*
* "Copyright (c) 1996 The Regents of the University of Maryland.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice and the following
* two paragraphs appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF MARYLAND BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* MARYLAND HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF MARYLAND SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF MARYLAND HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Authors: David A. Bader <dbader@umiacs.umd.edu>
* Joseph F. Ja'Ja' <joseph@umiacs.umd.edu>
* Institute for Advanced Computer Studies
* Department of Electrical Engineering
* AV Williams Building
* College Park, MD 20742
*
* Version: 1.0
* Creation Date: February 6, 1996
* Filename: select_seq.h
* History:
*/
#ifndef _SELECT_SEQ_H
#define _SELECT_SEQ_H
#include "ImageU.h"
#define partition(a,b,c) partition_i(a,b,c)
#define partition_unk_piv(a,b,c) partition_unk_piv_i(a,b,c)
int partition_unk_piv_i(int *, int, int);
int partition_unk_piv_d(double *, int, double);
#define select_mom(a,b,c) select_mom_i(a,b,c)
int select_mom_i(int *, int, int);
double select_mom_d(double *, int, int);
#define select_mom_alloc(a,b,c,d) select_mom_alloc_i(a,b,c,d)
int select_mom_alloc_i(int *, int, int, int *);
double select_mom_alloc_d(double *, int, int, double *);
_INLINE int partition_i(int *A, int n, int piv) {
#define DATA_TYPE int
register int done = 0;
register DATA_TYPE
*d1, *d2,
item;
d1 = A;
d2 = A + n-1;
do {
while (*d1 <= piv) d1++;
while (*d2 > piv) d2--;
if (d1 < d2) {
item = *d1;
*d1 = *d2;
*d2 = item;
}
else done = 1;
}
while (!done);
return((d2-A) + 1);
#undef DATA_TYPE
}
_INLINE int partition_d(double *A, int n, double piv) {
#define DATA_TYPE double
register int done = 0;
register DATA_TYPE
*d1, *d2,
item;
d1 = A;
d2 = A + n-1;
do {
while (*d1 <= piv) d1++;
while (*d2 > piv) d2--;
if (d1 < d2) {
item = *d1;
*d1 = *d2;
*d2 = item;
}
else done = 1;
}
while (!done);
return((d2-A) + 1);
#undef DATA_TYPE
}
_INLINE int partition_unk_piv_i(int *A, int n, int piv) {
#define DATA_TYPE int
register int done = 0;
register DATA_TYPE
*d1, *d2,
item;
d1 = A;
d2 = A + n-1;
do {
while ((d1<=d2)&&(*d1 <= piv)) d1++;
while ((d2>=d1)&&(*d2 > piv)) d2--;
if (d1 < d2) {
item = *d1;
*d1 = *d2;
*d2 = item;
}
else done = 1;
}
while (!done);
return ((d2-A) + 1);
#undef DATA_TYPE
}
_INLINE int partition_unk_piv_d(double *A, int n, double piv) {
#define DATA_TYPE double
register int done = 0;
register DATA_TYPE
*d1, *d2,
item;
d1 = A;
d2 = A + n-1;
do {
while ((d1<=d2)&&(*d1 <= piv)) d1++;
while ((d2>=d1)&&(*d2 > piv)) d2--;
if (d1 < d2) {
item = *d1;
*d1 = *d2;
*d2 = item;
}
else done = 1;
}
while (!done);
return((d2-A) + 1);
#undef DATA_TYPE
}
#endif