X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=isamc%2Fisamd.c;h=8fb7dcaec219e5f243522bc3556fda3ee5421010;hb=e5e4f1de02396b2cfab488f8e5918853e96d6b53;hp=f06cda07d1350096e0fe70738edbf99c14d9085d;hpb=6feeb67bdd353384cc16289c7db4fcb2e62cb74f;p=idzebra-moved-to-github.git diff --git a/isamc/isamd.c b/isamc/isamd.c index f06cda0..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.21 2002-07-11 16:16:00 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 @@ -557,9 +568,35 @@ void isamd_pp_close (ISAMD_PP 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; + + 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, ISAMD_P ipos) +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; @@ -568,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); @@ -582,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); @@ -787,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; @@ -849,9 +877,18 @@ void isamd_pp_dump (ISAMD is, ISAMD_P ipos) is->method->debug=olddebug; } /* dump */ +#endif + /* * $Log: isamd.c,v $ - * Revision 1.21 2002-07-11 16:16:00 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. *