X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=isamc%2Fisamd.c;h=8fb7dcaec219e5f243522bc3556fda3ee5421010;hb=e5e4f1de02396b2cfab488f8e5918853e96d6b53;hp=4b16ca65226996acb85672ee0c0a3e310a3a7e7c;hpb=500505a8413687c67b6be99ff1ae9c1460d35e25;p=idzebra-moved-to-github.git diff --git a/isamc/isamd.c b/isamc/isamd.c index 4b16ca6..8fb7dca 100644 --- a/isamc/isamd.c +++ b/isamc/isamd.c @@ -1,15 +1,26 @@ -/* - * Copyright (c) 1995-1998, Index Data. - * See the file LICENSE for details. - * $Id: isamd.c,v 1.17 1999-10-06 11:46:36 heikki Exp $ - * - * Isamd - isam with diffs - * Programmed by: Heikki Levanto - * - * Todo - * - Statistics are missing and/or completely wrong - * - Lots of code stolen from isamc, not all needed any more - */ +/* $Id: isamd.c,v 1.23 2002-08-02 19:26:56 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 + Index Data Aps + +This file is part of the Zebra server. + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Zebra; see the file LICENSE.zebra. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. +*/ + + #include @@ -17,7 +28,7 @@ #include #include -#include +#include #include "../index/index.h" /* isamd uses the internal structure of it_key */ #include "isamd-p.h" @@ -38,12 +49,13 @@ ISAMD_M isamd_getmethod (ISAMD_M me) { 64, 0 }, #else { 32, 1 }, - { 64, 1 }, { 128, 1 }, - { 512, 1 }, + { 256, 1 }, + { 512, 1 }, + { 1024, 1 }, { 2048, 1 }, - { 8192, 1 }, - { 32768, 0 }, + { 4096, 1 }, + { 8192, 0 }, #endif #ifdef SKIPTHIS @@ -546,18 +558,45 @@ void isamd_pp_close (ISAMD_PP pp) (*is->method->code_stop)(ISAMD_DECODE, pp->decodeClientData); isamd_free_diffs(pp); /* see merge-d.h */ - xfree (pp->buf); - xfree (pp); if (is->method->debug > 5) - logf (LOG_LOG, "isamd_pp_close %p %d=%d:%d sz=%d n=%d=%d:%d", + logf (LOG_LOG, "isamd_pp_close %p %d=%d:%d sz=%d n=%d=%d:%d nk=%d", pp, isamd_addr(pp->pos, pp->cat), pp->cat, pp->pos, pp->size, - pp->next, isamd_type(pp->next), isamd_block(pp->next) ); + pp->next, isamd_type(pp->next), isamd_block(pp->next), + pp->numKeys ); + xfree (pp->buf); + xfree (pp); } +ISAMD_PP isamd_pp_create (ISAMD is, int cat) +/* creates a pp_buff without data in it. pos=0, cat as given */ +{ + ISAMD_PP pp = (ISAMD_PP) xmalloc (sizeof(*pp)); + int sz = is->method->filecat[is->max_cat].bsize; -ISAMD_PP isamd_pp_open (ISAMD is, ISAMD_P ipos) + pp->numKeys = 0; + pp->buf = (char *) xmalloc (sz); + memset(pp->buf,'\0',sz); /* clear the buffer, for new blocks */ + + pp->next = 0; + pp->size = 0; + pp->offset = 0; + pp->is = is; + pp->diffs=0; + pp->diffbuf=0; + pp->diffinfo=0; + pp->decodeClientData = (*is->method->code_start)(ISAMD_DECODE); + pp->cat = cat; + pp->pos = 0; + is->no_op_new++; + return pp; + +} + + +ISAMD_PP isamd_pp_open (ISAMD is, const char *dictbuf, int dictlen) { + ISAMD_P ipos; ISAMD_PP pp = (ISAMD_PP) xmalloc (sizeof(*pp)); char *src; int sz = is->method->filecat[is->max_cat].bsize; @@ -566,6 +605,7 @@ ISAMD_PP isamd_pp_open (ISAMD is, ISAMD_P ipos) char *c_ptr; /* for fake encoding the singlekey */ char *i_ptr; int ofs; + int dictnum; pp->numKeys = 0; src = pp->buf = (char *) xmalloc (sz); @@ -580,36 +620,24 @@ ISAMD_PP isamd_pp_open (ISAMD is, ISAMD_P ipos) pp->diffinfo=0; pp->decodeClientData = (*is->method->code_start)(ISAMD_DECODE); - if ( is_singleton(ipos) ) + dictnum=*dictbuf; // numkeys for internals, 0 for externals + + if (0==dictnum) + { + memcpy(&ipos, dictbuf+1, sizeof(ISAMD_P) ); + } + else /* dictionary block, fake a real one */ { pp->cat=0; pp->pos=0; if (is->method->debug > 5) - logf (LOG_LOG, "isamd_pp_open %p %d=%d:%d sz=%d n=%d=%d:%d", - pp, isamd_addr(pp->pos, pp->cat), pp->cat, pp->pos, pp->size, - pp->next, isamd_type(pp->next), isamd_block(pp->next) ); - singleton_decode(ipos, &singlekey ); - pp->offset=ISAMD_BLOCK_OFFSET_1; - pp->numKeys = 1; - ofs=pp->offset+sizeof(int); /* reserve length of diffsegment */ - singlekey.seqno = singlekey.seqno * 2 + 1; /* make an insert diff */ - c_ptr=&(pp->buf[ofs]); - i_ptr=(char*)(&singlekey); - (*is->method->code_item)(ISAMD_ENCODE, pp->decodeClientData, - &c_ptr, &i_ptr); - (*is->method->code_reset)(pp->decodeClientData); - ofs += c_ptr-&(pp->buf[ofs]); - memcpy( &(pp->buf[pp->offset]), &ofs, sizeof(int) ); - /* since we memset buf earlier, we already have a zero endmark! */ - pp->size = ofs; - if (is->method->debug > 5) - logf (LOG_LOG, "isamd_pp_open single %d=%x: %d.%d sz=%d", - ipos,ipos, - singlekey.sysno, singlekey.seqno/2, - pp->size ); + logf (LOG_LOG, "isamd_pp_open dict"); + pp->numKeys=(unsigned char) dictbuf[0]; + memcpy(pp->buf+ISAMD_BLOCK_OFFSET_1, dictbuf+1,dictlen-1); + pp->size=pp->offset=dictlen+ISAMD_BLOCK_OFFSET_1-1; is->no_op_single++; return pp; - } /* singleton */ + } /* dict block */ pp->cat = isamd_type(ipos); pp->pos = isamd_block(ipos); @@ -785,6 +813,8 @@ static char *hexdump(unsigned char *p, int len, char *buff) { } +#ifdef SKIPTHIS + /* needs different arguments, or something */ void isamd_pp_dump (ISAMD is, ISAMD_P ipos) { ISAMD_PP pp; @@ -847,9 +877,32 @@ void isamd_pp_dump (ISAMD is, ISAMD_P ipos) is->method->debug=olddebug; } /* dump */ +#endif + /* * $Log: isamd.c,v $ - * Revision 1.17 1999-10-06 11:46:36 heikki + * Revision 1.23 2002-08-02 19:26:56 adam + * Towards GPL + * + * Revision 1.22 2002/07/12 18:12:21 heikki + * Isam-D now stores small entries directly in the dictionary. + * Needs more tuning and cleaning... + * + * Revision 1.21 2002/07/11 16:16:00 heikki + * Fixed a bug in isamd, failed to store a single key when its bits + * did not fit into a singleton. + * + * Revision 1.20 2002/06/19 10:29:18 adam + * align block sizes for isam sys. Better plot for test + * + * Revision 1.19 1999/11/30 13:48:04 adam + * Improved installation. Updated for inclusion of YAZ header files. + * + * Revision 1.18 1999/10/06 15:18:13 heikki + * + * Improving block sizes again + * + * Revision 1.17 1999/10/06 11:46:36 heikki * mproved statistics on isam-d * * Revision 1.16 1999/10/05 09:57:40 heikki @@ -893,4 +946,4 @@ void isamd_pp_dump (ISAMD is, ISAMD_P ipos) * Copied from isamh, starting to change things... * * - */ \ No newline at end of file + */