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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const MXJRS: i32 = 200;
const JSZIDX: i32 = 1;
const JRCIDX: i32 = 2;
const JTCIDX: i32 = 3;
const JSCIDX: i32 = 4;
const JSVBAS: i32 = 4;
const MAXQRY: i32 = 2000;
const MAXSEL: i32 = 50;
const MAXTAB: i32 = 10;
const MAXCON: i32 = 1000;
const MXJOIN: i32 = 10;
const MXJCON: i32 = 100;
const MAXORD: i32 = 10;
const MAXTOK: i32 = 500;
const MAXQNM: i32 = 100;
const MAXCLN: i32 = MAXQRY;
const MAXSTR: i32 = 1024;
//$Procedure ZZEKWEED ( Private: EK, weed out redundant row vectors )
pub fn ZZEKWEED(
NJRS: &mut i32,
BASES: &mut [i32],
NROWS: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut BASES = DummyArrayMut::new(BASES, 1..);
let mut BASE: i32 = 0;
let mut CANDSV = StackArray::<i32, 10>::new(1..=MAXTAB);
let mut CRWBAS: i32 = 0;
let mut CRWVEC = StackArray::<i32, 11>::new(1..=(MAXTAB + 1));
let mut CSGBAS: i32 = 0;
let mut J: i32 = 0;
let mut LOC: i32 = 0;
let mut NCNDRV: i32 = 0;
let mut NCNDSV: i32 = 0;
let mut NDEL: i32 = 0;
let mut NPRDRV: i32 = 0;
let mut NPRDSV: i32 = 0;
let mut NR: i32 = 0;
let mut NRLOC: i32 = 0;
let mut NSVLOC: i32 = 0;
let mut NTAB: i32 = 0;
let mut PREDSV = StackArray::<i32, 10>::new(1..=MAXTAB);
let mut PRV: i32 = 0;
let mut PRWBAS: i32 = 0;
let mut PRWVEC = StackArray::<i32, 11>::new(1..=(MAXTAB + 1));
let mut PSGBAS: i32 = 0;
let mut RVSIZE: i32 = 0;
let mut SVSIZE: i32 = 0;
let mut HIT: bool = false;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Use discovery check-in.
//
if ((*NJRS < 1) || (*NJRS > MXJRS)) {
CHKIN(b"ZZEKWEED", ctx)?;
SETMSG(b"The number of join row sets in the union is #", ctx);
ERRINT(b"#", *NJRS, ctx);
SIGERR(b"SPICE(INVALIDCOUNT)", ctx)?;
CHKOUT(b"ZZEKWEED", ctx)?;
return Ok(());
}
//
// Make sure that the addressing routines are properly initialized.
//
ZZEKVSET(*NJRS, BASES.as_slice(), ctx)?;
//
// Get the segment vector and row vector sizes. The sizes that
// apply to the first join row set will suffice throughout.
//
LOC = (BASES[1] + JTCIDX);
ZZEKSRD(LOC, LOC, std::slice::from_mut(&mut NTAB), ctx)?;
SVSIZE = NTAB;
RVSIZE = (NTAB + 1);
//
// Mark redundant rows vectors for deletion. One saving grace is
// that redundant rows can never occur in the same join row set, as
// long as that join row set represents a set of rows satisfying
// a conjunction of constraints.
//
for CAND in 2..=*NJRS {
//
// We'll compare row vectors in the CAND join row set to row
// vectors in the preceding join row sets. Only row vectors
// corresponding to matching segment vectors need be compared.
// Therefore, we'll loop over the segment vectors in the CAND
// join row set, and for each such segment vector, loop over the
// segment vectors in the preceding join row sets. If a match
// occurs, we'll compare row vectors corresponding to those
// segment vectors.
//
// NCNDSV will contain the number of segment vectors in the
// `candidate' join row set.
//
NSVLOC = (BASES[CAND] + JSCIDX);
ZZEKSRD(NSVLOC, NSVLOC, std::slice::from_mut(&mut NCNDSV), ctx)?;
for CSV in 1..=NCNDSV {
//
// Look up the candidate segment vector.
//
CSGBAS = ((BASES[CAND] + JSVBAS) + ((CSV - 1) * SVSIZE));
ZZEKSRD((CSGBAS + 1), (CSGBAS + SVSIZE), CANDSV.as_slice_mut(), ctx)?;
//
// Get the row vector count and base address of the set of
// row vectors for the candidate segment vector, in case
// we need them. (Referring to the diagram of the join
// row set structure in the join row set parameter include
// file may be helpful here.)
//
BASE = (((BASES[CAND] + JSVBAS) + (NCNDSV * SVSIZE)) + ((CSV - 1) * 2));
ZZEKSRD(
(BASE + 1),
(BASE + 1),
std::slice::from_mut(&mut CRWBAS),
ctx,
)?;
CRWBAS = (CRWBAS + BASES[CAND]);
ZZEKSRD(
(BASE + 2),
(BASE + 2),
std::slice::from_mut(&mut NCNDRV),
ctx,
)?;
//
// For the current predecessor join row set, look up the
// segment vectors in that join row set and compare them to the
// candidate.
//
for PRED in 1..=(CAND - 1) {
//
// Get the count of segment vectors in the current
// predecessor join row set.
//
NSVLOC = (BASES[PRED] + JSCIDX);
ZZEKSRD(NSVLOC, NSVLOC, std::slice::from_mut(&mut NPRDSV), ctx)?;
for PSV in 1..=NPRDSV {
//
// Look up the predecessor segment vector.
//
PSGBAS = ((BASES[PRED] + JSVBAS) + ((PSV - 1) * SVSIZE));
ZZEKSRD((CSGBAS + 1), (CSGBAS + SVSIZE), PREDSV.as_slice_mut(), ctx)?;
//
// Compare the segment vectors and hope for the best.
//
if SAMEAI(CANDSV.as_slice(), PREDSV.as_slice(), SVSIZE) {
//
// Unfortunately, the two segment vectors match, so
// there's something to do. We'll have to compare
// every row vector corresponding to the candidate
// segment vector with every row vector corresponding
// to the predecessor.
//
// Get the row vector count and base address of the
// set of row vectors for the current predecessor
// segment vector. We already have on hand the
// corresponding quantities for the candidate
// segment vector.
//
BASE = (((BASES[PRED] + JSVBAS) + (NPRDSV * SVSIZE)) + ((PSV - 1) * 2));
ZZEKSRD(
(BASE + 1),
(BASE + 1),
std::slice::from_mut(&mut PRWBAS),
ctx,
)?;
PRWBAS = (PRWBAS + BASES[PRED]);
ZZEKSRD(
(BASE + 2),
(BASE + 2),
std::slice::from_mut(&mut NPRDRV),
ctx,
)?;
//
// Compare all row vectors.
//
for CRV in 1..=NCNDRV {
BASE = (CRWBAS + ((CRV - 1) * RVSIZE));
ZZEKSRD((BASE + 1), (BASE + RVSIZE), CRWVEC.as_slice_mut(), ctx)?;
PRV = 1;
HIT = false;
while ((PRV <= NPRDRV) && !HIT) {
BASE = (PRWBAS + ((PRV - 1) * RVSIZE));
ZZEKSRD((BASE + 1), (BASE + RVSIZE), PRWVEC.as_slice_mut(), ctx)?;
if SAMEAI(CRWVEC.as_slice(), PRWVEC.as_slice(), RVSIZE) {
//
// The row vectors, together with their
// qualifying segment vectors, match. The
// higher-indexed vector is considered
// redundant. To mark this vector for
// deletion, we simply zero out the first
// element of the row vector. This makes the
// row vector invalid, so it will not match
// any valid row vector we see later.
//
BASE = (CRWBAS + ((CRV - 1) * RVSIZE));
ZZEKSUPD((BASE + 1), (BASE + 1), &[0], ctx)?;
HIT = true;
} else {
PRV = (PRV + 1);
}
}
}
}
//
// We've finished comparing row vectors for a pair of
// segment vectors, if it was necessary to do so.
//
}
//
// We've compared all segment vectors in the current
// predecessor join row set with the candidate segment
// vector.
//
}
//
// We've compared all segment vectors in all predecessor join
// row sets to the current segment vector.
//
}
//
// We've compared the candidate join row set to its predecessors.
//
}
//
// We've compared all of the join row sets.
//
//
// Now, clean up the join row set union by compressing out deleted
// rows, segment vectors, and join row sets.
//
J = 1;
NDEL = 0;
for I in 1..=*NJRS {
//
// Compress the current join row set. If it ends up empty,
// expel it from the union.
//
ZZEKJSQZ(BASES[I], ctx)?;
NRLOC = (BASES[I] + JRCIDX);
ZZEKSRD(NRLOC, NRLOC, std::slice::from_mut(&mut NR), ctx)?;
if (NR == 0) {
//
// This entire join row set can be deleted from the union.
// Consider the next join row set.
//
NDEL = (NDEL + 1);
} else {
BASES[J] = BASES[I];
J = (J + 1);
}
}
*NJRS = (*NJRS - NDEL);
//
// Count the rows remaining after our clean-up operation.
//
*NROWS = 0;
for I in 1..=*NJRS {
NRLOC = (BASES[I] + JRCIDX);
ZZEKSRD(NRLOC, NRLOC, std::slice::from_mut(&mut NR), ctx)?;
*NROWS = (*NROWS + NR);
}
Ok(())
}