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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const CDOFF: i32 = 24;
const CDSCSZ: i32 = 11;
const CLSIDX: i32 = 1;
const TYPIDX: i32 = (CLSIDX + 1);
const LENIDX: i32 = (TYPIDX + 1);
const SIZIDX: i32 = (LENIDX + 1);
const NAMIDX: i32 = (SIZIDX + 1);
const IXTIDX: i32 = (NAMIDX + 1);
const IXPIDX: i32 = (IXTIDX + 1);
const NFLIDX: i32 = (IXPIDX + 1);
const ORDIDX: i32 = (NFLIDX + 1);
const METIDX: i32 = (ORDIDX + 1);
const EQ: i32 = 1;
const GE: i32 = (EQ + 1);
const GT: i32 = (GE + 1);
const LE: i32 = (GT + 1);
const LT: i32 = (LE + 1);
const NE: i32 = (LT + 1);
const LIKE: i32 = (NE + 1);
const UNLIKE: i32 = (LIKE + 1);
const ISNULL: i32 = (UNLIKE + 1);
const NOTNUL: i32 = (ISNULL + 1);
const SDSCSZ: i32 = 24;
const EKTIDX: i32 = 1;
const SNOIDX: i32 = (EKTIDX + 1);
const IMDIDX: i32 = (SNOIDX + 1);
const TNMIDX: i32 = (IMDIDX + 1);
const NCIDX: i32 = (TNMIDX + 1);
const NRIDX: i32 = (NCIDX + 1);
const RTIDX: i32 = (NRIDX + 1);
const CPTIDX: i32 = (RTIDX + 1);
const DPTIDX: i32 = (CPTIDX + 1);
const IPTIDX: i32 = (DPTIDX + 1);
const MFLIDX: i32 = (IPTIDX + 1);
const IFLIDX: i32 = (MFLIDX + 1);
const SHDIDX: i32 = (IFLIDX + 1);
const CFHIDX: i32 = (SHDIDX + 1);
const CSNIDX: i32 = (CFHIDX + 1);
const LCPIDX: i32 = (CSNIDX + 1);
const LDPIDX: i32 = (LCPIDX + 1);
const LIPIDX: i32 = (LDPIDX + 1);
const LCWIDX: i32 = (LIPIDX + 1);
const LDWIDX: i32 = (LCWIDX + 1);
const LIWIDX: i32 = (LDWIDX + 1);
const NMLIDX: i32 = (LIWIDX + 1);
const CHR: i32 = 1;
const DP: i32 = 2;
const INT: i32 = 3;
const TIME: i32 = 4;
//$Procedure ZZEKERC1 ( EK, LLE using record pointers, char, type 1 )
pub fn ZZEKERC1(
HANDLE: i32,
SEGDSC: &[i32],
COLDSC: &[i32],
CKEY: &[u8],
RECPTR: i32,
NULL: bool,
PRVIDX: &mut i32,
PRVPTR: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let SEGDSC = DummyArray::new(SEGDSC, 1..=SDSCSZ);
let COLDSC = DummyArray::new(COLDSC, 1..=CDSCSZ);
let mut BEGIN: i32 = 0;
let mut BEGPTR: i32 = 0;
let mut END: i32 = 0;
let mut ENDPTR: i32 = 0;
let mut MIDDLE: i32 = 0;
let mut MIDPTR: i32 = 0;
let mut NREC: i32 = 0;
let mut TREE: i32 = 0;
let mut TSIZE: i32 = 0;
let mut LEQ: bool = false;
//
// SPICELIB functions
//
//
// Non-SPICELIB functions
//
//
// Local variables
//
//
// Use discovery check-in.
//
if FAILED(ctx) {
return Ok(());
}
//
// Make sure the number of records in the segment is at least as
// large as the number of entries in the index: we must not look
// up any entries that don't exist!
//
TREE = COLDSC[IXPIDX];
TSIZE = ZZEKTRSZ(HANDLE, TREE, ctx)?;
NREC = SEGDSC[NRIDX];
if (TSIZE > NREC) {
CHKIN(b"ZZEKERC1", ctx)?;
SETMSG(b"Index size = # but column contains # records.", ctx);
ERRINT(b"#", TSIZE, ctx);
ERRINT(b"#", NREC, ctx);
SIGERR(b"SPICE(SIZEMISMATCH)", ctx)?;
CHKOUT(b"ZZEKERC1", ctx)?;
return Ok(());
}
//
// Handle the case of an empty tree gracefully.
//
if (TSIZE == 0) {
*PRVIDX = 0;
*PRVPTR = 0;
return Ok(());
}
//
// The algorithm used here is very like unto that used in LSTLED.
//
BEGIN = 1;
END = TSIZE;
//
// Get the record pointers BEGPTR and ENDPTR of the least and
// greatest elements in the column.
//
ZZEKTRDP(HANDLE, TREE, BEGIN, &mut BEGPTR, ctx)?;
ZZEKTRDP(HANDLE, TREE, END, &mut ENDPTR, ctx)?;
//
// Compare the input value to the smallest value in the column.
//
if ZZEKSCMP(
GT,
HANDLE,
SEGDSC.as_slice(),
COLDSC.as_slice(),
BEGPTR,
1,
CHR,
CKEY,
0.0,
0,
NULL,
ctx,
)? {
//
// The smallest entry of the column is greater than
// the input value, so none of the entries
// are less than or equal to the input value.
//
*PRVIDX = 0;
*PRVPTR = 0;
return Ok(());
} else if (ZZEKSCMP(
EQ,
HANDLE,
SEGDSC.as_slice(),
COLDSC.as_slice(),
BEGPTR,
1,
CHR,
CKEY,
0.0,
0,
NULL,
ctx,
)? && (RECPTR < BEGPTR))
{
//
// The smallest entry of the column is greater than the input
// value, based on a comparison of record pointers, so none of the
// entries are less than or equal to the input value.
//
*PRVIDX = 0;
*PRVPTR = 0;
return Ok(());
}
//
// At this point, we know the input value is greater than or equal
// to the smallest element of the column.
//
// Compare the input value to the greatest value in the column.
//
if ZZEKSCMP(
LT,
HANDLE,
SEGDSC.as_slice(),
COLDSC.as_slice(),
ENDPTR,
1,
CHR,
CKEY,
0.0,
0,
NULL,
ctx,
)? {
//
// The last element of the column is less than the
// input value.
//
*PRVIDX = TSIZE;
ZZEKTRDP(HANDLE, TREE, *PRVIDX, PRVPTR, ctx)?;
return Ok(());
} else if (ZZEKSCMP(
EQ,
HANDLE,
SEGDSC.as_slice(),
COLDSC.as_slice(),
ENDPTR,
1,
CHR,
CKEY,
0.0,
0,
NULL,
ctx,
)? && (ENDPTR <= RECPTR))
{
//
// The last element of the column is less than or equal to the
// input value, based on a comparison of record pointers.
//
*PRVIDX = TSIZE;
*PRVPTR = ENDPTR;
return Ok(());
}
//
// The input value lies between some pair of column entries.
// The value is greater than or equal to the smallest column entry
// and less than the greatest entry, according to the dictionary
// ordering we're using.
//
// Below, we'll use the variable LEQ to indicate whether the "middle"
// element in our search is less than or equal to the input value.
//
while (END > (BEGIN + 1)) {
//
// Find the record pointer of the element whose ordinal position
// is halfway between BEGIN and END.
//
MIDDLE = ((BEGIN + END) / 2);
ZZEKTRDP(HANDLE, TREE, MIDDLE, &mut MIDPTR, ctx)?;
//
// Determine the order relation between CKEY and the column
// entry at record MIDPTR.
//
if ZZEKSCMP(
LT,
HANDLE,
SEGDSC.as_slice(),
COLDSC.as_slice(),
MIDPTR,
1,
CHR,
CKEY,
0.0,
0,
NULL,
ctx,
)? {
//
// The column element at record MIDPTR is less than
// or equal to CKEY, based on data values.
//
LEQ = true;
} else if ZZEKSCMP(
EQ,
HANDLE,
SEGDSC.as_slice(),
COLDSC.as_slice(),
MIDPTR,
1,
CHR,
CKEY,
0.0,
0,
NULL,
ctx,
)? {
//
// The column entry's value matches CKEY. We must
// compare record pointers at this point.
//
LEQ = (MIDPTR <= RECPTR);
} else {
//
// The inequality of data values is strict.
//
LEQ = false;
}
if LEQ {
//
// The middle value is less than or equal to the input
// value.
//
BEGIN = MIDDLE;
} else {
END = MIDDLE;
}
//
// The input value is greater than or equal to the element
// having ordinal position BEGIN and strictly less than the
// element having ordinal position END.
//
}
*PRVIDX = BEGIN;
ZZEKTRDP(HANDLE, TREE, *PRVIDX, PRVPTR, ctx)?;
Ok(())
}