Bug fixing (still a mem leak somewhere)
[idzebra-moved-to-github.git] / isamc / isamd.c
index f3f219a..ec9d2b1 100644 (file)
@@ -28,20 +28,23 @@ static void init_fc (ISAMD is, int cat);
 
 #define ISAMD_FREELIST_CHUNK 1
 
-#define SMALL_TEST 1
+#define SMALL_TEST 0
 
 ISAMD_M isamd_getmethod (ISAMD_M me)
 {
     static struct ISAMD_filecat_s def_cat[] = {
 #if SMALL_TEST
-/*        blocksz,   max keys before switching size */
+/*        blocksz,   max keys before switching size. Unused time being */
         {    32,   40 },
        {   128,    0 },
 #else
-        {    24,   40 },
-        {  2048, 2048 },
-        { 16384,    0 },
-
+        {    32,    1 },
+        {   128,    1 },
+        {   512,    1 },
+        {  2048,    1 },
+        {  8092,    1 },
+        { 32768,    1 },
+        {131068,    0 },
 #endif 
 
 /* old values from isamc, long time ago...
@@ -101,8 +104,10 @@ ISAMD isamd_open (BFiles bfs, const char *name, int writeflag, ISAMD_M method)
     } while (filecat[i++].mblocks);
     is->no_files = i;
     is->max_cat = --i;
-
     assert (is->no_files > 0);
+    assert (is->max_cat <=8 ); /* we have only 3 bits for it */
+    
     is->files = (ISAMD_file) xmalloc (sizeof(*is->files)*is->no_files);
     if (writeflag)
     {
@@ -397,6 +402,8 @@ void isamd_release_block (ISAMD is, int cat, int pos)
 {
     if (is->method->debug > 3)
         logf (LOG_LOG, "isamd: release_block in cat %d: %d", cat, pos);
+    assert(pos!=0);
+    
     if (is->files[cat].fc_list)
     {
         int j;
@@ -455,6 +462,7 @@ ISAMD_PP isamd_pp_open (ISAMD is, ISAMD_P ipos)
 
     src = pp->buf = (char *) xmalloc (is->method->filecat[is->max_cat].bsize);
                  /* always allocate for the largest blocks, saves trouble */
+    memset(pp->buf,'\0',is->method->filecat[is->max_cat].bsize);
     pp->next = 0;
     pp->size = 0;
     pp->offset = 0;
@@ -505,12 +513,13 @@ void isamd_buildfirstblock(ISAMD_PP pp){
   memcpy(dst, &pp->diffs, sizeof(pp->diffs));
   dst += sizeof(pp->diffs);  
   assert (dst - pp->buf  == ISAMD_BLOCK_OFFSET_1);
-  if (pp->is->method->debug > 2)
-     logf (LOG_LOG, "isamd: first: sz=%d  p=%d/%d>%d/%d nk=%d d=%d",
+  if (pp->is->method->debug > 1) //!!! 2
+     logf (LOG_LOG, "isamd: 1st: sz=%d  p=%d:%d>%d:%d nk=%d d=%d=2*%d+%d",
            pp->size, 
            pp->cat, pp->pos, 
            isamd_type(pp->next), isamd_block(pp->next),
-           pp->numKeys, pp->diffs);
+           pp->numKeys, 
+           pp->diffs, pp->diffs/2, pp->diffs&1);
 }
 
 void isamd_buildlaterblock(ISAMD_PP pp){
@@ -522,7 +531,7 @@ void isamd_buildlaterblock(ISAMD_PP pp){
   memcpy(dst, &pp->size,sizeof(pp->size));
   dst += sizeof(pp->size);
   assert (dst - pp->buf  == ISAMD_BLOCK_OFFSET_N);
-  if (pp->is->method->debug > 2)
+  if (pp->is->method->debug > 1)  //!!! 2
      logf (LOG_LOG, "isamd: l8r: sz=%d  p=%d/%d>%d/%d",
            pp->size, 
            pp->pos, pp->cat, 
@@ -679,7 +688,13 @@ void isamd_pp_dump (ISAMD is, ISAMD_P ipos)
 
 /*
  * $Log: isamd.c,v $
- * Revision 1.3  1999-07-21 14:24:50  heikki
+ * Revision 1.5  1999-08-07 11:30:59  heikki
+ * Bug fixing (still a mem leak somewhere)
+ *
+ * Revision 1.4  1999/08/04 14:21:18  heikki
+ * isam-d seems to be working.
+ *
+ * Revision 1.3  1999/07/21 14:24:50  heikki
  * isamd write and read functions ok, except when diff block full.
  * (merge not yet done)
  *