X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=isamc%2Fisamd.c;h=46b22baa2979528d6c6ec99282d3d4fe9c69ab5a;hb=b8e1425a7f78791afbf45dc11acd82808e455c65;hp=7333d31c129a5f8890a8e125eb9392144f023236;hpb=e150e51a7e20a902e9fd2f11f00811f94f67d529;p=idzebra-moved-to-github.git diff --git a/isamc/isamd.c b/isamc/isamd.c index 7333d31..46b22ba 100644 --- a/isamc/isamd.c +++ b/isamc/isamd.c @@ -1,7 +1,7 @@ /* * Copyright (c) 1995-1998, Index Data. * See the file LICENSE for details. - * $Id: isamd.c,v 1.19 1999-11-30 13:48:04 adam Exp $ + * $Id: isamd.c,v 1.22 2002-07-12 18:12:21 heikki Exp $ * * Isamd - isam with diffs * Programmed by: Heikki Levanto @@ -37,7 +37,7 @@ ISAMD_M isamd_getmethod (ISAMD_M me) { 32, 40 }, /* 24 is the smallest unreasonable size! */ { 64, 0 }, #else - { 64, 1 }, + { 32, 1 }, { 128, 1 }, { 256, 1 }, { 512, 1 }, @@ -547,18 +547,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; @@ -567,6 +594,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); @@ -581,36 +609,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); @@ -786,6 +802,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; @@ -848,9 +866,22 @@ void isamd_pp_dump (ISAMD is, ISAMD_P ipos) is->method->debug=olddebug; } /* dump */ +#endif + /* * $Log: isamd.c,v $ - * Revision 1.19 1999-11-30 13:48:04 adam + * 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