New method log_item for the various isams to print log an item (for debug)
[idzebra-moved-to-github.git] / index / kcompare.c
index ab14f79..82e9491 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: kcompare.c,v 1.41 2003-06-23 15:35:25 adam Exp $
-   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
+/* $Id: kcompare.c,v 1.44 2004-06-01 12:56:38 adam Exp $
+   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
 This file is part of the Zebra server.
@@ -20,9 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.
 */
 
-
-
-
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -30,12 +27,23 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include "index.h"
 
-void key_logdump (int logmask, const void *p)
+#define INT_CODEC_NEW 0
+#define CODEC_INLINE inline
+void key_logdump_txt (int logmask, const void *p, const char *txt)
 {
     struct it_key key;
+    if (p)
+    {
+        memcpy (&key, p, sizeof(key));
+        logf (logmask, "%7d:%-4d %s", key.sysno, key.seqno,txt);
+    }
+    else
+        logf(logmask, " (null) %s",txt);
+}
 
-    memcpy (&key, p, sizeof(key));
-    logf (logmask, "%7d s=%-4d", key.sysno, key.seqno);
+void key_logdump (int logmask, const void *p)
+{
+    key_logdump_txt(logmask,p,"");
 }
 
 int key_compare_it (const void *p1, const void *p2)
@@ -101,17 +109,11 @@ int key_qsort_compare (const void *p1, const void *p2)
     return cp1[l] - cp2[l];
 }
 
-int key_get_pos (const void *p)
-{
-    struct it_key key;
-    memcpy (&key, p, sizeof(key));
-    return key.seqno;
-}
-
 struct iscz1_code_info {
     struct it_key key;
 };
 
+
 static void *iscz1_code_start (int mode)
 {
     struct iscz1_code_info *p = (struct iscz1_code_info *)
@@ -133,7 +135,38 @@ static void iscz1_code_stop (int mode, void *p)
     xfree (p);
 }
 
-void iscz1_encode_int (unsigned d, char **dst)
+#if INT_CODEC_NEW 
+CODEC_INLINE void iscz1_encode_int (unsigned d, char **dst)
+{
+    unsigned char *bp = (unsigned char*) *dst;
+
+    while (d > 127)
+    {
+        *bp++ = 128 | (d & 127);
+       d = d >> 7;
+    }
+    *bp++ = d;
+    *dst = (char *) bp;
+}
+
+CODEC_INLINE int iscz1_decode_int (unsigned char **src)
+{
+    unsigned d = 0;
+    unsigned char c;
+    unsigned r = 0;
+
+    while (((c = *(*src)++) & 128))
+    {
+        d += ((c&127) << r);
+       r += 7;
+    }
+    d += (c << r);
+    return d;
+}
+#else
+/* ! INT_CODEC_NEW */
+
+CODEC_INLINE void iscz1_encode_int (unsigned d, char **dst)
 {
     unsigned char *bp = (unsigned char*) *dst;
 
@@ -160,7 +193,7 @@ void iscz1_encode_int (unsigned d, char **dst)
     *dst = (char *) bp;
 }
 
-int iscz1_decode_int (unsigned char **src)
+CODEC_INLINE int iscz1_decode_int (unsigned char **src)
 {
     unsigned c = *(*src)++;
     switch (c & 192)
@@ -183,6 +216,7 @@ int iscz1_decode_int (unsigned char **src)
     
     return c;
 }
+#endif
 
 static void iscz1_code_item (int mode, void *vp, char **dst, char **src)
 {
@@ -228,6 +262,7 @@ ISAMS_M *key_isams_m (Res res, ISAMS_M *me)
     isams_getmethod (me);
 
     me->compare_item = key_compare;
+    me->log_item = key_logdump_txt;
 
     me->code_start = iscz1_code_start;
     me->code_item = iscz1_code_item;
@@ -243,6 +278,7 @@ ISAMC_M *key_isamc_m (Res res, ISAMC_M *me)
     isc_getmethod (me);
 
     me->compare_item = key_compare;
+    me->log_item = key_logdump_txt;
 
     me->code_start = iscz1_code_start;
     me->code_item = iscz1_code_item;
@@ -259,6 +295,7 @@ ISAMD_M *key_isamd_m (Res res, ISAMD_M *me)
     me = isamd_getmethod (me);
 
     me->compare_item = key_compare;
+    me->log_item = key_logdump_txt;
 
     me->code_start = iscz1_code_start;
     me->code_item = iscz1_code_item;