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
//
// 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 ZZEKJSQZ ( Private: EK, join row set squeeze )
pub fn ZZEKJSQZ(JRSBAS: i32, ctx: &mut Context) -> f2rust_std::Result<()> {
let mut CNTLOC: i32 = 0;
let mut DELTA: i32 = 0;
let mut NSVDEL: i32 = 0;
let mut NRVDEL: i32 = 0;
let mut NEWNSV: i32 = 0;
let mut NR: i32 = 0;
let mut NRLOC: i32 = 0;
let mut NSV: i32 = 0;
let mut NSVLOC: i32 = 0;
let mut NTAB: i32 = 0;
let mut NTLOC: i32 = 0;
let mut PCPAIR = StackArray::<i32, 2>::new(1..=2);
let mut PTARG: i32 = 0;
let mut PTBASE: i32 = 0;
let mut PTRLOC: i32 = 0;
let mut RC: i32 = 0;
let mut RBASE: i32 = 0;
let mut ROWVEC = StackArray::<i32, 11>::new(1..=(MAXTAB + 1));
let mut RTARG: i32 = 0;
let mut RVSIZE: i32 = 0;
let mut SEGVEC = StackArray::<i32, 10>::new(1..=MAXTAB);
let mut SETBAS: i32 = 0;
let mut SIZE: i32 = 0;
let mut SIZLOC: i32 = 0;
let mut SVBASE: i32 = 0;
let mut SVSIZE: i32 = 0;
let mut VTARG: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Use discovery check-in.
//
//
// Look up the counts that are of interest:
//
// -- The table count
// -- The segment vector count
// -- The join row set size
//
// Save the address of each count.
//
SIZLOC = (JRSBAS + JSZIDX);
NSVLOC = (JRSBAS + JSCIDX);
NTLOC = (JRSBAS + JTCIDX);
ZZEKSRD(SIZLOC, SIZLOC, std::slice::from_mut(&mut SIZE), ctx)?;
ZZEKSRD(NTLOC, NTLOC, std::slice::from_mut(&mut NTAB), ctx)?;
ZZEKSRD(NSVLOC, NSVLOC, std::slice::from_mut(&mut NSV), ctx)?;
if FAILED(ctx) {
return Ok(());
}
//
// Set the sizes of segment and row vectors.
//
SVSIZE = NTAB;
RVSIZE = (NTAB + 1);
//
// For each segment vector, obtain the row count. Clean up after
// null segment vectors: compress out the space allocated for their
// row vector pointers. Keep track of the number of deletions.
//
NSVDEL = 0;
NRVDEL = 0;
VTARG = (JRSBAS + JSVBAS);
for I in 1..=NSV {
//
// The location of the row count is CNTLOC. The row vector base
// pointer precedes the row count.
//
CNTLOC = ((((JRSBAS + JSVBAS) + (NSV * SVSIZE)) + (2 * (I - 1))) + 2);
PTRLOC = (CNTLOC - 1);
ZZEKSRD(CNTLOC, CNTLOC, std::slice::from_mut(&mut RC), ctx)?;
if (RC > 0) {
//
// The row vector set for this segment vector is non-empty.
// scan the rows, looking for those marked for deletion, and
// update the row count to reflect the number of rows that
// we're going to keep.
//
ZZEKSRD(PTRLOC, PTRLOC, std::slice::from_mut(&mut SETBAS), ctx)?;
NRVDEL = 0;
for J in 1..=RC {
RBASE = ((JRSBAS + SETBAS) + ((J - 1) * RVSIZE));
ZZEKSRD((RBASE + 1), (RBASE + 1), ROWVEC.subarray_mut(1), ctx)?;
if (ROWVEC[1] == 0) {
NRVDEL = (NRVDEL + 1);
}
}
}
//
// Compute the base address of the current segment vector.
//
SVBASE = ((JRSBAS + JSVBAS) + ((I - 1) * SVSIZE));
if ((RC == 0) || (NRVDEL == RC)) {
//
// We're going to delete the current segment vector. We'll
// just skip over it without advancing our target pointers.
//
NSVDEL = (NSVDEL + 1);
} else if (NSVDEL > 0) {
//
// We need to shift the current segment vector to its
// destination.
//
ZZEKSRD((SVBASE + 1), (SVBASE + SVSIZE), SEGVEC.as_slice_mut(), ctx)?;
ZZEKSUPD((VTARG + 1), (VTARG + SVSIZE), SEGVEC.as_slice(), ctx)?;
VTARG = (VTARG + SVSIZE);
} else {
//
// No segment vectors have been deleted yet. We still must
// update the target in case we shift vectors later on in this
// loop.
//
VTARG = (VTARG + SVSIZE);
}
}
//
// At this point, we've compressed out the null segment vectors.
// The next step is to compress out the row vector counts and row
// vector pointers that corresponded to those segment vectors. We
// also want to remove the gap between the segment vectors and the
// row vector pointer/count pairs.
//
// We need to do this only if we deleted some segment vectors.
//
if (NSVDEL > 0) {
NEWNSV = (NSV - NSVDEL);
PTARG = ((JRSBAS + JSVBAS) + (NEWNSV * SVSIZE));
for I in 1..=NSV {
//
// The row count is RC.
//
SVSIZE = NTAB;
CNTLOC = ((((JRSBAS + JSVBAS) + (NSV * SVSIZE)) + (2 * (I - 1))) + 2);
ZZEKSRD(CNTLOC, CNTLOC, std::slice::from_mut(&mut RC), ctx)?;
PTBASE = (CNTLOC - 2);
if (RC > 0) {
//
// Shift the current row vector pointer and row vector
// count.
//
ZZEKSRD((PTBASE + 1), (PTBASE + 2), PCPAIR.as_slice_mut(), ctx)?;
ZZEKSUPD((PTARG + 1), (PTARG + 2), PCPAIR.as_slice(), ctx)?;
PTARG = (PTARG + 2);
}
}
} else {
NEWNSV = NSV;
}
//
// Update the segment vector count.
//
ZZEKSUPD(NSVLOC, NSVLOC, &[NEWNSV], ctx)?;
//
// Remove any gaps that may exist between any of the row vectors,
// or between the end of the segment vector's row vector counts
// and base addresses and the first row vector.
//
// The initial target location is the first element following the
// last segment vector's row vector count. RTARG is used as a base
// address; it precedes this location by 1.
//
// If we deleted any segment vectors, the segment vector pointers
// embedded in the row vectors must change. Make these updates
// if necessary.
//
//
RTARG = ((JRSBAS + JSVBAS) + (NEWNSV * (SVSIZE + 2)));
for I in 1..=NEWNSV {
//
// Find the row count and row pointer for the current segment
// vector.
//
CNTLOC = ((((JRSBAS + JSVBAS) + (NEWNSV * SVSIZE)) + (2 * (I - 1))) + 2);
ZZEKSRD(CNTLOC, CNTLOC, std::slice::from_mut(&mut RC), ctx)?;
PTRLOC = (CNTLOC - 1);
//
// Get the row vector set base pointer. After capturing the
// current value, we'll update this pointer to account for
// the shifting of row vectors.
//
ZZEKSRD(PTRLOC, PTRLOC, std::slice::from_mut(&mut SETBAS), ctx)?;
RBASE = (JRSBAS + SETBAS);
DELTA = (RTARG - RBASE);
ZZEKSUPD(PTRLOC, PTRLOC, &[(SETBAS + DELTA)], ctx)?;
//
// Shift the row vectors for the current segment vector,
// leaving behind the row vectors marked for deletion.
//
NRVDEL = 0;
for J in 1..=RC {
ZZEKSRD((RBASE + 1), (RBASE + RVSIZE), ROWVEC.as_slice_mut(), ctx)?;
if (ROWVEC[1] == 0) {
//
// This row vector is to be deleted; don't copy it.
//
RBASE = (RBASE + RVSIZE);
NRVDEL = (NRVDEL + 1);
} else {
//
// The segment vector pointer is base-relative.
//
ROWVEC[RVSIZE] = (JSVBAS + ((I - 1) * SVSIZE));
ZZEKSUPD((RTARG + 1), (RTARG + RVSIZE), ROWVEC.as_slice(), ctx)?;
RBASE = (RBASE + RVSIZE);
RTARG = (RTARG + RVSIZE);
}
}
//
// Update the row count for the current segment vector, if
// necessary. Note that no segment vector will become empty
// as a result of the row vector deletions we've done; we
// already eliminated any segment vectors for which that
// could happen, before we entered this loop.
//
if (NRVDEL > 0) {
ZZEKSUPD(CNTLOC, CNTLOC, &[(RC - NRVDEL)], ctx)?;
}
}
//
// Update the total row count and size of the join row set.
//
NR = 0;
for I in 1..=NEWNSV {
CNTLOC = ((((JRSBAS + JSVBAS) + (NEWNSV * SVSIZE)) + ((I - 1) * 2)) + 2);
ZZEKSRD(CNTLOC, CNTLOC, std::slice::from_mut(&mut RC), ctx)?;
NR = (NR + RC);
}
NRLOC = (JRSBAS + JRCIDX);
SIZE = ((JSVBAS + (NEWNSV * (SVSIZE + 2))) + (NR * RVSIZE));
ZZEKSUPD(NRLOC, NRLOC, &[NR], ctx)?;
ZZEKSUPD(SIZLOC, SIZLOC, &[SIZE], ctx)?;
Ok(())
}