-static RSET rpn_proximity (ZebraHandle zh, RSET rset1, RSET rset2,
- int ordered,
- int exclusion, int relation, int distance)
-{
- int i;
- RSFD rsfd1, rsfd2;
- int more1, more2;
- struct it_key buf1, buf2;
- RSFD rsfd_result;
- RSET result;
- rset_temp_parms parms;
- int term_index;
-
- rsfd1 = rset_open (rset1, RSETF_READ);
- more1 = rset_read (rset1, rsfd1, &buf1, &term_index);
-
- rsfd2 = rset_open (rset2, RSETF_READ);
- more2 = rset_read (rset2, rsfd2, &buf2, &term_index);
-
- parms.key_size = sizeof (struct it_key);
- parms.temp_path = res_get (zh->res, "setTmpDir");
- result = rset_create (rset_kind_temp, &parms);
- rsfd_result = rset_open (result, RSETF_WRITE);
-
- logf (LOG_DEBUG, "rpn_proximity excl=%d ord=%d rel=%d dis=%d",
- exclusion, ordered, relation, distance);
- while (more1 && more2)
- {
- int cmp = key_compare_it (&buf1, &buf2);
- if (cmp < -1)
- more1 = rset_read (rset1, rsfd1, &buf1, &term_index);
- else if (cmp > 1)
- more2 = rset_read (rset2, rsfd2, &buf2, &term_index);
- else
- {
- int sysno = buf1.sysno;
- int seqno[500];
- int n = 0;
-
- seqno[n++] = buf1.seqno;
- while ((more1 = rset_read (rset1, rsfd1, &buf1, &term_index)) &&
- sysno == buf1.sysno)
- if (n < 500)
- seqno[n++] = buf1.seqno;
- do
- {
- for (i = 0; i<n; i++)
- {
- int diff = buf2.seqno - seqno[i];
- int excl = exclusion;
- if (!ordered && diff < 0)
- diff = -diff;
- switch (relation)
- {
- case 1: /* < */
- if (diff < distance)
- excl = !excl;
- break;
- case 2: /* <= */
- if (diff <= distance)
- excl = !excl;
- break;
- case 3: /* == */
- if (diff == distance)
- excl = !excl;
- break;
- case 4: /* >= */
- if (diff >= distance)
- excl = !excl;
- break;
- case 5: /* > */
- if (diff > distance)
- excl = !excl;
- break;
- case 6: /* != */
- if (diff != distance)
- excl = !excl;
- break;
- }
- if (excl)
- rset_write (result, rsfd_result, &buf2);
- }
- } while ((more2 = rset_read (rset2, rsfd2, &buf2, &term_index)) &&
- sysno == buf2.sysno);
- }
- }
- rset_close (result, rsfd_result);
- rset_close (rset1, rsfd1);
- rset_close (rset2, rsfd2);
- return result;
-}
-
-static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no)