Fixed a bug in ISAMB splitting. A new block was attempted to be read
[idzebra-moved-to-github.git] / isamb / isamb.c
index 294683d..9f8fb84 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: isamb.c,v 1.76 2005-04-13 13:03:47 adam Exp $
+/* $Id: isamb.c,v 1.80 2005-06-29 12:31:46 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -196,7 +196,7 @@ ISAMB isamb_open(BFiles bfs, const char *name, int writeflag, ISAMC_M *method,
     isamb->skipped_numbers = 0;
     isamb->returned_numbers = 0;
     for (i = 0; i<ISAMB_MAX_LEVEL; i++)
-      isamb->skipped_nodes[i] = isamb->accessed_nodes[i] = 0;
+       isamb->skipped_nodes[i] = isamb->accessed_nodes[i] = 0;
 
     assert(cache == 0);
     isamb->file = xmalloc(sizeof(*isamb->file) * isamb->no_cat);
@@ -732,11 +732,12 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item,
         p->size = dst - dst_buf;
         assert (p->size >= 0);
 
-
         if (p->size <= b->file[p->cat].head.block_max)
         {
            /* it fits OK in this block */
             memcpy (startp, dst_buf, dst - dst_buf);
+
+           close_block(b, sub_p2);
         }
         else
         {
@@ -754,6 +755,9 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item,
             src = dst_buf;
             endp = dst;
 
+           p->dirty = 1;
+           close_block(b, sub_p2);
+
             half = src + b->file[p->cat].head.block_size/2;
             decode_ptr(&src, &pos);
 
@@ -807,8 +811,7 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item,
            (*sp)->no_items = p->no_items - no_items_first_half;
            p->no_items = no_items_first_half;
         }
-        p->dirty = 1;
-        close_block(b, sub_p2);
+       p->dirty = 1;
     }
     close_block(b, sub_p1);
     (*b->method->codec.stop)(c1);
@@ -1799,10 +1802,10 @@ int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf)
 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 */
-    struct ISAMB_block *p = pp->block[pp->level];
     assert(total);
     assert(current);
-    assert(p->leaf);
+    
+    /* if end-of-stream PP may not be leaf */
 
     *total = (double) (pp->block[0]->no_items);
     *current = (double) pp->returned_numbers;