Added the scope parameter to rsets, and using it in all forwards and reads
authorHeikki Levanto <heikki@indexdata.dk>
Thu, 9 Sep 2004 10:08:04 +0000 (10:08 +0000)
committerHeikki Levanto <heikki@indexdata.dk>
Thu, 9 Sep 2004 10:08:04 +0000 (10:08 +0000)
18 files changed:
include/isamb.h
include/rset.h
index/index.h
index/invstat.c
index/trunc.c
index/zrpn.c
isamb/isamb.c
isamb/tstisamb.c
rset/rsbetween.c
rset/rsbool.c
rset/rset.c
rset/rsisamb.c
rset/rsisamc.c
rset/rsisams.c
rset/rsmultior.c
rset/rsnull.c
rset/rsprox.c
rset/rstemp.c

index bc2b1fc..93ea909 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: isamb.h,v 1.14 2004-08-23 13:06:45 adam Exp $
+/* $Id: isamb.h,v 1.15 2004-09-09 10:08:04 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -38,7 +38,7 @@ void isamb_close (ISAMB isamb);
 
 ISAMB_P isamb_merge (ISAMB b, ISAMB_P pos, ISAMC_I *data);
 
-ISAMB_PP isamb_pp_open (ISAMB isamb, ISAMB_P pos);
+ISAMB_PP isamb_pp_open (ISAMB isamb, ISAMB_P pos, int scope);
 
 int isamb_pp_read (ISAMB_PP pp, void *buf);
 
@@ -50,7 +50,7 @@ void isamb_pp_close (ISAMB_PP pp);
 
 int isamb_unlink (ISAMB b, ISAMC_P pos);
 
-ISAMB_PP isamb_pp_open_x (ISAMB isamb, ISAMB_P pos, int *level);
+ISAMB_PP isamb_pp_open_x (ISAMB isamb, ISAMB_P pos, int *level, int scope);
 void isamb_pp_close_x (ISAMB_PP pp, int *size, int *blocks);
 
 int isamb_block_info (ISAMB isamb, int cat);
index e0838e3..48dfb65 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rset.h,v 1.33 2004-09-01 15:01:32 heikki Exp $
+/* $Id: rset.h,v 1.34 2004-09-09 10:08:04 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
@@ -67,6 +67,8 @@ int rset_default_forward(RSFD rfd, void *buf,
 
 struct key_control {
     int key_size;
+    int scope;  /* default for what level we operate (book/chapter/verse) on*/
+                /* usual sysno/seqno is 2 */
     int (*cmp) (const void *p1, const void *p2);
     void (*key_logdump_txt) (int logmask, const void *p, const char *txt);
     zint (*getseq)(const void *p);
@@ -85,17 +87,35 @@ typedef struct rset
     char my_nmem; /* Should the nmem be destroyed with the rset?  */
                   /* 1 if created with it, 0 if passed from above */
     RSFD free_list; /* all rfd's allocated but not currently in use */
+    int scope;    /* On what level do we count hits and compare them? */
 } rset;
-/* rset is a "virtual base class", which will never exist on its own */
-/* all instances are rsets of some specific type, like rsisamb, or rsbool */
-/* They keep their own stuff behind the priv pointer. */
+/* rset is a "virtual base class", which will never exist on its own 
+ * all instances are rsets of some specific type, like rsisamb, or rsbool
+ * They keep their own stuff behind the priv pointer.  */
+
+/* On the old sysno-seqno type isams, the scope was hard-coded to be 2.
+ * This means that we count hits on the sysno level, and when matching an
+ * 'and', we consider it a match if both term occur within the same sysno.
+ * In more complex isams we can specify on what level we wish to do the
+ * matching and counting of hits. For example, we can have book / chapter /
+ * verse, and a seqno. Scope 2 means then "give me all verses that match",
+ * 3 would be chapters, 4 books. 
+ * The resolution tells how much of the occurences we need to return. If we 
+ * are doing some sort of proximity, we need to get the seqnos of all
+ * occurences, whereas if we are only counting hits, we do not need anything
+ * below the scope. Again 1 is seqnos, 2 sysnos (or verses), 3 books, etc.
+ */
+/* FIXME - Add a resolution, to decide on what level we want to return */
+/* hits. That can well be below scope, if we need to get seqnos for prox */
+/* or suchlike... */
 
 RSFD rfd_create_base(RSET rs);
 void rfd_delete_base(RSFD rfd);
 
 RSET rset_create_base(const struct rset_control *sel, 
                       NMEM nmem,
-                      const struct key_control *kcontrol);
+                      const struct key_control *kcontrol,
+                      int scope );
 void rset_delete(RSET rs);
 RSET rset_dup (RSET rs);
 
@@ -129,38 +149,48 @@ RSET rset_dup (RSET rs);
 #define rset_type(rs) ((rs)->control->desc)
 
 RSET rstemp_create( NMEM nmem, const struct key_control *kcontrol,
+                    int scope, 
                     const char *temp_path);
 
 RSET rsnull_create(NMEM nmem, const struct key_control *kcontrol);
 
 RSET rsbool_create_and( NMEM nmem, const struct key_control *kcontrol,
+                        int scope, 
                         RSET rset_l, RSET rset_r);
 
 RSET rsbool_create_or ( NMEM nmem, const struct key_control *kcontrol,
+                        int scope,
                         RSET rset_l, RSET rset_r);
 
 RSET rsbool_create_not( NMEM nmem, const struct key_control *kcontrol,
+                        int scope,
                         RSET rset_l, RSET rset_r);
 
 RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol,
+                        int scope, 
                         RSET rset_l, RSET rset_m, RSET rset_r, 
                         RSET rset_attr);
 
 RSET rsmultior_create( NMEM nmem, const struct key_control *kcontrol,
+                        int scope, 
                       int no_rsets, RSET* rsets);
 
 RSET rsprox_create( NMEM nmem, const struct key_control *kcontrol,
+                        int scope, 
                     int rset_no, RSET *rset,
                     int ordered, int exclusion,
                     int relation, int distance);
 
 RSET rsisamb_create( NMEM nmem, const struct key_control *kcontrol,
+                        int scope, 
                      ISAMB is, ISAMB_P pos);
 
 RSET rsisamc_create( NMEM nmem, const struct key_control *kcontrol,
+                        int scope, 
                      ISAMC is, ISAMC_P pos);
 
 RSET rsisams_create( NMEM nmem, const struct key_control *kcontrol,
+                        int scope,
                      ISAMS is, ISAMS_P pos);
 
 
index e170208..fb87c35 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: index.h,v 1.118 2004-09-09 09:07:12 adam Exp $
+/* $Id: index.h,v 1.119 2004-09-09 10:08:04 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -374,7 +374,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
 RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
                 const char *term, int length_term, const char *flags,
                  int preserve_position, int term_type, NMEM rset_nmem,
-                 const struct key_control *kctrl);
+                 const struct key_control *kctrl, int scope);
 
 void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
                       const char *db, int set,
index 5001186..ca1427d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: invstat.c,v 1.39 2004-08-06 13:14:46 adam Exp $
+/* $Id: invstat.c,v 1.40 2004-09-09 10:08:05 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -151,7 +151,7 @@ static int inv_stat_handle (char *name, const char *info, int pos,
         int size;
         int blocks;
         
-        pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level);
+        pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level, 0);
 
         while (isamb_pp_read(pp, &key))
         {
index 391a64e..4ada4dc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: trunc.c,v 1.43 2004-09-03 14:59:49 heikki Exp $
+/* $Id: trunc.c,v 1.44 2004-09-09 10:08:05 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -127,7 +127,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length,
                           const char *flags, ISAMS_P *isam_p, int from, int to,
                           int merge_chunk, int preserve_position,
                           int term_type, NMEM rset_nmem,
-                          const struct key_control *kctrl)
+                          const struct key_control *kctrl, int scope)
 {
     RSET result; 
     RSFD result_rsfd;
@@ -140,7 +140,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length,
     parms.temp_path = res_get (zi->res, "setTmpDir");
     result = rset_create (rset_kind_temp, &parms);
     */
-    result=rstemp_create( rset_nmem,kctrl,
+    result=rstemp_create( rset_nmem,kctrl, scope,
             res_get (zi->res, "setTmpDir"));
     result_rsfd = rset_open (result, RSETF_WRITE);
 
@@ -162,12 +162,14 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length,
                 rset[rscur] = rset_trunc_r (zi, term, length, flags,
                                            isam_p, i, i+i_add,
                                             merge_chunk, preserve_position,
-                                            term_type, rset_nmem, kctrl);
+                                            term_type, rset_nmem, 
+                                            kctrl, scope);
             else
                 rset[rscur] = rset_trunc_r (zi, term, length, flags,
                                             isam_p, i, to,
                                             merge_chunk, preserve_position,
-                                            term_type, rset_nmem, kctrl);
+                                            term_type, rset_nmem, 
+                                            kctrl, scope);
             rscur++;
         }
         ti = heap_init (rscur, sizeof(struct it_key), key_compare_it);
@@ -321,7 +323,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length,
         for (i = to-from; --i >= 0; )
         {
            if (isam_p[from+i]) {
-                ispt[i] = isamb_pp_open (zi->reg->isamb, isam_p[from+i]);
+                ispt[i] = isamb_pp_open (zi->reg->isamb, isam_p[from+i], scope);
                 if (isamb_pp_read (ispt[i], ti->tmpbuf))
                     heap_insert (ti, ti->tmpbuf, i);
                 else
@@ -403,7 +405,7 @@ static int isamc_trunc_cmp (const void *p1, const void *p2)
 RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no,
                 const char *term, int length, const char *flags,
                  int preserve_position, int term_type, NMEM rset_nmem,
-                 const struct key_control *kctrl)
+                 const struct key_control *kctrl, int scope)
 {
     logf (LOG_DEBUG, "rset_trunc no=%d", no);
     if (no < 1)
@@ -411,21 +413,21 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no,
     if (zi->reg->isams)
     {
         if (no == 1)
-            return rsisams_create(rset_nmem, kctrl,
-                    zi->reg->isams, *isam_p);
+            return rsisams_create(rset_nmem, kctrl, scope,
+                    zi->reg->isams, *isam_p); 
         qsort (isam_p, no, sizeof(*isam_p), isams_trunc_cmp);
     }
     else if (zi->reg->isamc)
     {
         if (no == 1)
-            return rsisamc_create(rset_nmem, kctrl,
+            return rsisamc_create(rset_nmem, kctrl, scope,
                     zi->reg->isamc, *isam_p);
         qsort (isam_p, no, sizeof(*isam_p), isamc_trunc_cmp);
     }
     else if (zi->reg->isamb)
     {
         if (no == 1)
-            return rsisamb_create(rset_nmem,kctrl,
+            return rsisamb_create(rset_nmem,kctrl, scope,
                     zi->reg->isamb, *isam_p);
         else if (no <10000 ) /* FIXME - hardcoded number */
         {
@@ -433,9 +435,9 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no,
             RSET *rsets=xmalloc(no*sizeof(RSET)); /* use nmem! */
             int i;
             for (i=0;i<no;i++)
-                rsets[i]=rsisamb_create(rset_nmem, kctrl,
+                rsets[i]=rsisamb_create(rset_nmem, kctrl, scope,
                     zi->reg->isamb, isam_p[i] );
-            r=rsmultior_create( rset_nmem, kctrl, no, rsets);
+            r=rsmultior_create( rset_nmem, kctrl, scope, no, rsets);
             xfree(rsets);
         } 
         qsort (isam_p, no, sizeof(*isam_p), isamc_trunc_cmp);
@@ -446,6 +448,6 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no,
        return rsnull_create (rset_nmem, kctrl);
     }
     return rset_trunc_r (zi, term, length, flags, isam_p, 0, no, 100,
-                         preserve_position, term_type, rset_nmem,kctrl);
+                         preserve_position, term_type, rset_nmem,kctrl,scope);
 }
 
index 07b39b4..9d14757 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zrpn.c,v 1.149 2004-09-01 15:01:32 heikki Exp $
+/* $Id: zrpn.c,v 1.150 2004-09-09 10:08:05 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -39,11 +39,13 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 static const struct key_control it_ctrl={ 
     sizeof(struct it_key),
+    2, /* we have sysnos and seqnos in this key, nothing more */
     key_compare_it, 
     key_logdump_txt,   /* FIXME  - clean up these functions */
     key_get_seq,
 };
 
+
 const struct key_control *key_it_ctrl=&it_ctrl;
 
 struct rpn_char_map_info {
@@ -896,7 +898,8 @@ static RSET term_trunc (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
     return rset_trunc (zh, grep_info->isam_p_buf,
                        grep_info->isam_p_indx, term_dst,
                        strlen(term_dst), rank_type, 1 /* preserve pos */,
-                       zapt->term->which, rset_nmem,key_it_ctrl);
+                       zapt->term->which, rset_nmem,
+                       key_it_ctrl,key_it_ctrl->scope);
 }
 
 
@@ -1401,7 +1404,7 @@ static RSET rpn_search_APT_phrase (ZebraHandle zh,
     else if (rset_no == 1)
         return (rset[0]);
     else
-        result = rsprox_create( rset_nmem, key_it_ctrl,
+        result = rsprox_create( rset_nmem, key_it_ctrl, key_it_ctrl->scope,
                        rset_no, rset,
                        1 /* ordered */, 0 /* exclusion */,
                        3 /* relation */, 1 /* distance */);
@@ -1445,7 +1448,7 @@ static RSET rpn_search_APT_or_list (ZebraHandle zh,
     grep_info_delete (&grep_info);
     if (rset_no == 0)
         return rsnull_create (rset_nmem,key_it_ctrl);  
-    return rsmultior_create(rset_nmem, key_it_ctrl,
+    return rsmultior_create(rset_nmem, key_it_ctrl,key_it_ctrl->scope,
                             rset_no, rset);
 }
 
@@ -1490,7 +1493,7 @@ static RSET rpn_search_APT_and_list (ZebraHandle zh,
     result = rset[0];
     /* FIXME - Use a proper rsmultiand */
     for (i = 1; i<rset_no; i++)
-        result= rsbool_create_and(rset_nmem,key_it_ctrl,
+        result= rsbool_create_and(rset_nmem,key_it_ctrl,key_it_ctrl->scope,
                 result, rset[i] );
     return result;
 }
@@ -1712,7 +1715,8 @@ static RSET rpn_search_APT_numeric (ZebraHandle zh,
                                     grep_info.isam_p_indx, term_dst,
                                     strlen(term_dst), rank_type,
                                     0 /* preserve position */,
-                                    zapt->term->which, rset_nmem, key_it_ctrl);
+                                    zapt->term->which, rset_nmem, 
+                                    key_it_ctrl,key_it_ctrl->scope);
         assert (rset[rset_no]);
         if (++rset_no >= (int) (sizeof(rset)/sizeof(*rset)))
             break;
@@ -1724,7 +1728,7 @@ static RSET rpn_search_APT_numeric (ZebraHandle zh,
     for (i = 1; i<rset_no; i++)
     {
         /* FIXME - Use a proper multi-and */
-        result= rsbool_create_and(rset_nmem,key_it_ctrl,
+        result= rsbool_create_and(rset_nmem,key_it_ctrl,key_it_ctrl->scope,
                 result, rset[i] );
     }
     return result;
@@ -1748,7 +1752,7 @@ static RSET rpn_search_APT_local (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
     parms.temp_path = res_get (zh->res, "setTmpDir");
     result = rset_create (rset_kind_temp, &parms);
     */
-    result = rstemp_create( rset_nmem,key_it_ctrl,
+    result = rstemp_create( rset_nmem,key_it_ctrl,key_it_ctrl->scope,
                      res_get (zh->res, "setTmpDir") );
     rsfd = rset_open (result, RSETF_WRITE);
 
@@ -1927,7 +1931,8 @@ static RSET xpath_trunc(ZebraHandle zh, NMEM stream,
              grep_info.isam_p_indx);
     rset = rset_trunc (zh, grep_info.isam_p_buf,
                        grep_info.isam_p_indx, term, strlen(term),
-                       flags, 1, term_type,rset_nmem,key_it_ctrl);
+                       flags, 1, term_type,rset_nmem,
+                       key_it_ctrl, key_it_ctrl->scope);
     grep_info_delete (&grep_info);
     return rset;
 }
@@ -2074,7 +2079,7 @@ static RSET rpn_search_xpath (ZebraHandle zh,
                 parms.printer = key_print_it;
                 rset = rset_create (rset_kind_between, &parms);
                 */
-                rset=rsbetween_create( rset_nmem,key_it_ctrl,
+                rset=rsbetween_create( rset_nmem,key_it_ctrl,key_it_ctrl->scope,
                         rset_start_tag, rset, rset_end_tag, rset_attr);
             }
             first_path = 0;
@@ -2201,13 +2206,16 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
         switch (zop->which)
         {
         case Z_Operator_and:
-            r = rsbool_create_and(rset_nmem,key_it_ctrl, rset_l,rset_r );
+            r = rsbool_create_and(rset_nmem,key_it_ctrl, key_it_ctrl->scope,
+                    rset_l,rset_r );
             break;
         case Z_Operator_or:
-            r = rsbool_create_or(rset_nmem,key_it_ctrl, rset_l,rset_r );
+            r = rsbool_create_or(rset_nmem,key_it_ctrl, key_it_ctrl->scope,
+                    rset_l,rset_r );
             break;
         case Z_Operator_and_not:
-            r = rsbool_create_not(rset_nmem,key_it_ctrl, rset_l,rset_r );
+            r = rsbool_create_not(rset_nmem,key_it_ctrl, key_it_ctrl->scope,
+                    rset_l,rset_r );
             break;
         case Z_Operator_prox:
             if (zop->u.prox->which != Z_ProximityOperator_known)
@@ -2230,7 +2238,7 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
                 
                 twosets[0] = rset_l;
                 twosets[1] = rset_r;
-                r=rsprox_create(rset_nmem,key_it_ctrl,
+                r=rsprox_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope,
                          2, twosets, 
                          *zop->u.prox->ordered,
                          (!zop->u.prox->exclusion ? 
@@ -2635,8 +2643,8 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
                            &glist[i+before].term, mterm);
         rset = rset_trunc (zh, &scan_info_array[j0].list[ptr[j0]].isam_p, 1,
                            glist[i+before].term, strlen(glist[i+before].term),
-                           NULL, 0, zapt->term->which, rset_nmem, key_it_ctrl);
-
+                           NULL, 0, zapt->term->which, rset_nmem, 
+                           key_it_ctrl,key_it_ctrl->scope);
         ptr[j0]++;
         for (j = j0+1; j<ord_no; j++)
         {
@@ -2650,16 +2658,17 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
                    rset_trunc (zh, &scan_info_array[j].list[ptr[j]].isam_p, 1,
                                glist[i+before].term,
                                strlen(glist[i+before].term), NULL, 0,
-                               zapt->term->which,rset_nmem,key_it_ctrl);
+                               zapt->term->which,rset_nmem,
+                               key_it_ctrl, key_it_ctrl->scope);
                 rset = rsbool_create_or(rset_nmem,key_it_ctrl,
-                            rset, rset2);
+                               key_it_ctrl->scope, rset, rset2);
                 /* FIXME - Use a proper multi-or */
 
                 ptr[j]++;
             }
         }
         if (limit_set)
-            rset = rsbool_create_and(rset_nmem,key_it_ctrl,
+            rset = rsbool_create_and(rset_nmem,key_it_ctrl,key_it_ctrl->scope,
                             rset, rset_dup(limit_set));
         count_set (rset, &glist[i+before].occurrences);
         rset_delete (rset);
@@ -2700,7 +2709,8 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
         rset = rset_trunc
                (zh, &scan_info_array[j0].list[before-1-ptr[j0]].isam_p, 1,
                 glist[before-1-i].term, strlen(glist[before-1-i].term),
-                NULL, 0, zapt->term->which,rset_nmem,key_it_ctrl);
+                NULL, 0, zapt->term->which,rset_nmem,
+                key_it_ctrl,key_it_ctrl->scope);
 
         ptr[j0]++;
 
@@ -2716,15 +2726,16 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
                          &scan_info_array[j].list[before-1-ptr[j]].isam_p, 1,
                                     glist[before-1-i].term,
                                     strlen(glist[before-1-i].term), NULL, 0,
-                                    zapt->term->which, rset_nmem,key_it_ctrl);
+                                    zapt->term->which, rset_nmem,
+                                    key_it_ctrl, key_it_ctrl->scope);
                 rset = rsbool_create_and(rset_nmem,key_it_ctrl,
-                            rset, rset2);
+                            key_it_ctrl->scope, rset, rset2);
                 /* FIXME - multi-and ?? */
                 ptr[j]++;
             }
         }
         if (limit_set)
-            rset = rsbool_create_and(rset_nmem,key_it_ctrl,
+            rset = rsbool_create_and(rset_nmem,key_it_ctrl,key_it_ctrl->scope,
                             rset, rset_dup(limit_set));
         count_set (rset, &glist[before-1-i].occurrences);
         rset_delete (rset);
index 9ee3596..500c10d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: isamb.c,v 1.57 2004-09-03 14:59:49 heikki Exp $
+/* $Id: isamb.c,v 1.58 2004-09-09 10:08:05 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -119,6 +119,7 @@ struct ISAMB_PP_s {
     zint skipped_nodes[ISAMB_MAX_LEVEL]; /* [0]=skipped leaves, 1=higher etc */
     zint accessed_nodes[ISAMB_MAX_LEVEL]; /* nodes we did not skip */
     struct ISAMB_block **block;
+    int scope;  /* on what level we forward */
 };
 
 
@@ -1123,7 +1124,7 @@ ISAMB_P isamb_merge (ISAMB b, ISAMC_P pos, ISAMC_I *stream)
     return pos;
 }
 
-ISAMB_PP isamb_pp_open_x (ISAMB isamb, ISAMB_P pos, int *level)
+ISAMB_PP isamb_pp_open_x (ISAMB isamb, ISAMB_P pos, int *level, int scope)
 {
     ISAMB_PP pp = xmalloc (sizeof(*pp));
     int i;
@@ -1138,6 +1139,7 @@ ISAMB_PP isamb_pp_open_x (ISAMB isamb, ISAMB_P pos, int *level)
     pp->no_blocks = 0;
     pp->skipped_numbers=0;
     pp->returned_numbers=0;
+    pp->scope=scope;
     for (i=0;i<ISAMB_MAX_LEVEL;i++)
         pp->skipped_nodes[i] = pp->accessed_nodes[i]=0;
     while (1)
@@ -1164,9 +1166,9 @@ ISAMB_PP isamb_pp_open_x (ISAMB isamb, ISAMB_P pos, int *level)
     return pp;
 }
 
-ISAMB_PP isamb_pp_open (ISAMB isamb, ISAMB_P pos)
+ISAMB_PP isamb_pp_open (ISAMB isamb, ISAMB_P pos, int scope)
 {
-    return isamb_pp_open_x (isamb, pos, 0);
+    return isamb_pp_open_x (isamb, pos, 0, scope);
 }
 
 void isamb_pp_close_x (ISAMB_PP pp, int *size, int *blocks)
@@ -1270,80 +1272,11 @@ void isamb_dump (ISAMB b, ISAMB_P pos, void (*pr)(const char *str))
     isamb_dump_r(b, pos, pr, 0);
 }
 
-#if 0
-/* Old isamb_pp_read that Adam wrote, kept as a reference in case we need to
-   debug the more complex pp_read that also forwards. May be deleted near end
-   of 2004, if it has not shown to be useful */
-
-
-int isamb_pp_read (ISAMB_PP pp, void *buf)
-{
-    char *dst = buf;
-    char *src;
-    struct ISAMB_block *p = pp->block[pp->level];
-    if (!p)
-        return 0;
-
-    while (p->offset == p->size)
-    {
-        int pos, item_len;
-        while (p->offset == p->size)
-        {
-            if (pp->level == 0)
-                return 0;
-            close_block (pp->isamb, pp->block[pp->level]);
-            pp->block[pp->level] = 0;
-            (pp->level)--;
-            p = pp->block[pp->level];
-            assert (!p->leaf);  
-        }
-        src = p->bytes + p->offset;
-        
-        decode_ptr (&src, &item_len);
-        src += item_len;
-        decode_ptr (&src, &pos);
-        
-        p->offset = src - (char*) p->bytes;
-
-        ++(pp->level);
-        
-        while (1)
-        {
-            pp->block[pp->level] = p = open_block (pp->isamb, pos);
-
-            pp->total_size += p->size;
-            pp->no_blocks++;
-            
-            if (p->leaf) 
-            {
-                break;
-            }
-            src = p->bytes + p->offset;
-            decode_ptr (&src, &pos);
-            p->offset = src - (char*) p->bytes;
-            pp->level++;
-        }
-    }
-    assert (p->offset < p->size);
-    assert (p->leaf);
-    src = p->bytes + p->offset;
-    (*pp->isamb->method->codec.code_item)(ISAMC_DECODE, p->decodeClientData,
-                                    &dst, &src);
-    p->offset = src - (char*) p->bytes;
-    /* key_logdump_txt(LOG_DEBUG,buf, "isamb_pp_read returning 1"); */
-    return 1;
-}
-
-#else
 int isamb_pp_read (ISAMB_PP pp, void *buf)
 {
     return isamb_pp_forward(pp, buf, 0);
 }
-#endif
 
-#define NEW_FORWARD 1
-
-#if NEW_FORWARD == 1
 
 static int isamb_pp_on_right_node(ISAMB_PP pp, int level, const void *untilbuf)
 { /* looks one node higher to see if we should be on this node at all */
@@ -1373,7 +1306,7 @@ static int isamb_pp_on_right_node(ISAMB_PP pp, int level, const void *untilbuf)
         (*pp->isamb->method->codec.log_item)(LOG_DEBUG,src,"on_leaf: value");
 #endif
         cmp=(*pp->isamb->method->compare_item)(untilbuf,src);
-        if (cmp<2) {
+        if (cmp<pp->scope) {  /* cmp<2 */
 #if ISAMB_DEBUG
             logf(LOG_DEBUG,"isamb_pp_on_right returning true "
                             "cmp=%d lev=%d ofs=%d",cmp,level,p->offset);
@@ -1414,11 +1347,9 @@ static int isamb_pp_read_on_leaf(ISAMB_PP pp, void *buf)
     dst=buf;
     (*pp->isamb->method->codec.decode)(p->decodeClientData,&dst, &src);
     p->offset = src - (char*) p->bytes;
-    /*
 #if ISAMB_DEBUG
     (*pp->isamb->method->codec.log_item)(LOG_DEBUG, buf, "read_on_leaf returning 1");
 #endif
-*/
     pp->returned_numbers++;
     return 1;
 } /* read_on_leaf */
@@ -1432,7 +1363,7 @@ static int isamb_pp_forward_on_leaf(ISAMB_PP pp, void *buf, const void *untilbuf
             return 0;
         /* FIXME - this is an extra function call, inline the read? */
         cmp=(*pp->isamb->method->compare_item)(untilbuf,buf);
-        if (cmp <2){  /* found a good one */
+        if (cmp <pp->scope){  /* cmp<2  found a good one */
 #if ISAMB_DEBUG
             if (skips)
                 logf(LOG_DEBUG, "isam_pp_fwd_on_leaf skipped %d items",skips);
@@ -1538,7 +1469,7 @@ static zint isamb_pp_forward_unode(ISAMB_PP pp, zint pos, const void *untilbuf)
         cmp=(*pp->isamb->method->compare_item)(untilbuf,src);
         src+=item_len;
         decode_ptr(&src,&nxtpos);
-        if (cmp<2)
+        if (cmp<pp->scope) /* cmp<2 */
         {
 #if ISAMB_DEBUG
             logf(LOG_DEBUG,"isamb_pp_forward_unode returning a hit "
@@ -1640,8 +1571,8 @@ int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf)
     struct ISAMB_block *p = pp->block[pp->level];
     assert(p->leaf);
     logf(LOG_DEBUG,"isamb_pp_forward starting "
-                   "at level %d node %d ofs=%d sz=%d u=%p",
-                    pp->level, p->pos, p->offset, p->size,untilbuf);
+                   "at level %d node %d ofs=%d sz=%d u=%p sc=%d",
+                    pp->level, p->pos, p->offset, p->size,untilbuf, scope);
 #endif
     if (untilbuf) {
         if (isamb_pp_forward_on_leaf( pp, buf, untilbuf)) {
@@ -1698,296 +1629,6 @@ int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf)
     }
 } /* isam_pp_forward (new version) */
 
-#elif NEW_FORWARD == 0
-
-int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf)
-{
-    /* pseudocode:
-     *   while 1
-     *     while at end of node
-     *       climb higher. If out, return 0
-     *     while not on a leaf (and not at its end)
-     *       decode next
-     *       if cmp
-     *         descend to node
-     *     decode next
-     *     if cmp
-     *       return 1
-     */
-     /* 
-      * The upper nodes consist of a sequence of nodenumbers and keys
-      * When opening a block,  the first node number is read in, and
-      * offset points to the first key, which is the upper limit of keys
-      * in the node just read.
-      */
-    char *dst = buf;
-    const char *src;
-    struct ISAMB_block *p = pp->block[pp->level];
-    int cmp;
-    int item_len;
-    int pos;
-    int nxtpos;
-    int descending=0; /* used to prevent a border condition error */
-    if (!p)
-        return 0;
-#if ISAMB_DEBUG
-    logf(LOG_DEBUG,"isamb_pp_forward starting [%p] p=%d",pp,p->pos);
-    
-    (*pp->isamb->method->codec.log_item)(LOG_DEBUG, untilbuf, "until");
-    (*pp->isamb->method->codec.log_item)(LOG_DEBUG, buf, "buf");
-#endif
-
-    while (1)
-    {
-        while ( (p->offset == p->size) && !descending )
-        {  /* end of this block - climb higher */
-           assert (p->offset <= p->size);
-#if ISAMB_DEBUG
-            logf(LOG_DEBUG,"isamb_pp_forward climbing from l=%d",
-                            pp->level);
-#endif
-            if (pp->level == 0)
-            {
-#if ISAMB_DEBUG
-                logf(LOG_DEBUG,"isamb_pp_forward returning 0 at root");
-#endif
-                return 0; /* at end of the root, nothing left */
-            }
-            close_block(pp->isamb, pp->block[pp->level]);
-            pp->block[pp->level]=0;
-            (pp->level)--;
-            p=pp->block[pp->level];
-#if ISAMB_DEBUG
-            logf(LOG_DEBUG,"isamb_pp_forward climbed to node %d off=%d",
-                            p->pos, p->offset);
-#endif
-            assert(!p->leaf);
-            assert(p->offset <= p->size);
-            /* skip the child we have handled */
-            if (p->offset != p->size)
-            { 
-                src = p->bytes + p->offset;
-                decode_ptr(&src, &item_len);
-#if ISAMB_DEBUG                
-               (*pp->isamb->method->codec.log_item)(LOG_DEBUG, src,
-                                              " isamb_pp_forward "
-                                              "climb skipping old key");
-#endif
-                src += item_len;
-                decode_ptr(&src,&pos);
-                p->offset = src - (char*) p->bytes;
-                break; /* even if this puts us at the end of the block, we
-                         need to descend to the last pos. UGLY coding,
-                         clean up some day */
-            }
-        }
-        if (!p->leaf)
-        { 
-            src = p->bytes + p->offset;
-            if (p->offset == p->size)
-                cmp=-2 ; /* descend to the last node, as we have
-                           no value to cmp */
-            else
-            {
-                decode_ptr(&src, &item_len);
-#if ISAMB_DEBUG
-                logf(LOG_DEBUG,"isamb_pp_forward (B) on a high node. "
-                    "ofs=%d sz=%d nxtpos=%d ",
-                        p->offset,p->size,pos);
-               (*pp->isamb->method->codec.log_item)(LOG_DEBUG, src, "");
-#endif
-                if (untilbuf)
-                    cmp=(*pp->isamb->method->compare_item)(untilbuf,src);
-                else
-                    cmp=-2;
-                src += item_len;
-                decode_ptr(&src,&nxtpos);
-            }
-            if (cmp<2)
-            { 
-#if ISAMB_DEBUG
-                logf(LOG_DEBUG,"isambb_pp_forward descending l=%d p=%d ",
-                            pp->level, pos);
-#endif
-                descending=1; /* prevent climbing for a while */
-                ++(pp->level);
-                p = open_block(pp->isamb,pos);
-                pp->block[pp->level] = p ;
-                pp->total_size += p->size;
-                (pp->accessed_nodes[pp->maxlevel - pp->level])++;
-                pp->no_blocks++;
-                if ( !p->leaf)
-                { /* block starts with a pos */
-                    src = p->bytes + p->offset;
-                    decode_ptr(&src,&pos);
-                    p->offset=src-(char*) p->bytes;
-#if ISAMB_DEBUG
-                    logf(LOG_DEBUG,"isamb_pp_forward: block %d starts with %d",
-                                    p->pos, pos);
-#endif
-                } 
-            } /* descend to the node */
-            else
-            { /* skip the node */
-                p->offset = src - (char*) p->bytes;
-                pos=nxtpos;
-                (pp->skipped_nodes[pp->maxlevel - pp->level -1])++;
-#if ISAMB_DEBUG
-                logf(LOG_DEBUG,
-                    "isamb_pp_forward: skipping block on level %d, noting "
-                    "on %d (%d)",
-                    pp->level, pp->maxlevel - pp->level-1 , 
-                    pp->skipped_nodes[pp->maxlevel - pp->level-1 ]);
-#endif
-                /* 0 is always leafs, 1 is one level above leafs etc, no
-                 * matter how high tree */
-            }
-        } /* not on a leaf */
-        else
-        { /* on a leaf */
-           if (p->offset == p->size) { 
-               descending = 0;
-           }
-           else
-           {
-               assert (p->offset < p->size);
-               src = p->bytes + p->offset;
-               dst=buf;
-               (*pp->isamb->method->codec.decode)(p->decodeClientData,
-                                               &dst, &src);
-               p->offset = src - (char*) p->bytes;
-               if (untilbuf)
-                   cmp=(*pp->isamb->method->compare_item)(untilbuf,buf);
-               else
-                   cmp=-2;
-#if ISAMB_DEBUG
-               logf(LOG_DEBUG,"isamb_pp_forward on a leaf. cmp=%d", 
-                    cmp);
-               (*pp->isamb->method->codec.log_item)(LOG_DEBUG, buf, "");
-#endif
-               if (cmp <2)
-               {
-#if ISAMB_DEBUG
-                   if (untilbuf)
-                   {
-                       (*pp->isamb->method->codec.log_item)(
-                           LOG_DEBUG, buf,  "isamb_pp_forward returning 1");
-                   }
-                   else
-                   {
-                       (*pp->isamb->method->codec.log_item)(
-                           LOG_DEBUG, buf, "isamb_pp_read returning 1 (fwd)");
-                   }
-#endif
-                   pp->returned_numbers++;
-                   return 1;
-               }
-               else
-                   pp->skipped_numbers++;
-           }
-        } /* leaf */
-    } /* main loop */
-}
-
-#elif NEW_FORWARD == 2
-
-int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilb)
-{
-    char *dst = buf;
-    const char *src;
-    struct ISAMB_block *p = pp->block[pp->level];
-    if (!p)
-        return 0;
-
-again:
-    while (p->offset == p->size)
-    {
-        int pos, item_len;
-        while (p->offset == p->size)
-        {
-            if (pp->level == 0)
-                return 0;
-            close_block (pp->isamb, pp->block[pp->level]);
-            pp->block[pp->level] = 0;
-            (pp->level)--;
-            p = pp->block[pp->level];
-            assert (!p->leaf);  
-        }
-
-       assert(!p->leaf);
-        src = p->bytes + p->offset;
-        
-        decode_ptr (&src, &item_len);
-        src += item_len;
-        decode_ptr (&src, &pos);
-        
-        p->offset = src - (char*) p->bytes;
-
-       src = p->bytes + p->offset;
-
-       while(1)
-       {
-           if (!untilb || p->offset == p->size)
-               break;
-           assert(p->offset < p->size);
-           decode_ptr (&src, &item_len);
-           if ((*pp->isamb->method->compare_item)(untilb, src) <= 1)
-               break;
-           src += item_len;
-           decode_ptr (&src, &pos);
-           p->offset = src - (char*) p->bytes;
-       }
-
-       pp->level++;
-
-        while (1)
-        {
-            pp->block[pp->level] = p = open_block (pp->isamb, pos);
-
-            pp->total_size += p->size;
-            pp->no_blocks++;
-            
-            if (p->leaf) 
-            {
-                break;
-            }
-           
-            src = p->bytes + p->offset;
-           while(1)
-           {
-               decode_ptr (&src, &pos);
-               p->offset = src - (char*) p->bytes;
-               
-               if (!untilb || p->offset == p->size)
-                   break;
-               assert(p->offset < p->size);
-               decode_ptr (&src, &item_len);
-               if ((*pp->isamb->method->compare_item)(untilb, src) <= 1)
-                   break;
-               src += item_len;
-           }
-            pp->level++;
-        }
-    }
-    assert (p->offset < p->size);
-    assert (p->leaf);
-    while(1)
-    {
-       char *dst0 = dst;
-        src = p->bytes + p->offset;
-        (*pp->isamb->method->codec.decode)(p->decodeClientData, &dst, &src);
-        p->offset = src - (char*) p->bytes;
-        if (!untilb || (*pp->isamb->method->compare_item)(untilb, dst0) <= 1)
-           break;
-       dst = dst0;
-       if (p->offset == p->size) goto again;
-    }
-    /* key_logdump_txt(LOG_DEBUG,buf, "isamb_pp_read returning 1"); */
-    return 1;
-}
-
-#endif
-
 void isamb_pp_pos( ISAMB_PP pp, double *current, double *total )
 { /* return an estimate of the current position and of the total number of */
   /* occureences in the isam tree, based on the current leaf */
index 5f471cd..e3eebbb 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: tstisamb.c,v 1.9 2004-08-23 13:06:46 adam Exp $
+/* $Id: tstisamb.c,v 1.10 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -109,7 +109,7 @@ void tst_forward(ISAMB isb, int n)
     isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i);
 
     /* read the entries */
-    pp = isamb_pp_open (isb, isamc_p);
+    pp = isamb_pp_open (isb, isamc_p, 2);
     
     for (i = 0; i<ri.max; i +=2 )
     {
@@ -126,7 +126,7 @@ void tst_forward(ISAMB isb, int n)
     }
     isamb_pp_close(pp);
     
-    pp = isamb_pp_open (isb, isamc_p);
+    pp = isamb_pp_open (isb, isamc_p, 2);
     for (i = 0; i<ri.max; i += 100)
     {
        int x = -1;
@@ -165,7 +165,7 @@ void tst_insert(ISAMB isb, int n)
     isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i);
 
     /* read the entries */
-    pp = isamb_pp_open (isb, isamc_p);
+    pp = isamb_pp_open (isb, isamc_p, 2);
     
     ri.no = 0;
     while(isamb_pp_read (pp, key_buf))
index 93ab3e7..63901cd 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rsbetween.c,v 1.24 2004-09-01 15:01:32 heikki Exp $
+/* $Id: rsbetween.c,v 1.25 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
@@ -105,9 +105,10 @@ static void log2 (struct rset_between_rfd *p, char *msg, int cmp_l, int cmp_r)
 #endif
 
 RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol,
+            int scope,
             RSET rset_l, RSET rset_m, RSET rset_r, RSET rset_attr)
 {
-    RSET rnew=rset_create_base(&control, nmem, kcontrol);
+    RSET rnew=rset_create_base(&control, nmem, kcontrol, scope);
     struct rset_between_info *info=
         (struct rset_between_info *) nmem_malloc(rnew->nmem,sizeof(*info));
     info->rset_l = rset_l;
@@ -254,7 +255,7 @@ static int r_read_between (RSFD rfd, void *buf)
         else
         {
             p->level = 0;
-            cmp_l=2; /* past this record */
+            cmp_l=rfd->rset->scope; /* past this record */
         }
 #if RSBETWEEN_DEBUG
         log2( p, "after first L", cmp_l, cmp_r);
@@ -262,9 +263,9 @@ static int r_read_between (RSFD rfd, void *buf)
 
         while (cmp_l < 0)   /* l before m */
         {
-            if (cmp_l == -2)
+            if (cmp_l <= - rfd->rset->scope)  /* ==-2 */
                 p->level=0; /* earlier record */
-            if (cmp_l == -1)
+            if (cmp_l > - rfd->rset->scope)  /* == -1 */
             {
                 p->level++; /* relevant start tag */
 
@@ -284,12 +285,12 @@ static int r_read_between (RSFD rfd, void *buf)
                         }
                         else if (cmp_attr > 0)
                             break;
-                        else if (cmp_attr==-1) 
+                        else if (cmp_attr > - rfd->rset->scope)  /* == -1 */
                             p->more_attr = rset_read (p->rfd_attr, p->buf_attr);
                             /* if we had a forward that went all the way to
                              * the seqno, we could use that. But fwd only goes
                              * to the sysno */
-                        else if (cmp_attr==-2) 
+                        else if (cmp_attr <= - rfd->rset->scope) /* ==-2 */
                         {
                             p->more_attr = rset_forward( p->rfd_attr,
                                              p->buf_attr, p->buf_l);
@@ -303,7 +304,7 @@ static int r_read_between (RSFD rfd, void *buf)
             }
 #define NEWCODE 1 
 #if NEWCODE                
-            if (cmp_l==-2)
+            if (cmp_l <= - rfd->rset->scope )/* ==-2 */
             {
                 if (p->more_l) 
                 {
@@ -311,7 +312,7 @@ static int r_read_between (RSFD rfd, void *buf)
                     if (p->more_l)
                         cmp_l= (*kctrl->cmp)(p->buf_l, p->buf_m);
                     else
-                        cmp_l=2;
+                        cmp_l=rfd->rset->scope;  /*2*/
 #if RSBETWEEN_DEBUG
                     log2( p, "after forwarding L", cmp_l, cmp_r);
 #endif
@@ -328,7 +329,7 @@ static int r_read_between (RSFD rfd, void *buf)
                 cmp_l= (*kctrl->cmp)(p->buf_l, p->buf_m);
             }
             else
-                cmp_l=2; 
+                cmp_l=rfd->rset->scope;   /*2*/
 #if RSBETWEEN_DEBUG
             log2( p, "end of L loop", cmp_l, cmp_r);
 #endif
@@ -342,19 +343,19 @@ static int r_read_between (RSFD rfd, void *buf)
         if (p->more_r)
             cmp_r= (*kctrl->cmp)(p->buf_r, p->buf_m);
         else
-            cmp_r=2; 
+            cmp_r=rfd->rset->scope;  /*2*/
 #if RSBETWEEN_DEBUG
         log2( p, "after first R", cmp_l, cmp_r);
 #endif
         while (cmp_r < 0)   /* r before m */
         {
              /* -2, earlier record, don't count level */
-            if (cmp_r == -1)
+            if (cmp_r > -rfd->rset->scope) /* == -1 */
                 p->level--; /* relevant end tag */
             if (p->more_r)
             {
 #if NEWCODE                
-                if (cmp_r==-2)
+                if (cmp_r <= - rfd->rset->scope) /* == -2 */
                 {
                     p->more_r=rset_forward(p->rfd_r, p->buf_r, p->buf_m);
                 } else
@@ -370,7 +371,7 @@ static int r_read_between (RSFD rfd, void *buf)
 #endif
             }
             else
-                cmp_r=2; 
+                cmp_r=rfd->rset->scope;  /*2*/
 #if RSBETWEEN_DEBUG
         log2( p, "End of R loop", cmp_l, cmp_r);
 #endif
@@ -386,7 +387,7 @@ static int r_read_between (RSFD rfd, void *buf)
             log2( p, "Returning a hit (and forwarding m)", cmp_l, cmp_r);
 #endif
             p->more_m = rset_read (p->rfd_m, p->buf_m);
-            if (cmp_l == 2)
+            if (cmp_l >= rfd->rset->scope)  /* == 2 */
                 p->level = 0;
             p->hits++;
             return 1;
@@ -399,7 +400,7 @@ static int r_read_between (RSFD rfd, void *buf)
             return 0;  /* ergo, nothing can be found. stop scanning */
         }
 #if NEWCODE                
-        if (cmp_l == 2)
+        if (cmp_l >= rfd->rset->scope) /* == 2 */
         {
             p->level = 0;
             p->more_m=rset_forward(p->rfd_m, p->buf_m,  p->buf_l);
@@ -408,7 +409,7 @@ static int r_read_between (RSFD rfd, void *buf)
             p->more_m = rset_read (p->rfd_m, p->buf_m);
         }
 #else
-        if (cmp_l == 2)
+        if (cmp_l >= rfd->rset->scope )  /* == 2 */
             p->level = 0;
         p->more_m = rset_read (p->rfd_m, p->buf_m);
 #endif
index 574f782..b7f2ba6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rsbool.c,v 1.46 2004-09-01 15:01:32 heikki Exp $
+/* $Id: rsbool.c,v 1.47 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -105,9 +105,10 @@ struct rset_bool_rfd {
 
 static RSET rsbool_create_base( const struct rset_control *ctrl,
             NMEM nmem, const struct key_control *kcontrol,
+            int scope, 
             RSET rset_l, RSET rset_r)
 {
-    RSET rnew=rset_create_base(ctrl, nmem, kcontrol);
+    RSET rnew=rset_create_base(ctrl, nmem, kcontrol, scope);
     struct rset_bool_info *info;
     info = (struct rset_bool_info *) nmem_malloc(rnew->nmem,sizeof(*info));
     info->rset_l = rset_l;
@@ -118,23 +119,29 @@ static RSET rsbool_create_base( const struct rset_control *ctrl,
 
 
 RSET rsbool_create_and( NMEM nmem, const struct key_control *kcontrol,
+                        int scope, 
                         RSET rset_l, RSET rset_r)
 {
     return rsbool_create_base(rset_kind_and, nmem, kcontrol,
+                              scope,
                               rset_l, rset_r);
 }
 
 RSET rsbool_create_or( NMEM nmem, const struct key_control *kcontrol,
+                        int scope, 
                        RSET rset_l, RSET rset_r)
 {
     return rsbool_create_base(rset_kind_or, nmem, kcontrol,
+                              scope,
                               rset_l, rset_r);
 }
 
 RSET rsbool_create_not( NMEM nmem, const struct key_control *kcontrol,
+                        int scope, 
                         RSET rset_l, RSET rset_r)
 {
     return rsbool_create_base(rset_kind_not, nmem, kcontrol,
+                              scope, 
                               rset_l, rset_r);
 }
 
@@ -209,9 +216,9 @@ static int r_forward (RSFD rfd, void *buf,
     struct rset_bool_rfd *p=(struct rset_bool_rfd *)rfd->priv;
     const struct key_control *kctrl=rfd->rset->keycontrol;
 
-    if ( p->more_l && ((kctrl->cmp)(untilbuf,p->buf_l)==2) )
+    if ( p->more_l && ((kctrl->cmp)(untilbuf,p->buf_l)>=rfd->rset->scope) )
         p->more_l = rset_forward(p->rfd_l, p->buf_l, untilbuf);
-    if ( p->more_r && ((kctrl->cmp)(untilbuf,p->buf_r)==2))
+    if ( p->more_r && ((kctrl->cmp)(untilbuf,p->buf_r)>=rfd->rset->scope))
         p->more_r = rset_forward(p->rfd_r, p->buf_r, untilbuf);
     p->tail=0; 
     return rset_read(rfd,buf); 
@@ -245,9 +252,9 @@ static int r_read_and (RSFD rfd, void *buf)
         if (p->more_l && p->more_r)
             cmp = (*kctrl->cmp)(p->buf_l, p->buf_r);
         else if (p->more_l)
-            cmp = -2;
+            cmp = -rfd->rset->scope;
         else
-            cmp = 2;
+            cmp = rfd->rset->scope;
 #if RSET_DEBUG
         logf (LOG_DEBUG, "r_read_and [%p] looping: m=%d/%d c=%d t=%d",
                         rfd, p->more_l, p->more_r, cmp, p->tail);
@@ -255,13 +262,13 @@ static int r_read_and (RSFD rfd, void *buf)
         (*kctrl->log_item)(LOG_DEBUG, p->buf_r, "right ");
 #endif
         if (!cmp)
-        {
+        {  /* cmp==0 */
             memcpy (buf, p->buf_l, kctrl->key_size);
             p->more_l = rset_read (p->rfd_l, p->buf_l);
             p->tail = 1;
         }
-        else if (cmp == 1)
-        {
+        else if ( (cmp>0) && (cmp<rfd->rset->scope))
+        {  /* typically cmp == 1 */
             memcpy (buf, p->buf_r, kctrl->key_size);
             p->more_r = rset_read (p->rfd_r, p->buf_r);
             p->tail = 1;
@@ -274,8 +281,8 @@ static int r_read_and (RSFD rfd, void *buf)
             p->hits++;
             return 1;
         }
-        else if (cmp == -1)
-        {
+        else if ( (cmp<0) && (-cmp<rfd->rset->scope))
+        {  /* cmp == -1 */
             memcpy (buf, p->buf_l, kctrl->key_size);
             p->more_l = rset_read (p->rfd_l, p->buf_l);
             p->tail = 1;
@@ -287,8 +294,8 @@ static int r_read_and (RSFD rfd, void *buf)
             p->hits++;
             return 1;
         }
-        else if (cmp > 1)  /* cmp == 2 */
-        {
+        else if (cmp >= rfd->rset->scope )  
+        {  /* cmp == 2 */
             if (p->tail)
             {
                 memcpy (buf, p->buf_r, kctrl->key_size);
@@ -316,8 +323,8 @@ static int r_read_and (RSFD rfd, void *buf)
                     return 0; /* no point in reading further */
             }
         }
-        else  /* cmp == -2 */
-        {
+        else  
+        { /* cmp == -2 */
             if (p->tail)
             {
                 memcpy (buf, p->buf_l, kctrl->key_size);
@@ -364,11 +371,11 @@ static int r_read_or (RSFD rfd, void *buf)
         if (p->more_l && p->more_r)
             cmp = (*kctrl->cmp)(p->buf_l, p->buf_r);
         else if (p->more_r)
-            cmp = 2;
+            cmp = rfd->rset->scope;
         else
-            cmp = -2;
+            cmp = -rfd->rset->scope;
         if (!cmp)
-        {
+        { /* cmp==0 */
             memcpy (buf, p->buf_l, kctrl->key_size);
             p->more_l = rset_read (p->rfd_l, p->buf_l);
             p->more_r = rset_read (p->rfd_r, p->buf_r);
@@ -420,20 +427,21 @@ static int r_read_not (RSFD rfd, void *buf)
         if (p->more_l && p->more_r)
             cmp = (*kctrl->cmp)(p->buf_l, p->buf_r);
         else if (p->more_r)
-            cmp = 2;
+            cmp = rfd->rset->scope;
         else
-            cmp = -2;
-        if (cmp < -1)
-        {
+            cmp = -rfd->rset->scope;
+
+        if (cmp <= -rfd->rset->scope)
+        { /* cmp == -2 */
             memcpy (buf, p->buf_l, kctrl->key_size);
             p->more_l = rset_read (p->rfd_l, p->buf_l);
             p->hits++;
             return 1;
         }
-        else if (cmp > 1)
+        else if (cmp >= rfd->rset->scope)   /* cmp >1 */
             p->more_r = rset_forward( p->rfd_r, p->buf_r, p->buf_l);
         else
-        {
+        { /* cmp== -1, 0, or 1 */
             memcpy (buf, p->buf_l, kctrl->key_size);
             do
             { 
@@ -441,14 +449,16 @@ static int r_read_not (RSFD rfd, void *buf)
                 if (!p->more_l)
                     break;
                 cmp = (*kctrl->cmp)(p->buf_l, buf);
-            } while (cmp >= -1 && cmp <= 1);
+            } while (abs(cmp)<rfd->rset->scope);
+                /*  (cmp >= -1 && cmp <= 1) */
             do
             {
                 p->more_r = rset_read (p->rfd_r, p->buf_r);
                 if (!p->more_r)
                     break;
                 cmp = (*kctrl->cmp)(p->buf_r, buf);
-            } while (cmp >= -1 && cmp <= 1);
+            } while (abs(cmp)<rfd->rset->scope);
+               /* (cmp >= -1 && cmp <= 1) */
         }
     }
     return 0;
index 6f7c342..d4122c4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rset.c,v 1.32 2004-09-03 14:59:50 heikki Exp $
+/* $Id: rset.c,v 1.33 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -68,7 +68,8 @@ void rfd_delete_base(RSFD rfd)
 
 
 RSET rset_create_base(const struct rset_control *sel, 
-                      NMEM nmem, const struct key_control *kcontrol)
+                      NMEM nmem, const struct key_control *kcontrol,
+                      int scope)
 {
     RSET rnew;
     NMEM M;
@@ -89,6 +90,7 @@ RSET rset_create_base(const struct rset_control *sel,
     rnew->priv = 0;
     rnew->free_list=NULL;
     rnew->keycontrol=kcontrol;
+    rnew->scope=scope;
     return rnew;
 }
 
@@ -127,11 +129,11 @@ int rset_default_forward(RSFD rfd, void *buf,
                            const void *untilbuf)
 {
     int more=1;
-    int cmp=2;
+    int cmp=rfd->rset->scope;
     logf (LOG_DEBUG, "rset_default_forward starting '%s' (ct=%p rfd=%p)",
                     rfd->rset->control->desc, rfd->rset, rfd);
     /* key_logdump(LOG_DEBUG, untilbuf); */
-    while ( (cmp==2) && (more))
+    while ( (cmp>=rfd->rset->scope) && (more))
     {
         logf (LOG_DEBUG, "rset_default_forward looping m=%d c=%d",more,cmp);
         more=rset_read(rfd, buf);
index 170a22d..cd16cba 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rsisamb.c,v 1.21 2004-09-01 15:01:32 heikki Exp $
+/* $Id: rsisamb.c,v 1.22 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -64,10 +64,10 @@ struct rset_isamb_info {
     ISAMB_P pos;
 };
 
-RSET rsisamb_create( NMEM nmem, const struct key_control *kcontrol,
+RSET rsisamb_create( NMEM nmem, const struct key_control *kcontrol, int scope,
             ISAMB is, ISAMB_P pos)
 {
-    RSET rnew=rset_create_base(&control, nmem, kcontrol);
+    RSET rnew=rset_create_base(&control, nmem, kcontrol, scope);
     struct rset_isamb_info *info;
     info = (struct rset_isamb_info *) nmem_malloc(rnew->nmem,sizeof(*info));
     info->is=is;
@@ -100,7 +100,7 @@ RSFD r_open (RSET ct, int flag)
         ptinfo->buf = nmem_malloc (ct->nmem,ct->keycontrol->key_size);
         rfd->priv=ptinfo;
     }
-    ptinfo->pt = isamb_pp_open (info->is, info->pos);
+    ptinfo->pt = isamb_pp_open (info->is, info->pos, ct->scope );
     return rfd;
 }
 
index 5761a9b..c7fb530 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rsisamc.c,v 1.24 2004-09-01 15:01:32 heikki Exp $
+/* $Id: rsisamc.c,v 1.25 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -62,10 +62,10 @@ struct rset_isamc_info {
     ISAMC_P pos;
 };
 
-RSET rsisamc_create( NMEM nmem, const struct key_control *kcontrol,
+RSET rsisamc_create( NMEM nmem, const struct key_control *kcontrol, int scope,
                              ISAMC is, ISAMC_P pos)
 {
-    RSET rnew=rset_create_base(&control, nmem, kcontrol);
+    RSET rnew=rset_create_base(&control, nmem, kcontrol, scope);
     struct rset_isamc_info *info;
     info = (struct rset_isamc_info *) nmem_malloc(rnew->nmem,sizeof(*info));
     info->is=is;
@@ -113,7 +113,7 @@ static void r_close (RSFD rfd)
 
 static void r_rewind (RSFD rfd)
 {   
-    logf (LOG_DEBUG, "rsisamc_rewind");
+    logf (LOG_FATAL, "rsisamc_rewind");
     abort ();
 }
 
index 835f715..683a545 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rsisams.c,v 1.12 2004-09-01 15:01:32 heikki Exp $
+/* $Id: rsisams.c,v 1.13 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
@@ -60,10 +60,10 @@ struct rset_isams_info {
 };
 
 
-RSET rsisams_create( NMEM nmem, const struct key_control *kcontrol,
+RSET rsisams_create( NMEM nmem, const struct key_control *kcontrol, int scope,
             ISAMS is, ISAMS_P pos)
 {
-    RSET rnew=rset_create_base(&control, nmem, kcontrol);
+    RSET rnew=rset_create_base(&control, nmem, kcontrol, scope);
     struct rset_isams_info *info;
     info = (struct rset_isams_info *) nmem_malloc(rnew->nmem,sizeof(*info));
     rnew->priv=info;
index 83a24fe..cb75533 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rsmultior.c,v 1.9 2004-09-01 15:01:32 heikki Exp $
+/* $Id: rsmultior.c,v 1.10 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
@@ -210,10 +210,10 @@ static void heap_destroy (HEAP h)
 }
 
 
-RSET rsmultior_create( NMEM nmem, const struct key_control *kcontrol,
+RSET rsmultior_create( NMEM nmem, const struct key_control *kcontrol, int scope,
             int no_rsets, RSET* rsets)
 {
-    RSET rnew=rset_create_base(&control, nmem,kcontrol);
+    RSET rnew=rset_create_base(&control, nmem,kcontrol, scope);
     struct rset_multior_info *info;
     info = (struct rset_multior_info *) nmem_malloc(rnew->nmem,sizeof(*info));
     info->no_rsets=no_rsets;
index 6f3e44a..d10b274 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rsnull.c,v 1.25 2004-09-01 15:01:32 heikki Exp $
+/* $Id: rsnull.c,v 1.26 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
@@ -53,7 +53,7 @@ const struct rset_control *rset_kind_null = &control;
 
 RSET rsnull_create(NMEM nmem, const struct key_control *kcontrol )
 {
-    RSET rnew=rset_create_base(&control, nmem, kcontrol);
+    RSET rnew=rset_create_base(&control, nmem, kcontrol,0);
     rnew->priv=NULL;
     return rnew;
 }
index 618a272..b55b53d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rsprox.c,v 1.15 2004-09-03 15:04:11 heikki Exp $
+/* $Id: rsprox.c,v 1.16 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -73,12 +73,12 @@ struct rset_prox_rfd {
 };    
 
 
-RSET rsprox_create( NMEM nmem, const struct key_control *kcontrol,
+RSET rsprox_create( NMEM nmem, const struct key_control *kcontrol, int scope,
             int rset_no, RSET *rset,
             int ordered, int exclusion,
             int relation, int distance)
 {
-    RSET rnew=rset_create_base(&control, nmem, kcontrol);
+    RSET rnew=rset_create_base(&control, nmem, kcontrol, scope);
     struct rset_prox_info *info;
     info = (struct rset_prox_info *) nmem_malloc(rnew->nmem,sizeof(*info));
     info->rset = nmem_malloc(rnew->nmem,rset_no * sizeof(*info->rset));
@@ -177,7 +177,8 @@ static int r_forward (RSFD rfd, void *buf, const void *untilbuf)
     if (untilbuf)
     {
         /* it is enough to forward first one. Other will follow. */
-        if ( p->more[0] && ((kctrl->cmp)(untilbuf, p->buf[0]) >= 2) )
+        if ( p->more[0] &&   /* was: cmp >=2 */
+           ((kctrl->cmp)(untilbuf, p->buf[0]) >= rfd->rset->scope) ) 
             p->more[0] = rset_forward(p->rfd[0], p->buf[0], untilbuf);
     }
     if (info->ordered && info->relation == 3 && info->exclusion == 0
@@ -193,14 +194,14 @@ static int r_forward (RSFD rfd, void *buf, const void *untilbuf)
                     break;
                 }
                 cmp = (*kctrl->cmp) (p->buf[i], p->buf[i-1]);
-                if (cmp > 1)
+                if (cmp >= rfd->rset->scope )  /* cmp>1 */
                 {
                     p->more[i-1] = rset_forward (p->rfd[i-1],
                                                  p->buf[i-1],
                                                  p->buf[i]);
                     break;
                 }
-                else if (cmp == 1)
+                else if ( cmp>0 ) /* cmp == 1*/
                 {
                     if ((*kctrl->getseq)(p->buf[i-1]) +1 != 
                         (*kctrl->getseq)(p->buf[i]))
@@ -230,11 +231,10 @@ static int r_forward (RSFD rfd, void *buf, const void *untilbuf)
         while (p->more[0] && p->more[1]) 
         {
             int cmp = (*kctrl->cmp)(p->buf[0], p->buf[1]);
-            if (cmp < -1)
+            if ( cmp <= - rfd->rset->scope) /* cmp<-1*/
                 p->more[0] = rset_forward (p->rfd[0],
                                            p->buf[0], p->buf[1]);
-                /* FIXME - this certainly looks wrong! */
-            else if (cmp > 1)
+            else if ( cmp >= rfd->rset->scope ) /* cmp>1 */
                 p->more[1] = rset_forward (p->rfd[1],
                                            p->buf[1], p->buf[0]);
             else
index afdeb54..f15200b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rstemp.c,v 1.48 2004-09-01 15:01:32 heikki Exp $
+/* $Id: rstemp.c,v 1.49 2004-09-09 10:08:06 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
    Index Data Aps
 
@@ -79,9 +79,10 @@ struct rset_temp_rfd {
 };
 
 RSET rstemp_create( NMEM nmem, const struct key_control *kcontrol,
+                    int scope, 
                     const char *temp_path)
 {
-    RSET rnew=rset_create_base(&control, nmem, kcontrol);
+    RSET rnew=rset_create_base(&control, nmem, kcontrol, scope);
     struct rset_temp_info *info;
    
     info = (struct rset_temp_info *) nmem_malloc(rnew->nmem, sizeof(*info));