rsspice/generated/spicelib/
zzekjsqz.rs

1//
2// GENERATED FILE
3//
4
5use super::*;
6use f2rust_std::*;
7
8const MXJRS: i32 = 200;
9const JSZIDX: i32 = 1;
10const JRCIDX: i32 = 2;
11const JTCIDX: i32 = 3;
12const JSCIDX: i32 = 4;
13const JSVBAS: i32 = 4;
14const MAXQRY: i32 = 2000;
15const MAXSEL: i32 = 50;
16const MAXTAB: i32 = 10;
17const MAXCON: i32 = 1000;
18const MXJOIN: i32 = 10;
19const MXJCON: i32 = 100;
20const MAXORD: i32 = 10;
21const MAXTOK: i32 = 500;
22const MAXQNM: i32 = 100;
23const MAXCLN: i32 = MAXQRY;
24const MAXSTR: i32 = 1024;
25
26//$Procedure  ZZEKJSQZ ( Private: EK, join row set squeeze )
27pub fn ZZEKJSQZ(JRSBAS: i32, ctx: &mut Context) -> f2rust_std::Result<()> {
28    let mut CNTLOC: i32 = 0;
29    let mut DELTA: i32 = 0;
30    let mut NSVDEL: i32 = 0;
31    let mut NRVDEL: i32 = 0;
32    let mut NEWNSV: i32 = 0;
33    let mut NR: i32 = 0;
34    let mut NRLOC: i32 = 0;
35    let mut NSV: i32 = 0;
36    let mut NSVLOC: i32 = 0;
37    let mut NTAB: i32 = 0;
38    let mut NTLOC: i32 = 0;
39    let mut PCPAIR = StackArray::<i32, 2>::new(1..=2);
40    let mut PTARG: i32 = 0;
41    let mut PTBASE: i32 = 0;
42    let mut PTRLOC: i32 = 0;
43    let mut RC: i32 = 0;
44    let mut RBASE: i32 = 0;
45    let mut ROWVEC = StackArray::<i32, 11>::new(1..=(MAXTAB + 1));
46    let mut RTARG: i32 = 0;
47    let mut RVSIZE: i32 = 0;
48    let mut SEGVEC = StackArray::<i32, 10>::new(1..=MAXTAB);
49    let mut SETBAS: i32 = 0;
50    let mut SIZE: i32 = 0;
51    let mut SIZLOC: i32 = 0;
52    let mut SVBASE: i32 = 0;
53    let mut SVSIZE: i32 = 0;
54    let mut VTARG: i32 = 0;
55
56    //
57    // SPICELIB functions
58    //
59
60    //
61    // Local variables
62    //
63
64    //
65    // Use discovery check-in.
66    //
67    //
68    // Look up the counts that are of interest:
69    //
70    //   -- The table count
71    //   -- The segment vector count
72    //   -- The join row set size
73    //
74    // Save the address of each count.
75    //
76    SIZLOC = (JRSBAS + JSZIDX);
77    NSVLOC = (JRSBAS + JSCIDX);
78    NTLOC = (JRSBAS + JTCIDX);
79
80    ZZEKSRD(SIZLOC, SIZLOC, std::slice::from_mut(&mut SIZE), ctx)?;
81    ZZEKSRD(NTLOC, NTLOC, std::slice::from_mut(&mut NTAB), ctx)?;
82    ZZEKSRD(NSVLOC, NSVLOC, std::slice::from_mut(&mut NSV), ctx)?;
83
84    if FAILED(ctx) {
85        return Ok(());
86    }
87
88    //
89    // Set the sizes of segment and row vectors.
90    //
91    SVSIZE = NTAB;
92    RVSIZE = (NTAB + 1);
93
94    //
95    // For each segment vector, obtain the row count.  Clean up after
96    // null segment vectors:  compress out the space allocated for their
97    // row vector pointers.  Keep track of the number of deletions.
98    //
99    NSVDEL = 0;
100    NRVDEL = 0;
101    VTARG = (JRSBAS + JSVBAS);
102
103    for I in 1..=NSV {
104        //
105        // The location of the row count is CNTLOC.  The row vector base
106        // pointer precedes the row count.
107        //
108        CNTLOC = ((((JRSBAS + JSVBAS) + (NSV * SVSIZE)) + (2 * (I - 1))) + 2);
109        PTRLOC = (CNTLOC - 1);
110
111        ZZEKSRD(CNTLOC, CNTLOC, std::slice::from_mut(&mut RC), ctx)?;
112
113        if (RC > 0) {
114            //
115            // The row vector set for this segment vector is non-empty.
116            // scan the rows, looking for those marked for deletion, and
117            // update the row count to reflect the number of rows that
118            // we're going to keep.
119            //
120            ZZEKSRD(PTRLOC, PTRLOC, std::slice::from_mut(&mut SETBAS), ctx)?;
121
122            NRVDEL = 0;
123
124            for J in 1..=RC {
125                RBASE = ((JRSBAS + SETBAS) + ((J - 1) * RVSIZE));
126
127                ZZEKSRD((RBASE + 1), (RBASE + 1), ROWVEC.subarray_mut(1), ctx)?;
128
129                if (ROWVEC[1] == 0) {
130                    NRVDEL = (NRVDEL + 1);
131                }
132            }
133        }
134
135        //
136        // Compute the base address of the current segment vector.
137        //
138        SVBASE = ((JRSBAS + JSVBAS) + ((I - 1) * SVSIZE));
139
140        if ((RC == 0) || (NRVDEL == RC)) {
141            //
142            // We're going to delete the current segment vector.  We'll
143            // just skip over it without advancing our target pointers.
144            //
145            NSVDEL = (NSVDEL + 1);
146        } else if (NSVDEL > 0) {
147            //
148            // We need to shift the current segment vector to its
149            // destination.
150            //
151            ZZEKSRD((SVBASE + 1), (SVBASE + SVSIZE), SEGVEC.as_slice_mut(), ctx)?;
152            ZZEKSUPD((VTARG + 1), (VTARG + SVSIZE), SEGVEC.as_slice(), ctx)?;
153
154            VTARG = (VTARG + SVSIZE);
155        } else {
156            //
157            // No segment vectors have been deleted yet.  We still must
158            // update the target in case we shift vectors later on in this
159            // loop.
160            //
161            VTARG = (VTARG + SVSIZE);
162        }
163    }
164
165    //
166    // At this point, we've compressed out the null segment vectors.
167    // The next step is to compress out the row vector counts and row
168    // vector pointers that corresponded to those segment vectors.  We
169    // also want to remove the gap between the segment vectors and the
170    // row vector pointer/count pairs.
171    //
172    // We need to do this only if we deleted some segment vectors.
173    //
174    if (NSVDEL > 0) {
175        NEWNSV = (NSV - NSVDEL);
176        PTARG = ((JRSBAS + JSVBAS) + (NEWNSV * SVSIZE));
177
178        for I in 1..=NSV {
179            //
180            // The row count is RC.
181            //
182            SVSIZE = NTAB;
183            CNTLOC = ((((JRSBAS + JSVBAS) + (NSV * SVSIZE)) + (2 * (I - 1))) + 2);
184
185            ZZEKSRD(CNTLOC, CNTLOC, std::slice::from_mut(&mut RC), ctx)?;
186
187            PTBASE = (CNTLOC - 2);
188
189            if (RC > 0) {
190                //
191                // Shift the current row vector pointer and row vector
192                // count.
193                //
194                ZZEKSRD((PTBASE + 1), (PTBASE + 2), PCPAIR.as_slice_mut(), ctx)?;
195                ZZEKSUPD((PTARG + 1), (PTARG + 2), PCPAIR.as_slice(), ctx)?;
196
197                PTARG = (PTARG + 2);
198            }
199        }
200    } else {
201        NEWNSV = NSV;
202    }
203
204    //
205    // Update the segment vector count.
206    //
207    ZZEKSUPD(NSVLOC, NSVLOC, &[NEWNSV], ctx)?;
208
209    //
210    // Remove any gaps that may exist between any of the row vectors,
211    // or between the end of the segment vector's row vector counts
212    // and base addresses and the first row vector.
213    //
214    // The initial target location is the first element following the
215    // last segment vector's row vector count.  RTARG is used as a base
216    // address; it precedes this location by 1.
217    //
218    // If we deleted any segment vectors, the segment vector pointers
219    // embedded in the row vectors must change.  Make these updates
220    // if necessary.
221    //
222    //
223    RTARG = ((JRSBAS + JSVBAS) + (NEWNSV * (SVSIZE + 2)));
224
225    for I in 1..=NEWNSV {
226        //
227        // Find the row count and row pointer for the current segment
228        // vector.
229        //
230        CNTLOC = ((((JRSBAS + JSVBAS) + (NEWNSV * SVSIZE)) + (2 * (I - 1))) + 2);
231
232        ZZEKSRD(CNTLOC, CNTLOC, std::slice::from_mut(&mut RC), ctx)?;
233
234        PTRLOC = (CNTLOC - 1);
235
236        //
237        // Get the row vector set base pointer.  After capturing the
238        // current value, we'll update this pointer to account for
239        // the shifting of row vectors.
240        //
241        ZZEKSRD(PTRLOC, PTRLOC, std::slice::from_mut(&mut SETBAS), ctx)?;
242
243        RBASE = (JRSBAS + SETBAS);
244        DELTA = (RTARG - RBASE);
245
246        ZZEKSUPD(PTRLOC, PTRLOC, &[(SETBAS + DELTA)], ctx)?;
247
248        //
249        // Shift the row vectors for the current segment vector,
250        // leaving behind the row vectors marked for deletion.
251        //
252        NRVDEL = 0;
253
254        for J in 1..=RC {
255            ZZEKSRD((RBASE + 1), (RBASE + RVSIZE), ROWVEC.as_slice_mut(), ctx)?;
256
257            if (ROWVEC[1] == 0) {
258                //
259                // This row vector is to be deleted; don't copy it.
260                //
261                RBASE = (RBASE + RVSIZE);
262                NRVDEL = (NRVDEL + 1);
263            } else {
264                //
265                // The segment vector pointer is base-relative.
266                //
267                ROWVEC[RVSIZE] = (JSVBAS + ((I - 1) * SVSIZE));
268
269                ZZEKSUPD((RTARG + 1), (RTARG + RVSIZE), ROWVEC.as_slice(), ctx)?;
270
271                RBASE = (RBASE + RVSIZE);
272                RTARG = (RTARG + RVSIZE);
273            }
274        }
275
276        //
277        // Update the row count for the current segment vector, if
278        // necessary.  Note that no segment vector will become empty
279        // as a result of the row vector deletions we've done; we
280        // already eliminated any segment vectors for which that
281        // could happen, before we entered this loop.
282        //
283        if (NRVDEL > 0) {
284            ZZEKSUPD(CNTLOC, CNTLOC, &[(RC - NRVDEL)], ctx)?;
285        }
286    }
287
288    //
289    // Update the total row count and size of the join row set.
290    //
291    NR = 0;
292
293    for I in 1..=NEWNSV {
294        CNTLOC = ((((JRSBAS + JSVBAS) + (NEWNSV * SVSIZE)) + ((I - 1) * 2)) + 2);
295
296        ZZEKSRD(CNTLOC, CNTLOC, std::slice::from_mut(&mut RC), ctx)?;
297
298        NR = (NR + RC);
299    }
300
301    NRLOC = (JRSBAS + JRCIDX);
302    SIZE = ((JSVBAS + (NEWNSV * (SVSIZE + 2))) + (NR * RVSIZE));
303
304    ZZEKSUPD(NRLOC, NRLOC, &[NR], ctx)?;
305    ZZEKSUPD(SIZLOC, SIZLOC, &[SIZE], ctx)?;
306
307    Ok(())
308}