From 2e4e9c6def27f1e1463dcb6f205fab6a98054f38 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 4 Aug 2004 08:35:22 +0000 Subject: [PATCH] Remove isamd. It's not been in use for a long time and isamb is better in most cases. Change SYSNO to be zint. Change pointers in isamc and isamb to zint. Change block number in bfile/cfile to zint. zint is a long integer (64-bit). This change practially removes register limits for Zebra. Implement int-list encoding for ISAMs. --- NEWS | 9 ++ bfile/bfile.c | 7 +- bfile/cfile.c | 16 +-- bfile/cfile.h | 18 +-- bfile/commit.c | 17 +-- bfile/mfile.c | 8 +- configure.in | 4 +- data1/d1_absyn.c | 6 +- data1/d1_read.c | 15 ++- examples/gils/zebra.cfg | 6 +- examples/zthes/Makefile.am | 3 +- include/Makefile.am | 9 +- include/bfile.h | 18 +-- include/data1.h | 6 +- include/isam-codec.h | 34 ++++++ include/isamb.h | 6 +- include/isamc.h | 26 ++--- include/isamd.h | 2 +- include/isams.h | 12 +- include/mfile.h | 22 ++-- include/rsm_or.h | 14 +-- include/sortidx.h | 9 +- include/zebraapi.h | 20 ++-- include/zebrautl.h | 10 +- include/zebraver.h | 27 ++++- index/Makefile.am | 4 +- index/dirs.c | 6 +- index/extract.c | 209 ++++++++++++++++++++++++++++++----- index/index.h | 64 +++++------ index/invstat.c | 108 +++--------------- index/kcompare.c | 264 +++++++++++++++++++++++++++++++++----------- index/kdump.c | 13 ++- index/kinput.c | 127 ++++++--------------- index/livcode.c | 6 +- index/rank1.c | 6 +- index/recindex.c | 106 +++++++++++------- index/recindex.h | 10 +- index/recindxp.h | 30 +++-- index/recstat.c | 18 +-- index/retrieve.c | 8 +- index/sortidx.c | 10 +- index/trunc.c | 104 +---------------- index/zebraapi.c | 42 +++---- index/zebrash.c | 4 +- index/zinfo.c | 64 +++++------ index/zrpn.c | 36 ++++-- index/zserver.c | 4 +- index/zsets.c | 48 +++++--- index/zvrank.c | 6 +- isamb/isamb.c | 236 ++++++++++++++++++++------------------- isamb/tstisamb.c | 17 +-- isamc/Makefile.am | 4 +- isamc/isamc-p.h | 47 ++++---- isamc/isamc.c | 135 ++++++++++++---------- isamc/merge.c | 121 ++++---------------- isams/isams.c | 39 +++---- perl/IDZebra.i | 10 +- perl/lib/IDZebra.pm | 207 +++++----------------------------- perl/zebra_perl.h | 2 +- recctrl/regxread.c | 14 +-- rset/Makefile.am | 4 +- test/api/t5.c | 4 +- test/codec/tstcodec.c | 122 ++++++++++++++++++-- util/Makefile.am | 4 +- util/atoi_zn.c | 39 +++++++ 65 files changed, 1375 insertions(+), 1251 deletions(-) create mode 100644 include/isam-codec.h create mode 100644 util/atoi_zn.c diff --git a/NEWS b/NEWS index 5a35531..a50a492 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,13 @@ +Remove isamd. It's not been in use for a long time and isamb is better +in most cases. + +Change SYSNO to be zint. Change pointers in isamc and isamb to zint. +Change block number in bfile/cfile to zint. zint is a long integer +(64-bit). This change practially removes register limits for Zebra. + +Implement int-list encoding for ISAMs. + Added a new 'cut' directive to charmaps (.chr files) which specifies that only characters after the cutting char should be indexed. diff --git a/bfile/bfile.c b/bfile/bfile.c index b9372fe..681c050 100644 --- a/bfile/bfile.c +++ b/bfile/bfile.c @@ -1,4 +1,4 @@ -/* $Id: bfile.c,v 1.35 2002-08-02 19:26:55 adam Exp $ +/* $Id: bfile.c,v 1.36 2004-08-04 08:35:22 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -34,6 +34,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include + #include "cfile.h" struct BFiles_struct { @@ -154,7 +155,7 @@ BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag) return(tmp); } -int bf_read (BFile bf, int no, int offset, int nbytes, void *buf) +int bf_read (BFile bf, zint no, int offset, int nbytes, void *buf) { int r; @@ -170,7 +171,7 @@ int bf_read (BFile bf, int no, int offset, int nbytes, void *buf) return r; } -int bf_write (BFile bf, int no, int offset, int nbytes, const void *buf) +int bf_write (BFile bf, zint no, int offset, int nbytes, const void *buf) { int r; zebra_lock_rdwr_wlock (&bf->rdwr_lock); diff --git a/bfile/cfile.c b/bfile/cfile.c index 9241385..550da60 100644 --- a/bfile/cfile.c +++ b/bfile/cfile.c @@ -1,4 +1,4 @@ -/* $Id: cfile.c,v 1.27 2002-08-02 19:26:55 adam Exp $ +/* $Id: cfile.c,v 1.28 2004-08-04 08:35:22 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -328,7 +328,8 @@ static void cf_moveto_flat (CFile cf) int i, j; logf (LOG_DEBUG, "cf: Moving to flat shadow: %s", cf->rmf->name); - logf (LOG_DEBUG, "cf: hits=%d miss=%d bucket_in_memory=%d total=%d", + logf (LOG_DEBUG, "cf: hits=%d miss=%d bucket_in_memory=" ZINT_FORMAT " total=" + ZINT_FORMAT, cf->no_hits, cf->no_miss, cf->bucket_in_memory, cf->head.next_bucket - cf->head.first_bucket); assert (cf->head.state == 1); @@ -447,7 +448,7 @@ int cf_new (CFile cf, int no) } -int cf_read (CFile cf, int no, int offset, int nbytes, void *buf) +int cf_read (CFile cf, zint no, int offset, int nbytes, void *buf) { int block; @@ -461,13 +462,13 @@ int cf_read (CFile cf, int no, int offset, int nbytes, void *buf) zebra_mutex_unlock (&cf->mutex); if (!mf_read (cf->block_mf, block, offset, nbytes, buf)) { - logf (LOG_FATAL|LOG_ERRNO, "cf_read no=%d, block=%d", no, block); + logf (LOG_FATAL|LOG_ERRNO, "cf_read no=" ZINT_FORMAT ", block=%d", no, block); exit (1); } return 1; } -int cf_write (CFile cf, int no, int offset, int nbytes, const void *buf) +int cf_write (CFile cf, zint no, int offset, int nbytes, const void *buf) { int block; @@ -488,7 +489,7 @@ int cf_write (CFile cf, int no, int offset, int nbytes, const void *buf) zebra_mutex_unlock (&cf->mutex); if (mf_write (cf->block_mf, block, offset, nbytes, buf)) { - logf (LOG_FATAL|LOG_ERRNO, "cf_write no=%d, block=%d", no, block); + logf (LOG_FATAL|LOG_ERRNO, "cf_write no=" ZINT_FORMAT ", block=%d", no, block); exit (1); } return 0; @@ -496,7 +497,8 @@ int cf_write (CFile cf, int no, int offset, int nbytes, const void *buf) int cf_close (CFile cf) { - logf (LOG_DEBUG, "cf: close hits=%d miss=%d bucket_in_memory=%d total=%d", + logf (LOG_DEBUG, "cf: close hits=%d miss=%d bucket_in_memory=" ZINT_FORMAT + " total=" ZINT_FORMAT, cf->no_hits, cf->no_miss, cf->bucket_in_memory, cf->head.next_bucket - cf->head.first_bucket); flush_bucket (cf, -1); diff --git a/bfile/cfile.h b/bfile/cfile.h index 43d69a9..5b88209 100644 --- a/bfile/cfile.h +++ b/bfile/cfile.h @@ -1,4 +1,4 @@ -/* $Id: cfile.h,v 1.14 2002-08-02 19:26:55 adam Exp $ +/* $Id: cfile.h,v 1.15 2004-08-04 08:35:22 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -53,12 +53,12 @@ typedef struct CFile_struct { struct CFile_head { int state; /* 1 = hash, 2 = flat */ - int next_block; /* next free block / last block */ + zint next_block; /* next free block / last block */ int block_size; /* mfile/bfile block size */ int hash_size; /* no of chains in hash table */ - int first_bucket; /* first hash bucket */ - int next_bucket; /* last hash bucket + 1 = first flat bucket */ - int flat_bucket; /* last flat bucket + 1 */ + zint first_bucket; /* first hash bucket */ + zint next_bucket; /* last hash bucket + 1 = first flat bucket */ + zint flat_bucket; /* last flat bucket + 1 */ } head; MFile block_mf; MFile hash_mf; @@ -66,8 +66,8 @@ typedef struct CFile_struct struct CFile_hash_bucket **parray; struct CFile_hash_bucket *bucket_lru_front, *bucket_lru_back; int dirty; - int bucket_in_memory; - int max_bucket_in_memory; + zint bucket_in_memory; + zint max_bucket_in_memory; char *iobuf; MFile rmf; int no_hits; @@ -78,8 +78,8 @@ typedef struct CFile_struct int cf_close (CFile cf); CFile cf_open (MFile mf, MFile_area area, const char *fname, int block_size, int wflag, int *firstp); -int cf_read (CFile cf, int no, int offset, int nbytes, void *buf); -int cf_write (CFile cf, int no, int offset, int nbytes, const void *buf); +int cf_read (CFile cf, zint no, int offset, int nbytes, void *buf); +int cf_write (CFile cf, zint no, int offset, int nbytes, const void *buf); void cf_unlink (CFile cf); void cf_commit (CFile cf); diff --git a/bfile/commit.c b/bfile/commit.c index 5727679..875a27d 100644 --- a/bfile/commit.c +++ b/bfile/commit.c @@ -1,5 +1,5 @@ -/* $Id: commit.c,v 1.16 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: commit.c,v 1.17 2004-08-04 08:35:22 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. @@ -180,9 +180,10 @@ static void cf_commit_hash (CFile cf) static void cf_commit_flat (CFile cf) { - int *fp; + zint *fp; int hno; - int i, vno = 0; + int i; + zint vno = 0; #if CF_OPTIMIZE_COMMIT struct map_cache *m_p; @@ -192,7 +193,7 @@ static void cf_commit_flat (CFile cf) #if CF_OPTIMIZE_COMMIT m_p = map_cache_init (cf); #endif - fp = (int *) xmalloc (HASH_BSIZE); + fp = (zint *) xmalloc (HASH_BSIZE); for (hno = cf->head.next_bucket; hno < cf->head.flat_bucket; hno++) { for (i = 0; i < (int) (HASH_BSIZE/sizeof(int)); i++) @@ -200,7 +201,7 @@ static void cf_commit_flat (CFile cf) if (!mf_read (cf->hash_mf, hno, 0, 0, fp) && hno != cf->head.flat_bucket-1) { - logf (LOG_FATAL, "read index block hno=%d (%d-%d) commit", + logf (LOG_FATAL, "read index block hno=%d (" ZINT_FORMAT "-" ZINT_FORMAT ") commit", hno, cf->head.next_bucket, cf->head.flat_bucket-1); } for (i = 0; i < (int) (HASH_BSIZE/sizeof(int)); i++) @@ -212,8 +213,8 @@ static void cf_commit_flat (CFile cf) #else if (!mf_read (cf->block_mf, fp[i], 0, 0, cf->iobuf)) { - logf (LOG_FATAL, "read data block hno=%d (%d-%d) " - "i=%d commit block at %d (->%d)", + logf (LOG_FATAL, "read data block hno=%d (" ZINT_FORMAT "-" ZINT_FORMAT ") " + "i=%d commit block at " ZINT_FORMAT " (->" ZINT_FORMAT")", hno, cf->head.next_bucket, cf->head.flat_bucket-1, i, fp[i], vno); exit (1); diff --git a/bfile/mfile.c b/bfile/mfile.c index 52b64cf..a96820a 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -1,4 +1,4 @@ -/* $Id: mfile.c,v 1.52 2003-04-05 12:32:34 adam Exp $ +/* $Id: mfile.c,v 1.53 2004-08-04 08:35:22 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -451,7 +451,7 @@ int mf_close(MFile mf) /* * Read one block from a metafile. Interface mirrors bfile. */ -int mf_read(MFile mf, int no, int offset, int nbytes, void *buf) +int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf) { int rd, toread; @@ -486,7 +486,7 @@ int mf_read(MFile mf, int no, int offset, int nbytes, void *buf) /* * Write. */ -int mf_write(MFile mf, int no, int offset, int nbytes, const void *buf) +int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf) { int ps, nblocks, towrite; mf_dir *dp; @@ -554,7 +554,7 @@ int mf_write(MFile mf, int no, int offset, int nbytes, const void *buf) mf->files[mf->cur_file].blocks = 0; mf->files[mf->cur_file].bytes = 0; mf->files[mf->cur_file].fd = -1; - sprintf(tmp, "%s/%s-%d.mf", dp->name, mf->name, + sprintf(tmp, "%s/%s-" ZINT_FORMAT ".mf", dp->name, mf->name, mf->files[mf->cur_file].number); mf->files[mf->cur_file].path = xstrdup(tmp); mf->no_files++; diff --git a/configure.in b/configure.in index 6689c38..20a4a4b 100644 --- a/configure.in +++ b/configure.in @@ -1,8 +1,8 @@ dnl Zebra, Index Data Aps, 1995-2004 -dnl $Id: configure.in,v 1.91 2004-06-11 10:36:08 adam Exp $ +dnl $Id: configure.in,v 1.92 2004-08-04 08:35:22 adam Exp $ dnl AC_INIT(include/zebraver.h) -AM_INIT_AUTOMAKE(idzebra,1.3.16) +AM_INIT_AUTOMAKE(idzebra,1.4.0) dnl ------ Substitutions AC_SUBST(TCL_INCLUDE) AC_SUBST(TCL_LIB) diff --git a/data1/d1_absyn.c b/data1/d1_absyn.c index dec05b8..a913e4b 100644 --- a/data1/d1_absyn.c +++ b/data1/d1_absyn.c @@ -1,4 +1,4 @@ -/* $Id: d1_absyn.c,v 1.9 2003-06-12 18:20:24 adam Exp $ +/* $Id: d1_absyn.c,v 1.10 2004-08-04 08:35:22 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -58,7 +58,7 @@ data1_absyn *data1_absyn_search (data1_handle dh, const char *name) while (p) { - if (!strcmp (name, p->name)) + if (!yaz_matchstr (name, p->name)) return p->absyn; p = p->next; } @@ -133,7 +133,7 @@ data1_attset *data1_attset_search_name (data1_handle dh, const char *name) while (p) { - if (!strcmp (name, p->name)) + if (!yaz_matchstr (name, p->name)) return p->attset; p = p->next; } diff --git a/data1/d1_read.c b/data1/d1_read.c index 1c494d9..742e170 100644 --- a/data1/d1_read.c +++ b/data1/d1_read.c @@ -1,4 +1,4 @@ -/* $Id: d1_read.c,v 1.8 2004-07-26 13:51:42 adam Exp $ +/* $Id: d1_read.c,v 1.9 2004-08-04 08:35:22 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -470,8 +470,8 @@ data1_node *data1_add_taggeddata (data1_handle dh, data1_node *root, return data1_add_insert_taggeddata (dh, at, tagname, m, 1, 0); } -data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at, - const char *tag, int num, +data1_node *data1_mk_tag_data_zint (data1_handle dh, data1_node *at, + const char *tag, zint num, NMEM nmem) { data1_node *node_data; @@ -481,11 +481,18 @@ data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at, return 0; node_data->u.data.what = DATA1I_num; node_data->u.data.data = node_data->lbuf; - sprintf (node_data->u.data.data, "%d", num); + sprintf (node_data->u.data.data, ZINT_FORMAT, num); node_data->u.data.len = strlen (node_data->u.data.data); return node_data; } +data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at, + const char *tag, int num, + NMEM nmem) +{ + return data1_mk_tag_data_zint(dh, at, tag, num, nmem); +} + data1_node *data1_mk_tag_data_oid (data1_handle dh, data1_node *at, const char *tag, Odr_oid *oid, NMEM nmem) diff --git a/examples/gils/zebra.cfg b/examples/gils/zebra.cfg index 52d0bd9..cc54678 100644 --- a/examples/gils/zebra.cfg +++ b/examples/gils/zebra.cfg @@ -1,5 +1,5 @@ # Simple Zebra configuration file -# $Id: zebra.cfg,v 1.2 2003-03-04 23:30:20 adam Exp $ +# $Id: zebra.cfg,v 1.3 2004-08-04 08:35:23 adam Exp $ # # Where the schema files, attribute files, etc are located. profilePath: ../../tab @@ -10,4 +10,6 @@ attset: gils.att attset: explain.att recordtype: grs.sgml -isam: b +isam: c + +#recordId: (bib-1,identifier-standard) diff --git a/examples/zthes/Makefile.am b/examples/zthes/Makefile.am index 2e1fd20..92c88c9 100644 --- a/examples/zthes/Makefile.am +++ b/examples/zthes/Makefile.am @@ -13,5 +13,6 @@ records/dino.xml: tree2xml.pl dino.tree clean: rm -f records/dino.xml *.mf *.LCK zebrasrv.pid -dist-hook: +dist-hook: records/dino.xml -mkdir $(distdir)/records + cp records/dino.xml $(distdir)/records diff --git a/include/Makefile.am b/include/Makefile.am index 3922ad9..6ee6333 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,9 +1,10 @@ noinst_HEADERS = bfile.h bset.h charmap.h d1_attset.h d1_map.h \ -data1.h dfa.h dict.h direntz.h isamb.h isamc.h isamd.h isamg.h isam.h \ -isams.h mfile.h passwddb.h recctrl.h res.h rsbetween.h rsbool.h rset.h \ -rsisamb.h rsisamc.h rsisamd.h rsisam.h rsisams.h rsm_or.h rsnull.h \ -rsprox.h rstemp.h set.h sortidx.h str.h zebra-lock.h zebramap.h zebrautl.h \ +data1.h dfa.h dict.h direntz.h isam-codec.h isamb.h isamc.h isamg.h \ +isam.h isams.h mfile.h passwddb.h recctrl.h \ +res.h rsbetween.h rsbool.h rset.h rsisamb.h rsisamc.h rsisam.h \ +rsisams.h rsm_or.h rsnull.h rsprox.h rstemp.h set.h \ +sortidx.h str.h zebra-lock.h zebramap.h zebrautl.h \ zebra_xpath.h include_HEADERS = zebraapi.h zebraver.h diff --git a/include/bfile.h b/include/bfile.h index 93871e4..d82d7a8 100644 --- a/include/bfile.h +++ b/include/bfile.h @@ -1,5 +1,5 @@ -/* $Id: bfile.h,v 1.21 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: bfile.h,v 1.22 2004-08-04 08:35:23 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,16 +20,12 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #ifndef BFILE_H #define BFILE_H #include -#ifdef __cplusplus -extern "C" { -#endif +YAZ_BEGIN_CDECL #define bf_blocksize(bf) mf_blocksize(bf->mf) @@ -61,14 +57,14 @@ BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag); block 'no'. stores contents in buffer 'buf'. returns 1 if whole block could be read; 0 otherwise. */ -int bf_read (BFile bf, int no, int offset, int nbytes, void *buf); +int bf_read (BFile bf, zint no, int offset, int nbytes, void *buf); /* bf_write: writes bytes to bfile 'bf'. writes 'nbytes' bytes (or whole block if 0) at offset 'offset' to block 'no'. retrieves contents from buffer 'buf'. returns 0 if successful; non-zero otherwise. */ -int bf_write (BFile bf, int no, int offset, int nbytes, const void *buf); +int bf_write (BFile bf, zint no, int offset, int nbytes, const void *buf); /* bf_cache: enables bfile cache if spec is not NULL */ void bf_cache (BFiles bfs, const char *spec); @@ -85,8 +81,6 @@ void bf_commitClean (BFiles bfs, const char *spec); /* bf_reset: delete register and shadow completely */ void bf_reset (BFiles bfs); -#ifdef __cplusplus -} -#endif +YAZ_END_CDECL #endif diff --git a/include/data1.h b/include/data1.h index 276bdd5..0e335db 100644 --- a/include/data1.h +++ b/include/data1.h @@ -1,4 +1,4 @@ -/* $Id: data1.h,v 1.9 2004-07-26 12:20:06 adam Exp $ +/* $Id: data1.h,v 1.10 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -31,6 +31,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include +#include #include #include #include @@ -423,6 +424,9 @@ YAZ_EXPORT data1_node *data1_mk_root (data1_handle dh, NMEM nmem, YAZ_EXPORT void data1_set_root(data1_handle dh, data1_node *res, NMEM nmem, const char *name); +YAZ_EXPORT data1_node *data1_mk_tag_data_zint (data1_handle dh, data1_node *at, + const char *tag, zint num, + NMEM nmem); YAZ_EXPORT data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at, const char *tag, int num, NMEM nmem); diff --git a/include/isam-codec.h b/include/isam-codec.h new file mode 100644 index 0000000..c7c6dc9 --- /dev/null +++ b/include/isam-codec.h @@ -0,0 +1,34 @@ +/* $Id: isam-codec.h,v 1.1 2004-08-04 08:35:23 adam Exp $ + Copyright (C) 2004 + 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. +*/ + +#ifndef ISAM_CODEC_H +#define ISAM_CODEC_H + +typedef struct { + void *(*start)(void); + void (*stop)(void *p); + void (*decode)(void *p, char **dst, const char **src); + void (*encode)(void *p, char **dst, const char **src); + void (*reset)(void *p); +} ISAM_CODEC; + +#endif diff --git a/include/isamb.h b/include/isamb.h index 5a599bd..181b7c2 100644 --- a/include/isamb.h +++ b/include/isamb.h @@ -1,4 +1,4 @@ -/* $Id: isamb.h,v 1.10 2004-08-03 14:54:41 heikki Exp $ +/* $Id: isamb.h,v 1.11 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -26,6 +26,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include +YAZ_BEGIN_CDECL + typedef struct ISAMB_s *ISAMB; typedef struct ISAMB_PP_s *ISAMB_PP; typedef ISAMC_P ISAMB_P; @@ -57,4 +59,6 @@ int isamb_block_info (ISAMB isamb, int cat); void isamb_dump (ISAMB b, ISAMB_P pos, void (*pr)(const char *str)); +YAZ_END_CDECL + #endif diff --git a/include/isamc.h b/include/isamc.h index 61ba2d2..0dc73ec 100644 --- a/include/isamc.h +++ b/include/isamc.h @@ -1,4 +1,4 @@ -/* $Id: isamc.h,v 1.12 2004-06-01 12:56:38 adam Exp $ +/* $Id: isamc.h,v 1.13 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -20,19 +20,16 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #ifndef ISAMC_H #define ISAMC_H +#include #include -#ifdef __cplusplus -extern "C" { -#endif +YAZ_BEGIN_CDECL typedef struct ISAMC_s *ISAMC; -typedef int ISAMC_P; +typedef zint ISAMC_P; typedef struct ISAMC_PP_s *ISAMC_PP; typedef struct ISAMC_filecat_s { @@ -48,12 +45,7 @@ typedef struct ISAMC_M_s { int (*compare_item)(const void *a, const void *b); void (*log_item)(int logmask, const void *p, const char *txt); -#define ISAMC_DECODE 0 -#define ISAMC_ENCODE 1 - void *(*code_start)(int mode); - void (*code_stop)(int mode, void *p); - void (*code_item)(int mode, void *p, char **dst, char **src); - void (*code_reset)(void *p); + ISAM_CODEC codec; int max_blocks_mem; int debug; @@ -74,16 +66,14 @@ ISAMC_PP isc_pp_open (ISAMC is, ISAMC_P pos); void isc_pp_close (ISAMC_PP pp); int isc_read_item (ISAMC_PP pp, char **dst); int isc_pp_read (ISAMC_PP pp, void *buf); -int isc_pp_num (ISAMC_PP pp); +zint isc_pp_num (ISAMC_PP pp); -int isc_block_used (ISAMC is, int type); +zint isc_block_used (ISAMC is, int type); int isc_block_size (ISAMC is, int type); #define isc_type(x) ((x) & 7) #define isc_block(x) ((x) >> 3) -#ifdef __cplusplus -} -#endif +YAZ_END_CDECL #endif diff --git a/include/isamd.h b/include/isamd.h index d252a2f..d9112ed 100644 --- a/include/isamd.h +++ b/include/isamd.h @@ -46,7 +46,7 @@ typedef struct ISAMD_M_s { #define ISAMD_ENCODE 1 void *(*code_start)(int mode); void (*code_stop)(int mode, void *p); - void (*code_item)(int mode, void *p, char **dst, char **src); + void (*code_item)(int mode, void *p, char **dst, const char **src); void (*code_reset)(void *p); int max_blocks_mem; diff --git a/include/isams.h b/include/isams.h index 92c3160..7338d93 100644 --- a/include/isams.h +++ b/include/isams.h @@ -1,4 +1,4 @@ -/* $Id: isams.h,v 1.5 2004-06-01 12:56:38 adam Exp $ +/* $Id: isams.h,v 1.6 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -24,25 +24,23 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #ifndef ISAMS_H #define ISAMS_H +#include #include +#include #ifdef __cplusplus extern "C" { #endif typedef struct ISAMS_s *ISAMS; -typedef int ISAMS_P; +typedef ISAMC_P ISAMS_P; typedef struct ISAMS_PP_s *ISAMS_PP; typedef struct ISAMS_M_s { int (*compare_item)(const void *a, const void *b); void (*log_item)(int logmask, const void *p, const char *txt); -#define ISAMC_DECODE 0 -#define ISAMC_ENCODE 1 - void *(*code_start)(int mode); - void (*code_stop)(int mode, void *p); - void (*code_item)(int mode, void *p, char **dst, char **src); + ISAM_CODEC codec; int debug; int block_size; diff --git a/include/mfile.h b/include/mfile.h index 57a7f94..fd8cb63 100644 --- a/include/mfile.h +++ b/include/mfile.h @@ -1,5 +1,5 @@ -/* $Id: mfile.h,v 1.21 2003-03-25 23:47:24 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: mfile.h,v 1.22 2004-08-04 08:35:23 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. @@ -27,19 +27,13 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include +#include #ifdef WIN32 -#if 0 -/* 32-bit access .. */ -typedef long mfile_off_t; -#define mfile_seek lseek - -#else /* 64-bit access .. */ typedef __int64 mfile_off_t; #define mfile_seek _lseeki64 -#endif #else #include @@ -72,9 +66,9 @@ typedef struct mf_dir typedef struct part_file { - int number; - int top; - int blocks; + zint number; + zint top; + zint blocks; mfile_off_t bytes; mf_dir *dir; char *path; @@ -133,12 +127,12 @@ int mf_close(MFile mf); /* * Read one block from a metafile. Interface mirrors bfile. */ -int mf_read(MFile mf, int no, int offset, int nbytes, void *buf); +int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf); /* * Same. */ -int mf_write(MFile mf, int no, int offset, int nbytes, const void *buf); +int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf); /* * Destroy a metafile, unlinking component files. File must be open. diff --git a/include/rsm_or.h b/include/rsm_or.h index bdf2de5..7d96e85 100644 --- a/include/rsm_or.h +++ b/include/rsm_or.h @@ -1,5 +1,5 @@ -/* $Id: rsm_or.h,v 1.6 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: rsm_or.h,v 1.7 2004-08-04 08:35:23 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. @@ -27,9 +27,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include -#ifdef __cplusplus -extern "C" { -#endif +YAZ_BEGIN_CDECL extern const struct rset_control *rset_kind_m_or; @@ -39,15 +37,13 @@ typedef struct rset_m_or_parms int (*cmp)(const void *p1, const void *p2); ISAMC isc; - ISAM_P *isam_positions; + ISAMC_P *isam_positions; RSET_TERM rset_term; int no_isam_positions; int no_save_positions; } rset_m_or_parms; -#ifdef __cplusplus -} -#endif +YAZ_END_CDECL #endif diff --git a/include/sortidx.h b/include/sortidx.h index eb79426..2ca958c 100644 --- a/include/sortidx.h +++ b/include/sortidx.h @@ -1,5 +1,5 @@ -/* $Id: sortidx.h,v 1.3 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: sortidx.h,v 1.4 2004-08-04 08:35:23 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,11 +20,10 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #ifndef SORTIDX_H #define SORTIDX_H +#include #include #ifdef __cplusplus @@ -38,7 +37,7 @@ typedef struct sortIdx *SortIdx; SortIdx sortIdx_open (BFiles bfs, int write_flag); void sortIdx_close (SortIdx si); int sortIdx_type (SortIdx si, int type); -void sortIdx_sysno (SortIdx si, int sysno); +void sortIdx_sysno (SortIdx si, SYSNO sysno); void sortIdx_add (SortIdx si, const char *buf, int len); void sortIdx_read (SortIdx si, char *buf); diff --git a/include/zebraapi.h b/include/zebraapi.h index f7facec..4488047 100644 --- a/include/zebraapi.h +++ b/include/zebraapi.h @@ -1,4 +1,4 @@ -/* $Id: zebraapi.h,v 1.13 2004-07-28 08:15:45 adam Exp $ +/* $Id: zebraapi.h,v 1.14 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -62,7 +62,7 @@ typedef struct { int len; /* length */ oid_value format; /* record syntax */ char *base; - int sysno; + SYSNO sysno; int score; } ZebraRetrievalRecord; @@ -210,17 +210,17 @@ int zebra_add_record (ZebraHandle zh, const char *buf, int buf_size); int zebra_insert_record (ZebraHandle zh, const char *recordType, - int *sysno, const char *match, const char *fname, + SYSNO *sysno, const char *match, const char *fname, const char *buf, int buf_size, int force_update); int zebra_update_record (ZebraHandle zh, const char *recordType, - int* sysno, const char *match, const char *fname, + SYSNO *sysno, const char *match, const char *fname, const char *buf, int buf_size, int force_update); int zebra_delete_record (ZebraHandle zh, const char *recordType, - int *sysno, const char *match, const char *fname, + SYSNO *sysno, const char *match, const char *fname, const char *buf, int buf_size, int force_update); @@ -229,11 +229,11 @@ YAZ_EXPORT int zebra_resultSetTerms (ZebraHandle zh, const char *setname, int *type, char *out, size_t *len); YAZ_EXPORT int zebra_sort (ZebraHandle zh, ODR stream, - int num_input_setnames, - const char **input_setnames, - const char *output_setname, - Z_SortKeySpecList *sort_sequence, - int *sort_status); + int num_input_setnames, + const char **input_setnames, + const char *output_setname, + Z_SortKeySpecList *sort_sequence, + int *sort_status); YAZ_EXPORT int zebra_select_databases (ZebraHandle zh, int num_bases, diff --git a/include/zebrautl.h b/include/zebrautl.h index dd5ae6a..753815d 100644 --- a/include/zebrautl.h +++ b/include/zebrautl.h @@ -1,5 +1,5 @@ -/* $Id: zebrautl.h,v 1.7 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: zebrautl.h,v 1.8 2004-08-04 08:35:23 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,8 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #ifndef ZEBRA_UTIL_H #define ZEBRA_UTIL_H @@ -29,4 +27,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include +YAZ_BEGIN_CDECL +zint atoi_zn (const char *buf, zint len); +YAZ_END_CDECL + #endif diff --git a/include/zebraver.h b/include/zebraver.h index 72dc698..9f49208 100644 --- a/include/zebraver.h +++ b/include/zebraver.h @@ -1,4 +1,4 @@ -/* $Id: zebraver.h,v 1.38 2004-07-30 10:06:09 adam Exp $ +/* $Id: zebraver.h,v 1.39 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -21,9 +21,28 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ #ifndef ZEBRAVER -#define ZEBRAVER "1.3.16" + +#define ZEBRAVER "1.4.0" + +#define ZEBRADATE "$Date: 2004-08-04 08:35:23 $" + +#ifdef __GNUC__ +typedef long long int zint; +#define ZINT_FORMAT "%lld" +#define ZINT_FORMAT0 "lld" +#else +#ifdef WIN32 +typedef __int64 zint; +#define ZINT_FORMAT "%lld" +#define ZINT_FORMAT0 "lld" +#error must define ZINT_FORMAT on Windows +#else +typedef long zint; +#define ZINT_FORMAT "%ld" +#define ZINT_FORMAT0 "ld" #endif +#endif + +typedef zint SYSNO; -#ifndef ZEBRADATE -#define ZEBRADATE "$Date: 2004-07-30 10:06:09 $" #endif diff --git a/index/Makefile.am b/index/Makefile.am index 1978423..0da7de0 100644 --- a/index/Makefile.am +++ b/index/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.23 2003-03-26 16:41:48 adam Exp $ +## $Id: Makefile.am,v 1.24 2004-08-04 08:35:23 adam Exp $ noinst_PROGRAMS = apitest kdump @@ -23,7 +23,7 @@ zebraidx_SOURCES = main.c zebrasrv_SOURCES = zserver.c zebrash_SOURCES = zebrash.c apitest_SOURCES = apitest.c -kdump_SOURCES=kdump.c kcompare.c +kdump_SOURCES = kdump.c AM_CPPFLAGS = -I$(srcdir)/../include $(YAZINC) $(TCL_INCLUDE) -DDEFAULT_PROFILE_PATH=\"$(pkgdatadir)/tab\" diff --git a/index/dirs.c b/index/dirs.c index 429a92a..7ae040e 100644 --- a/index/dirs.c +++ b/index/dirs.c @@ -1,5 +1,5 @@ -/* $Id: dirs.c,v 1.19 2002-08-17 07:59:03 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: dirs.c,v 1.20 2004-08-04 08:35:23 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. @@ -185,7 +185,7 @@ void dirs_rmdir (struct dirs_info *p, const char *src) dict_delete (p->dict, path); } -void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime) +void dirs_add (struct dirs_info *p, const char *src, SYSNO sysno, time_t mtime) { char path[DIRS_MAX_PATH]; char info[16]; diff --git a/index/extract.c b/index/extract.c index 593c9e8..9561c6e 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.157 2004-07-28 09:47:41 adam Exp $ +/* $Id: extract.c,v 1.158 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -20,7 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #include #include #include @@ -93,6 +92,51 @@ static const char **searchRecordKey (ZebraHandle zh, struct recKeys *reckeys, int attrSetS, int attrUseS) { +#if IT_KEY_NEW +/* #error searchRecordKey does not work yet in this mode.. */ + static const char *ws[32]; + void *decode_handle = iscz1_start(); + int off = 0; + int startSeq = -1; + int seqno = 0; + int i; + + for (i = 0; i<32; i++) + ws[i] = NULL; + + while (off < reckeys->buf_used) + { + const char *src = reckeys->buf + off; + struct it_key key; + char *dst = (char*) &key; + int attrSet, attrUse; + + iscz1_decode(decode_handle, &dst, &src); + assert(key.len < 4 && key.len > 2); + + attrSet = key.mem[0]; + attrUse = key.mem[1]; + seqno = key.mem[2]; + + if (attrUseS == attrUse && attrSetS == attrSet) + { + int woff; + + if (startSeq == -1) + startSeq = seqno; + woff = seqno - startSeq; + if (woff >= 0 && woff < 31) + ws[woff] = src; + } + + while (*src++) + ; + off = src - reckeys->buf; + } + iscz1_stop(decode_handle); + assert (off == reckeys->buf_used); + return ws; +#else static const char *ws[32]; int off = 0; int startSeq = -1; @@ -171,6 +215,7 @@ static const char **searchRecordKey (ZebraHandle zh, } assert (off == reckeys->buf_used); return ws; +#endif } struct file_read_info { @@ -415,6 +460,18 @@ struct recordLogInfo { int recordOffset; struct recordGroup *rGroup; }; + +void create_rec_keys_codec(struct recKeys *keys) +{ + keys->buf_used = 0; +#if IT_KEY_NEW + iscz1_reset(keys->codec_handle); +#else + keys->prevAttrUse = -1; + keys->prevAttrSet = -1; + keys->prevSeqNo = 0; +#endif +} static int file_extract_record(ZebraHandle zh, SYSNO *sysno, const char *fname, @@ -455,10 +512,8 @@ static int file_extract_record(ZebraHandle zh, /* we are going to read from a file, so prepare the extraction */ int i; - zh->reg->keys.buf_used = 0; - zh->reg->keys.prevAttrUse = -1; - zh->reg->keys.prevAttrSet = -1; - zh->reg->keys.prevSeqNo = 0; + create_rec_keys_codec(&zh->reg->keys); + zh->reg->sortKeys.buf_used = 0; recordOffset = fi->file_moffset; @@ -551,7 +606,10 @@ static int file_extract_record(ZebraHandle zh, { rinfo = dict_lookup (zh->reg->matchDict, matchStr); if (rinfo) + { + assert(*rinfo == sizeof(*sysno)); memcpy (sysno, rinfo+1, sizeof(*sysno)); + } } else { @@ -842,7 +900,7 @@ int buffer_extract_record (ZebraHandle zh, int delete_flag, int test_mode, const char *recordType, - int *sysno, + SYSNO *sysno, const char *match_criteria, const char *fname, int force_update, @@ -877,10 +935,8 @@ int buffer_extract_record (ZebraHandle zh, extractCtrl.endf = zebra_record_int_end; extractCtrl.fh = &fc; - zh->reg->keys.buf_used = 0; - zh->reg->keys.prevAttrUse = -1; - zh->reg->keys.prevAttrSet = -1; - zh->reg->keys.prevSeqNo = 0; + create_rec_keys_codec(&zh->reg->keys); + zh->reg->sortKeys.buf_used = 0; if (zebraExplain_curDatabase (zh->reg->zei, zh->basenames[0])) @@ -973,7 +1029,10 @@ int buffer_extract_record (ZebraHandle zh, if (matchStr) { rinfo = dict_lookup (zh->reg->matchDict, matchStr); if (rinfo) + { + assert(*rinfo == sizeof(*sysno)); memcpy (sysno, rinfo+1, sizeof(*sysno)); + } } } @@ -1178,10 +1237,8 @@ int explain_extract (void *handle, Record rec, data1_node *n) abort (); } - zh->reg->keys.buf_used = 0; - zh->reg->keys.prevAttrUse = -1; - zh->reg->keys.prevAttrSet = -1; - zh->reg->keys.prevSeqNo = 0; + create_rec_keys_codec(&zh->reg->keys); + zh->reg->sortKeys.buf_used = 0; extractCtrl.init = extract_init; @@ -1232,12 +1289,16 @@ int explain_extract (void *handle, Record rec, data1_node *n) void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, int cmd, struct recKeys *reckeys) { +#if IT_KEY_NEW + void *decode_handle = iscz1_start(); +#else + int seqno = 0; #if SU_SCHEME #else unsigned char attrSet = (unsigned char) -1; unsigned short attrUse = (unsigned short) -1; #endif - int seqno = 0; +#endif int off = 0; int ch = 0; ZebraExplainInfo zei = zh->reg->zei; @@ -1259,6 +1320,53 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, zh->reg->key_file_no = 0; } zebraExplain_recordCountIncrement (zei, cmd ? 1 : -1); +#if IT_KEY_NEW + while (off < reckeys->buf_used) + { + const char *src = reckeys->buf + off; + struct it_key key; + char *dst = (char*) &key; + int attrSet, attrUse; + + iscz1_decode(decode_handle, &dst, &src); + assert(key.len < 4 && key.len > 2); + + attrSet = key.mem[0]; + attrUse = key.mem[1]; /* sequence in mem[2] */ + + if (zh->reg->key_buf_used + 1024 > + (zh->reg->ptr_top -zh->reg->ptr_i)*sizeof(char*)) + extract_flushWriteKeys (zh,0); + assert(zh->reg->ptr_i >= 0); + ++(zh->reg->ptr_i); + assert(zh->reg->ptr_i > 0); + (zh->reg->key_buf)[zh->reg->ptr_top - zh->reg->ptr_i] = + (char*)zh->reg->key_buf + zh->reg->key_buf_used; + + ch = zebraExplain_lookupSU (zei, attrSet, attrUse); + if (ch < 0) + ch = zebraExplain_addSU (zei, attrSet, attrUse); + + assert (ch > 0); + zh->reg->key_buf_used += + key_SU_encode (ch,((char*)zh->reg->key_buf) + + zh->reg->key_buf_used); + while (*src) + ((char*)zh->reg->key_buf) [(zh->reg->key_buf_used)++] = *src++; + src++; + ((char*)(zh->reg->key_buf))[(zh->reg->key_buf_used)++] = '\0'; + ((char*)(zh->reg->key_buf))[(zh->reg->key_buf_used)++] = cmd; + + key.len = 2; + key.mem[0] = sysno; + key.mem[1] = key.mem[2]; /* sequence .. */ + + memcpy ((char*)zh->reg->key_buf + zh->reg->key_buf_used, + &key, sizeof(key)); + (zh->reg->key_buf_used) += sizeof(key); + off = src - reckeys->buf; + } +#else while (off < reckeys->buf_used) { const char *src = reckeys->buf + off; @@ -1323,7 +1431,11 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, (zh->reg->key_buf_used) += sizeof(key); off = src - reckeys->buf; } +#endif assert (off == reckeys->buf_used); +#if IT_KEY_NEW + iscz1_stop(decode_handle); +#endif } void extract_flushWriteKeys (ZebraHandle zh, int final) @@ -1460,18 +1572,22 @@ void extract_flushWriteKeys (ZebraHandle zh, int final) zh->reg->key_buf_used = 0; } -void extract_add_index_string (RecWord *p, const char *string, - int length) +void extract_add_index_string (RecWord *p, const char *str, int length) { char *dst; + ZebraHandle zh = p->extractCtrl->handle; + struct recKeys *keys = &zh->reg->keys; +#if IT_KEY_NEW + struct it_key key; + const char *src = (char*) &key; +#else unsigned char attrSet; unsigned short attrUse; int lead = 0; int diff = 0; int *pseqno = &p->seqno; - ZebraHandle zh = p->extractCtrl->handle; ZebraExplainInfo zei = zh->reg->zei; - struct recKeys *keys = &zh->reg->keys; +#endif if (keys->buf_used+1024 > keys->buf_max) { @@ -1485,6 +1601,25 @@ void extract_add_index_string (RecWord *p, const char *string, } dst = keys->buf + keys->buf_used; +#if IT_KEY_NEW + key.len = 3; + key.mem[0] = p->attrSet; + key.mem[1] = p->attrUse; + key.mem[2] = p->seqno; + +#if 0 + /* just for debugging .. */ + yaz_log(LOG_LOG, "set=%d use=%d seqno=%d", p->attrSet, p->attrUse, + p->seqno); +#endif + + iscz1_encode(keys->codec_handle, &dst, &src); + + *dst++ = p->reg_type; + memcpy (dst, str, length); + dst += length; + *dst++ = '\0'; +#else /* leader byte is encoded as follows: bit 0 : 1 if attrset is unchanged; 0 if attrset is changed bit 1 : 1 if attruse is unchanged; 0 if attruse is changed @@ -1499,13 +1634,13 @@ void extract_add_index_string (RecWord *p, const char *string, lead |= 2; else keys->prevAttrUse = attrUse; -#if 1 + diff = 1 + *pseqno - keys->prevSeqNo; if (diff >= 1 && diff <= 15) lead |= (diff << 2); else diff = 0; -#endif + keys->prevSeqNo = *pseqno; *dst++ = lead; @@ -1537,7 +1672,7 @@ void extract_add_index_string (RecWord *p, const char *string, } #endif *dst++ = p->reg_type; - memcpy (dst, string, length); + memcpy (dst, str, length); dst += length; *dst++ = '\0'; @@ -1546,10 +1681,11 @@ void extract_add_index_string (RecWord *p, const char *string, memcpy (dst, pseqno, sizeof(*pseqno)); dst += sizeof(*pseqno); } +#endif keys->buf_used = dst - keys->buf; } -static void extract_add_sort_string (RecWord *p, const char *string, +static void extract_add_sort_string (RecWord *p, const char *str, int length) { ZebraHandle zh = p->extractCtrl->handle; @@ -1582,7 +1718,7 @@ static void extract_add_sort_string (RecWord *p, const char *string, off += key_SU_encode(p->attrSet, sk->buf + off); off += key_SU_encode(p->attrUse, sk->buf + off); off += key_SU_encode(length, sk->buf + off); - memcpy (sk->buf + off, string, length); + memcpy (sk->buf + off, str, length); sk->buf_used = off + length; } @@ -1755,8 +1891,13 @@ void encode_key_init (struct encode_info *i) i->prevseq=0; i->prevcmd=-1; i->keylen=0; +#if IT_KEY_NEW + i->encode_handle = iscz1_start(); +#endif } +#if IT_KEY_NEW +#else char *encode_key_int (int d, char *bp) { if (d <= 63) @@ -1781,6 +1922,8 @@ char *encode_key_int (int d, char *bp) } return bp; } +#endif + #define OLDENCODE 1 #ifdef OLDENCODE @@ -1791,11 +1934,19 @@ char *encode_key_int (int d, char *bp) void encode_key_write (char *k, struct encode_info *i, FILE *outf) { struct it_key key; - char *bp = i->buf; + char *bp = i->buf, *bp0; + const char *src = (char *) &key; + /* copy term to output buf */ while ((*bp++ = *k++)) ; - memcpy (&key, k+1, sizeof(struct it_key)); + /* and copy & align key so we can mangle */ + memcpy (&key, k+1, sizeof(struct it_key)); /* *k is insert/delete */ +#if IT_KEY_NEW + bp0 = bp++; + iscz1_encode(i->encode_handle, &bp, &src); + *bp0 = (*k * 128) + bp - bp0 - 1; /* length and insert/delete combined */ +#else bp = encode_key_int ( (key.sysno - i->sysno) * 2 + *k, bp); if (i->sysno != key.sysno) { @@ -1807,6 +1958,7 @@ void encode_key_write (char *k, struct encode_info *i, FILE *outf) bp = encode_key_int (key.seqno - i->seqno, bp); i->seqno = key.seqno; i->cmd = *k; +#endif if (fwrite (i->buf, bp - i->buf, 1, outf) != 1) { logf (LOG_FATAL|LOG_ERRNO, "fwrite"); @@ -1816,6 +1968,9 @@ void encode_key_write (char *k, struct encode_info *i, FILE *outf) void encode_key_flush (struct encode_info *i, FILE *outf) { /* dummy routine */ +#if IT_KEY_NEW + iscz1_stop(i->encode_handle); +#endif } #else diff --git a/index/index.h b/index/index.h index afb416e..5d9bcfa 100644 --- a/index/index.h +++ b/index/index.h @@ -1,5 +1,5 @@ -/* $Id: index.h,v 1.109 2004-06-14 10:31:56 mike Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: index.h,v 1.110 2004-08-04 08:35:23 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,8 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #ifndef INDEX_H #define INDEX_H @@ -40,7 +38,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#include #include #define ISAM_DEFAULT "c" #include @@ -56,15 +53,25 @@ YAZ_BEGIN_CDECL #define SU_SCHEME 1 #define IT_MAX_WORD 256 -#define IT_KEY_HAVE_SEQNO 1 -#define IT_KEY_HAVE_FIELD 0 -typedef int SYSNO; +#define IT_KEY_NEW 1 + +#if IT_KEY_NEW + +#endif +#if IT_KEY_NEW +#define IT_KEY_LEVEL_MAX 4 +struct it_key { + int len; + zint mem[IT_KEY_LEVEL_MAX]; +}; +#else struct it_key { int sysno; int seqno; }; +#endif enum dirsKind { dirs_dir, dirs_file }; @@ -89,7 +96,7 @@ struct dirs_entry *dirs_read (struct dirs_info *p); struct dirs_entry *dirs_last (struct dirs_info *p); void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime); void dirs_rmdir (struct dirs_info *p, const char *src); -void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime); +void dirs_add (struct dirs_info *p, const char *src, SYSNO sysno, time_t mtime); void dirs_del (struct dirs_info *p, const char *src); void dirs_free (struct dirs_info **pp); @@ -106,6 +113,7 @@ void repositoryShow (ZebraHandle zh, const char *path); int key_open (ZebraHandle zh, int mem); int key_close (ZebraHandle zh); int key_compare (const void *p1, const void *p2); +void key_init(struct it_key *k); char *key_print_it (const void *p, char *buf); int key_get_seq (const void *p); int key_compare_it (const void *p1, const void *p2); @@ -117,7 +125,6 @@ void inv_compact (BFiles bfs); void key_input (ZebraHandle zh, int nkeys, int cache, Res res); ISAMS_M *key_isams_m (Res res, ISAMS_M *me); ISAMC_M *key_isamc_m (Res res, ISAMC_M *me); -ISAMD_M *key_isamd_m (Res res, ISAMD_M *me); int merge_sort (char **buf, int from, int to); int key_SU_code (int ch, char *out); @@ -180,6 +187,9 @@ struct encode_info { int prevseq; int prevcmd; int keylen; /* tells if we have an unwritten key in buf, and how long*/ +#if IT_KEY_NEW + void *encode_handle; +#endif char buf[ENCODE_BUFLEN]; }; @@ -208,26 +218,20 @@ struct recKeys { int buf_used; int buf_max; char *buf; +#if IT_KEY_NEW + void *codec_handle; +#else + int prevSeqNo; char prevAttrSet; short prevAttrUse; - int prevSeqNo; +#endif }; -#if 1 struct sortKeys { int buf_used; int buf_max; char *buf; }; -#else -struct sortKey { - char *string; - int length; - int attrSet; - int attrUse; - struct sortKey *next; -}; -#endif struct zebra_register { char *name; @@ -235,7 +239,6 @@ struct zebra_register { ISAMS isams; ISAM isam; ISAMC isamc; - ISAMD isamd; ISAMB isamb; Dict dict; Dict matchDict; @@ -343,7 +346,7 @@ struct rank_control { * int rssize; // number of records in result set (estimate?) */ void (*end)(struct zebra_register *reg, void *set_handle); - int (*calc)(void *set_handle, int sysno); + int (*calc)(void *set_handle, zint sysno); void (*add)(void *set_handle, int seqno, int term_index); }; @@ -422,7 +425,7 @@ extern struct rank_control *rank1_class; extern struct rank_control *rankzv_class; extern struct rank_control *rankliv_class; -int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, +int zebra_record_fetch (ZebraHandle zh, SYSNO sysno, int score, ODR stream, oid_value input_format, Z_RecordComposition *comp, oid_value *output_format, char **rec_bufp, int *rec_lenp, char **basenamep); @@ -436,7 +439,7 @@ int buffer_extract_record (ZebraHandle zh, int delete_flag, int test_mode, const char *recordType, - int *sysno, + SYSNO *sysno, const char *match_criteria, const char *fname, int force_update, @@ -488,12 +491,11 @@ int zebra_file_stat (const char *file_name, struct stat *buf, void zebra_livcode_transform(ZebraHandle zh, Z_RPNQuery *query); -void *iscz1_code_start (int mode); -void iscz1_code_reset (void *vp); -void iscz1_code_stop (int mode, void *p); -void iscz1_code_item (int mode, void *vp, char **dst, char **src); - - +void *iscz1_start (); +void iscz1_reset (void *vp); +void iscz1_stop (void *p); +void iscz1_decode (void *vp, char **dst, const char **src); +void iscz1_encode (void *vp, char **dst, const char **src); YAZ_END_CDECL diff --git a/index/invstat.c b/index/invstat.c index bb537a1..7443538 100644 --- a/index/invstat.c +++ b/index/invstat.c @@ -1,4 +1,4 @@ -/* $Id: invstat.c,v 1.35 2003-06-20 14:21:23 heikki Exp $ +/* $Id: invstat.c,v 1.36 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -26,7 +26,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include "index.h" -#include "../isamc/isamd-p.h" struct inv_stat_info { ZebraHandle zh; @@ -84,11 +83,8 @@ static int inv_stat_handle (char *name, const char *info, int pos, stat_info->no_dict_entries++; stat_info->no_dict_bytes += strlen(name); - if (!stat_info->zh->reg->isamd) - { - assert (*info == sizeof(ISAMS_P)); - memcpy (&isam_p, info+1, sizeof(ISAMS_P)); - } + assert (*info == sizeof(ISAMS_P)); + memcpy (&isam_p, info+1, sizeof(ISAMS_P)); if (stat_info->zh->reg->isams) { @@ -100,9 +96,11 @@ static int inv_stat_handle (char *name, const char *info, int pos, occur = isams_pp_num (pp); while (isams_pp_read(pp, &key)) { + occurx++; +#if IT_KEY_NEW +#else stat_info->cksum = stat_info->cksum * 65509 + key.sysno + 11 * key.seqno; - occurx++; if (-1==firstsys) { firstseq=key.seqno; @@ -110,6 +108,7 @@ static int inv_stat_handle (char *name, const char *info, int pos, } lastsys=key.sysno; lastseq=key.seqno; +#endif } assert (occurx == occur); stat_info->no_isam_entries[0] += occur; @@ -134,9 +133,11 @@ static int inv_stat_handle (char *name, const char *info, int pos, occur = isc_pp_num (pp); while (isc_pp_read(pp, &key)) { + occurx++; +#if IT_KEY_NEW +#else stat_info->cksum = stat_info->cksum * 65509 + key.sysno + 11 * key.seqno; - occurx++; if (-1==firstsys) { firstseq=key.seqno; @@ -144,56 +145,12 @@ static int inv_stat_handle (char *name, const char *info, int pos, } lastsys=key.sysno; lastseq=key.seqno; +#endif } assert (occurx == occur); stat_info->no_isam_entries[isc_type(isam_p)] += occur; isc_pp_close (pp); } - if (stat_info->zh->reg->isamd) - { - ISAMD_PP pp; - int occurx = 0; - struct it_key key; - /* printf("[%d: %d %d %d %d %d %d] ", */ - /* info[0], info[1], info[2], info[3], info[4], info[5], info[7]);*/ - pp = isamd_pp_open (stat_info->zh->reg->isamd, info+1, info[0]); - - occur = isamd_pp_num (pp); - while (isamd_pp_read(pp, &key)) - { - stat_info->cksum = stat_info->cksum * 65509 + - key.sysno + 11 * key.seqno; - occurx++; - /* printf("%d.%d ", key.sysno, key.seqno); */ /*!*/ - if (-1==firstsys) - { - firstseq=key.seqno; - firstsys=key.sysno; - } - lastsys=key.sysno; - lastseq=key.seqno; - if ( pp->is->method->debug >8 ) - logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ", - key.sysno, key.seqno, - key.sysno, key.seqno, - occur,occurx, pp->offset); - } - /* printf("\n"); */ /*!*/ -#ifdef SKIPTHIS - if ( pp->is->method->debug >7 ) - logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d", - isam_p, isamd_type(isam_p), isamd_block(isam_p), - occur, occurx); -#endif - if (occurx != occur) - logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx); - assert (occurx == occur); - i = pp->cat; - if (info[1]) - i=SINGLETON_TYPE; - stat_info->no_isam_entries[i] += occur; - isamd_pp_close (pp); - } if (stat_info->zh->reg->isamb) { ISAMB_PP pp; @@ -207,9 +164,11 @@ static int inv_stat_handle (char *name, const char *info, int pos, while (isamb_pp_read(pp, &key)) { + occur++; +#if IT_KEY_NEW +#else stat_info->cksum = stat_info->cksum * 65509 + key.sysno + 11 * key.seqno; - occur++; if (-1==firstsys) { firstseq=key.seqno; @@ -217,6 +176,7 @@ static int inv_stat_handle (char *name, const char *info, int pos, } lastsys=key.sysno; lastseq=key.seqno; +#endif } isamb_pp_close_x (pp, &size, &blocks); stat_info->isamb_blocks[cat] += blocks; @@ -238,9 +198,6 @@ static int inv_stat_handle (char *name, const char *info, int pos, int zebra_register_statistics (ZebraHandle zh, int dumpdict) { - int blocks; - int size; - int count; int i, prev; int before = 0; int occur; @@ -303,7 +260,7 @@ int zebra_register_statistics (ZebraHandle zh, int dumpdict) fprintf (stdout, " Blocks Occur Size KB Bytes/Entry\n"); for (i = 0; isc_block_used (zh->reg->isamc, i) >= 0; i++) { - fprintf (stdout, " %8d %8d", isc_block_used (zh->reg->isamc, i), + fprintf (stdout, " %8" ZINT_FORMAT0 " %8d", isc_block_used (zh->reg->isamc, i), stat_info.no_isam_entries[i]); if (stat_info.no_isam_entries[i]) @@ -317,39 +274,6 @@ int zebra_register_statistics (ZebraHandle zh, int dumpdict) fprintf (stdout, "\n"); } } - if (zh->reg->isamd) - { - fprintf (stdout, " Blocks Occur KB Bytes/Entry\n"); - if (zh->reg->isamd->method->debug >0) - logf(LOG_LOG," Blocks Occur KB Bytes/Entry"); - for (i = 0; i<=SINGLETON_TYPE; i++) - { - blocks= isamd_block_used(zh->reg->isamd,i); - size= isamd_block_size(zh->reg->isamd,i); - count=stat_info.no_isam_entries[i]; - if (i==SINGLETON_TYPE) - blocks=size=0; - if (stat_info.no_isam_entries[i]) - { - fprintf (stdout, "%c %7d %7d %7d %5.2f\n", - (i==SINGLETON_TYPE)?('z'):('A'+i), - blocks, - count, - (int) ((1023.0 + (double) blocks * size)/1024), - ((double) blocks * size)/count); - if (zh->reg->isamd->method->debug >0) - logf(LOG_LOG, "%c %7d %7d %7d %5.2f", - (i==SINGLETON_TYPE)?('z'):('A'+i), - blocks, - count, - (int) ((1023.0 + (double) blocks * size)/1024), - ((double) blocks * size)/count); - } /* entries */ - } /* for */ - } /* isamd */ - if ( (zh->reg->isamd) && (zh->reg->isamd->method->debug>0)) - fprintf (stdout, "\n%d words using %d bytes\n", - stat_info.no_dict_entries, stat_info.no_dict_bytes); if (zh->reg->isamb) { diff --git a/index/kcompare.c b/index/kcompare.c index 2c53065..e874af1 100644 --- a/index/kcompare.c +++ b/index/kcompare.c @@ -1,4 +1,4 @@ -/* $Id: kcompare.c,v 1.46 2004-06-09 13:11:49 adam Exp $ +/* $Id: kcompare.c,v 1.47 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -27,15 +27,37 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "index.h" +#if IT_KEY_NEW +#define INT_CODEC_NEW 1 +#else #define INT_CODEC_NEW 0 +#endif + #define CODEC_INLINE inline void key_logdump_txt (int logmask, const void *p, const char *txt) { struct it_key key; if (p) { +#if IT_KEY_NEW + char formstr[128]; + int i; + memcpy (&key, p, sizeof(key)); - logf (logmask, "%7d:%-4d %s", key.sysno, key.seqno,txt); + assert(key.len > 0 && key.len <= IT_KEY_LEVEL_MAX); + *formstr = '\0'; + for (i = 0; ilen; + if (((struct it_key *) p2)->len > l) + l = ((struct it_key *) p2)->len; + assert (l <= 4 && l > 0); + for (i = 0; i < l; i++) + { + if (((struct it_key *) p1)->mem[i] != ((struct it_key *) p2)->mem[i]) + { + if (((struct it_key *) p1)->mem[i] > ((struct it_key *) p2)->mem[i]) + return l-i; + else + return i-l; + } + } +#else if (((struct it_key *) p1)->sysno != ((struct it_key *) p2)->sysno) { if (((struct it_key *) p1)->sysno > ((struct it_key *) p2)->sysno) @@ -62,13 +100,18 @@ int key_compare_it (const void *p1, const void *p2) else return -1; } +#endif return 0; } char *key_print_it (const void *p, char *buf) { +#if IT_KEY_NEW + strcpy(buf, ""); +#else const struct it_key *i = p; sprintf (buf, "%d:%d", i->sysno, i->seqno); +#endif return buf; } @@ -77,6 +120,22 @@ int key_compare (const void *p1, const void *p2) struct it_key i1, i2; memcpy (&i1, p1, sizeof(i1)); memcpy (&i2, p2, sizeof(i2)); +#if IT_KEY_NEW + int i, l = i1.len; + if (i2.len > l) + l = i2.len; + assert (l <= 4 && l > 0); + for (i = 0; i < l; i++) + { + if (i1.mem[i] != i2.mem[i]) + { + if (i1.mem[i] > i2.mem[i]) + return l-i; + else + return i-l; + } + } +#else if (i1.sysno != i2.sysno) { if (i1.sysno > i2.sysno) @@ -91,6 +150,7 @@ int key_compare (const void *p1, const void *p2) else return -1; } +#endif return 0; } @@ -98,7 +158,11 @@ int key_get_seq(const void *p) { struct it_key k; memcpy (&k, p, sizeof(k)); +#if IT_KEY_NEW + return k.mem[k.len-1]; +#else return k.seqno; +#endif } int key_qsort_compare (const void *p1, const void *p2) @@ -120,29 +184,46 @@ struct iscz1_code_info { struct it_key key; }; -void *iscz1_code_start (int mode) +void *iscz1_start (void) { struct iscz1_code_info *p = (struct iscz1_code_info *) xmalloc (sizeof(*p)); - p->key.sysno = 0; - p->key.seqno = 0; + iscz1_reset(p); return p; } -void iscz1_code_reset (void *vp) +#if IT_KEY_NEW +void key_init(struct it_key *key) +{ + int i; + key->len = 0; + for (i = 0; imem[i] = 0; +} +#endif + +void iscz1_reset (void *vp) { struct iscz1_code_info *p = (struct iscz1_code_info *) vp; +#if IT_KEY_NEW + int i; + p->key.len = 0; + for (i = 0; i< IT_KEY_LEVEL_MAX; i++) + p->key.mem[i] = 0; +#else p->key.sysno = 0; p->key.seqno = 0; +#endif } -void iscz1_code_stop (int mode, void *p) +void iscz1_stop (void *p) { xfree (p); } -#if INT_CODEC_NEW -static CODEC_INLINE void iscz1_encode_int (unsigned d, char **dst) +#if INT_CODEC_NEW +/* small encoder that works with unsigneds of any length */ +static CODEC_INLINE void iscz1_encode_int (zint d, char **dst) { unsigned char *bp = (unsigned char*) *dst; @@ -155,23 +236,25 @@ static CODEC_INLINE void iscz1_encode_int (unsigned d, char **dst) *dst = (char *) bp; } -static CODEC_INLINE int iscz1_decode_int (unsigned char **src) +/* small decoder that works with unsigneds of any length */ +static CODEC_INLINE zint iscz1_decode_int (unsigned char **src) { - unsigned d = 0; + zint d = 0; unsigned char c; unsigned r = 0; while (((c = *(*src)++) & 128)) { - d += ((c&127) << r); + d += ((zint) (c&127) << r); r += 7; } - d += (c << r); + d += ((zint) c << r); return d; } #else /* ! INT_CODEC_NEW */ +/* old encoder that works with unsigneds up to 30 bits */ static CODEC_INLINE void iscz1_encode_int (unsigned d, char **dst) { unsigned char *bp = (unsigned char*) *dst; @@ -199,6 +282,7 @@ static CODEC_INLINE void iscz1_encode_int (unsigned d, char **dst) *dst = (char *) bp; } +/* old decoder that works with unsigneds up to 30 bits */ static CODEC_INLINE int iscz1_decode_int (unsigned char **src) { unsigned c = *(*src)++; @@ -224,43 +308,107 @@ static CODEC_INLINE int iscz1_decode_int (unsigned char **src) } #endif -void iscz1_code_item (int mode, void *vp, char **dst, char **src) +void iscz1_encode (void *vp, char **dst, const char **src) { struct iscz1_code_info *p = (struct iscz1_code_info *) vp; struct it_key tkey; +#if IT_KEY_NEW + zint d; + int i; +#else int d; +#endif - if (mode == ISAMC_ENCODE) + /* 1 + 3, 2, 9, 12 + 3, 2, 10, 2 + 4, 1 + + if diff is 0, then there is more ... + if diff is non-zero, then _may_ be more + */ + memcpy (&tkey, *src, sizeof(struct it_key)); +#if IT_KEY_NEW + /* deal with leader + delta encoding .. */ + d = 0; + assert(tkey.len > 0 && tkey.len <= 4); + for (i = 0; i < tkey.len; i++) { - memcpy (&tkey, *src, sizeof(struct it_key)); - d = tkey.sysno - p->key.sysno; - if (d) - { - iscz1_encode_int (2*tkey.seqno + 1, dst); - iscz1_encode_int (d, dst); - p->key.sysno += d; - p->key.seqno = tkey.seqno; - } - else - { - iscz1_encode_int (2*(tkey.seqno - p->key.seqno), dst); - p->key.seqno = tkey.seqno; - } - (*src) += sizeof(struct it_key); + d = tkey.mem[i] - p->key.mem[i]; + if (d || i == tkey.len-1) + { /* all have been equal until now, now make delta .. */ + p->key.mem[i] = tkey.mem[i]; + if (d > 0) + { + iscz1_encode_int (i + (tkey.len << 3) + 64, dst); + i++; + iscz1_encode_int (d, dst); + } + else + { + iscz1_encode_int (i + (tkey.len << 3), dst); + } + break; + } + } + /* rest uses absolute encoding ... */ + for (; i < tkey.len; i++) + { + iscz1_encode_int (tkey.mem[i], dst); + p->key.mem[i] = tkey.mem[i]; + } + (*src) += sizeof(struct it_key); +#else + d = tkey.sysno - p->key.sysno; + if (d) + { + iscz1_encode_int (2*tkey.seqno + 1, dst); + iscz1_encode_int (d, dst); + p->key.sysno += d; + p->key.seqno = tkey.seqno; } else { - d = iscz1_decode_int ((unsigned char **) src); - if (d & 1) - { - p->key.seqno = d>>1; - p->key.sysno += iscz1_decode_int ((unsigned char **) src); - } - else - p->key.seqno += d>>1; - memcpy (*dst, &p->key, sizeof(struct it_key)); - (*dst) += sizeof(struct it_key); + iscz1_encode_int (2*(tkey.seqno - p->key.seqno), dst); + p->key.seqno = tkey.seqno; + } + (*src) += sizeof(struct it_key); +#endif +} + +void iscz1_decode (void *vp, char **dst, const char **src) +{ + struct iscz1_code_info *p = (struct iscz1_code_info *) vp; +#if IT_KEY_NEW + int i; +#else + int d; +#endif + +#if IT_KEY_NEW + int leader = iscz1_decode_int ((unsigned char **) src); + i = leader & 7; + if (leader & 64) + p->key.mem[i] += iscz1_decode_int ((unsigned char **) src); + else + p->key.mem[i] = iscz1_decode_int ((unsigned char **) src); + p->key.len = (leader >> 3) & 7; + while (++i < p->key.len) + p->key.mem[i] = iscz1_decode_int ((unsigned char **) src); + memcpy (*dst, &p->key, sizeof(struct it_key)); + (*dst) += sizeof(struct it_key); +#else + d = iscz1_decode_int ((unsigned char **) src); + if (d & 1) + { + p->key.seqno = d>>1; + p->key.sysno += iscz1_decode_int ((unsigned char **) src); } + else + p->key.seqno += d>>1; + memcpy (*dst, &p->key, sizeof(struct it_key)); + (*dst) += sizeof(struct it_key); +#endif } ISAMS_M *key_isams_m (Res res, ISAMS_M *me) @@ -270,9 +418,11 @@ ISAMS_M *key_isams_m (Res res, ISAMS_M *me) me->compare_item = key_compare; me->log_item = key_logdump_txt; - me->code_start = iscz1_code_start; - me->code_item = iscz1_code_item; - me->code_stop = iscz1_code_stop; + me->codec.start = iscz1_start; + me->codec.decode = iscz1_decode; + me->codec.encode = iscz1_encode; + me->codec.stop = iscz1_stop; + me->codec.reset = iscz1_reset; me->debug = atoi(res_get_def (res, "isamsDebug", "0")); @@ -286,33 +436,17 @@ ISAMC_M *key_isamc_m (Res res, ISAMC_M *me) me->compare_item = key_compare; me->log_item = key_logdump_txt; - me->code_start = iscz1_code_start; - me->code_item = iscz1_code_item; - me->code_stop = iscz1_code_stop; - me->code_reset = iscz1_code_reset; + me->codec.start = iscz1_start; + me->codec.decode = iscz1_decode; + me->codec.encode = iscz1_encode; + me->codec.stop = iscz1_stop; + me->codec.reset = iscz1_reset; me->debug = atoi(res_get_def (res, "isamcDebug", "0")); return me; } -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; - me->code_stop = iscz1_code_stop; - me->code_reset = iscz1_code_reset; - - me->debug = atoi(res_get_def (res, "isamdDebug", "0")); - - return me; -} - int key_SU_encode (int ch, char *out) { int i; diff --git a/index/kdump.c b/index/kdump.c index aab7f45..6d78d70 100644 --- a/index/kdump.c +++ b/index/kdump.c @@ -1,4 +1,4 @@ -/* $Id: kdump.c,v 1.24 2004-01-22 11:27:21 adam Exp $ +/* $Id: kdump.c,v 1.25 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -20,7 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #include #include #include @@ -36,7 +35,12 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA char *prog; - +#if IT_KEY_NEW +int main(int argc, char **argv) +{ + exit(0); +} +#else int key_file_decode (FILE *f) { int c, d; @@ -97,6 +101,7 @@ static int read_one (FILE *inf, char *name, char *key, struct it_key *prevk) return 1; } + int main (int argc, char **argv) { int ret; @@ -184,6 +189,6 @@ int main (int argc, char **argv) logf (LOG_FATAL|LOG_ERRNO, "fclose %s", key_fname); exit (1); } - exit (0); } +#endif diff --git a/index/kinput.c b/index/kinput.c index 72eef09..3ed7512 100644 --- a/index/kinput.c +++ b/index/kinput.c @@ -1,5 +1,5 @@ -/* $Id: kinput.c,v 1.59 2004-06-15 10:56:31 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: kinput.c,v 1.60 2004-08-04 08:35:23 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. @@ -19,8 +19,6 @@ 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 #ifdef WIN32 @@ -49,8 +47,12 @@ struct key_file { size_t chunk; /* number of bytes allocated */ size_t buf_ptr; /* current position in buffer */ char *prev_name; /* last word read */ +#if IT_KEY_NEW + void *decode_handle; +#else int sysno; /* last sysno */ int seqno; /* last seqno */ +#endif off_t length; /* length of file */ /* handler invoked in each read */ void (*readHandler)(struct key_file *keyp, void *rinfo); @@ -124,6 +126,9 @@ void key_file_chunk_read (struct key_file *f) void key_file_destroy (struct key_file *f) { +#if IT_KEY_NEW + iscz1_stop(f->decode_handle); +#endif xfree (f->buf); xfree (f->prev_name); xfree (f); @@ -135,8 +140,12 @@ struct key_file *key_file_init (int no, int chunk, Res res) f = (struct key_file *) xmalloc (sizeof(*f)); f->res = res; +#if IT_KEY_NEW + f->decode_handle = iscz1_start(); +#else f->sysno = 0; f->seqno = 0; +#endif f->no = no; f->chunk = chunk; f->offset = 0; @@ -191,8 +200,16 @@ int key_file_decode (struct key_file *f) int key_file_read (struct key_file *f, char *key) { - int i, d, c; + int i, c; + char srcbuf[128]; +#if IT_KEY_NEW + const char *src = srcbuf; + char *dst; + int j; +#else struct it_key itkey; + int d; +#endif c = key_file_getc (f); if (c == 0) @@ -209,8 +226,20 @@ int key_file_read (struct key_file *f, char *key) while ((key[i++] = key_file_getc (f))) ; strcpy (f->prev_name, key); - f->sysno = 0; +#if IT_KEY_NEW + iscz1_reset(f->decode_handle); +#endif } +#if IT_KEY_NEW + c = key_file_getc(f); /* length + insert/delete combined */ + key[i++] = c & 128; + c = c & 127; + for (j = 0; j < c; j++) + srcbuf[j] = key_file_getc(f); + dst = key + i; + iscz1_decode(f->decode_handle, &dst, &src); + return i + sizeof(struct it_key); +#else d = key_file_decode (f); key[i++] = d & 1; d = d >> 1; @@ -225,6 +254,7 @@ int key_file_read (struct key_file *f, char *key) f->seqno = itkey.seqno; memcpy (key + i, &itkey, sizeof(struct it_key)); return i + sizeof (struct it_key); +#endif } struct heap_info { @@ -674,87 +704,6 @@ int heap_inpb (struct heap_info *hi) return 0; } -int heap_inpd (struct heap_info *hi) -{ - struct heap_cread_info hci; - ISAMD_I isamd_i = (ISAMD_I) xmalloc (sizeof(*isamd_i)); - - hci.key = (char *) xmalloc (KEY_SIZE); - hci.key_1 = (char *) xmalloc (KEY_SIZE); - hci.key_2 = (char *) xmalloc (KEY_SIZE); - hci.ret = -1; - hci.first_in_list = 1; - hci.hi = hi; - hci.more = heap_read_one (hi, hci.cur_name, hci.key); - - isamd_i->clientData = &hci; - isamd_i->read_item = heap_cread_item; - - while (hci.more) - { - char this_name[INP_NAME_MAX]; - char *dict_info; - char dictentry[ISAMD_MAX_DICT_LEN+1]; - char dictlen; - - strcpy (this_name, hci.cur_name); - - /* print_dict_item (hi->reg->zebra_maps, hci.cur_name); */ - /*!*/ /* FIXME: depend on isamd-debug */ - - assert (hci.cur_name[1]); - hi->no_diffs++; - if ((dict_info = dict_lookup (hi->reg->dict, hci.cur_name))) - { - dictlen=dict_info[0]; - memcpy (dictentry, dict_info+1, dictlen ); -#ifdef SKIPTHIS - logf(LOG_LOG,"dictentry before. len=%d: %d %d %d %d %d %d %d %d %d", - dictlen,dictentry[0], dictentry[1], dictentry[2], - dictentry[3], dictentry[4], dictentry[5], - dictentry[6], dictentry[7], dictentry[8]); /*!*/ -#endif - dictlen= isamd_append(hi->reg->isamd, dictentry, dictlen, isamd_i); - /* logf dictentry after */ - if (dictlen) - { - hi->no_updates++; - if ( (dictlen!=dict_info[0]) || - (0!=memcmp(dictentry, dict_info+1, dictlen)) ) - { - dict_insert(hi->reg->dict, this_name, - dictlen,dictentry); - } - } - else - { - hi->no_deletions++; - if (!dict_delete (hi->reg->dict, this_name)) - { - logf (LOG_FATAL, "dict_delete failed"); - abort(); - } - } - } - else - { - dictlen=0; - memset (dictentry, '\0', ISAMD_MAX_DICT_LEN); - dictlen= isamd_append(hi->reg->isamd, dictentry, dictlen, isamd_i); - /* logf dictentry first */ - hi->no_insertions++; - if (dictlen) - dict_insert(hi->reg->dict, this_name, - dictlen,dictentry); - } - } - xfree (isamd_i); - xfree (hci.key); - xfree (hci.key_1); - xfree (hci.key_2); - return 0; -} - int heap_inp (struct heap_info *hi) { char *info; @@ -966,8 +915,6 @@ void zebra_index_merge (ZebraHandle zh) heap_inpc (hi); if (zh->reg->isam) heap_inp (hi); - if (zh->reg->isamd) - heap_inpd (hi); if (zh->reg->isamb) heap_inpb (hi); @@ -994,5 +941,3 @@ void zebra_index_merge (ZebraHandle zh) key_heap_destroy (hi, nkeys); } - - diff --git a/index/livcode.c b/index/livcode.c index 44dec1b..21b18d3 100644 --- a/index/livcode.c +++ b/index/livcode.c @@ -11,7 +11,7 @@ rights reserved. Licensed under the Academic Free License version 1.1. http://opensource.org/licenses/academic.php -$Id: livcode.c,v 1.1 2003-03-26 16:41:48 adam Exp $ +$Id: livcode.c,v 1.2 2004-08-04 08:35:23 adam Exp $ */ @@ -649,12 +649,12 @@ static void add (void *set_handle, int seqno, int term_index) * score should be between 0 and 1000. If score cannot be obtained * -1 should be returned. */ -static int calc (void *set_handle, int sysno) +static int calc (void *set_handle, zint sysno) { int i, lo, divisor, score = 0; struct rank_set_info *si = (struct rank_set_info *) set_handle; - logf (LOG_DEBUG, "livrank calc sysno=%d", sysno); + logf (LOG_DEBUG, "livrank calc sysno=" ZINT_FORMAT, sysno); if (!si->no_rank_entries) return -1; diff --git a/index/rank1.c b/index/rank1.c index 1c1c149..b4de2dd 100644 --- a/index/rank1.c +++ b/index/rank1.c @@ -1,4 +1,4 @@ -/* $Id: rank1.c,v 1.14 2003-03-26 16:57:24 adam Exp $ +/* $Id: rank1.c,v 1.15 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -168,7 +168,7 @@ static void add (void *set_handle, int seqno, int term_index) * score should be between 0 and 1000. If score cannot be obtained * -1 should be returned. */ -static int calc (void *set_handle, int sysno) +static int calc (void *set_handle, zint sysno) { int i, lo, divisor, score = 0; struct rank_set_info *si = (struct rank_set_info *) set_handle; @@ -192,7 +192,7 @@ static int calc (void *set_handle, int sysno) divisor = si->no_rank_entries * (8+log2_int (si->last_pos/si->no_entries)); score = score / divisor; #if DEBUG_RANK - yaz_log (LOG_LOG, "sysno=%d score=%d", sysno, score); + yaz_log (LOG_LOG, "sysno=" ZINT_FORMAT " score=%d", sysno, score); #endif if (score > 1000) score = 1000; diff --git a/index/recindex.c b/index/recindex.c index e60cb1a..0f19b21 100644 --- a/index/recindex.c +++ b/index/recindex.c @@ -1,5 +1,5 @@ -/* $Id: recindex.c,v 1.34 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: recindex.c,v 1.35 2004-08-04 08:35:23 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. @@ -21,8 +21,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ - - /* * Format of first block * next (4 bytes) @@ -73,11 +71,11 @@ static void rec_tmp_expand (Records p, int size) } } -static int read_indx (Records p, int sysno, void *buf, int itemsize, +static int read_indx (Records p, SYSNO sysno, void *buf, int itemsize, int ignoreError) { int r; - int pos = (sysno-1)*itemsize; + zint pos = (sysno-1)*itemsize; r = bf_read (p->index_BFile, 1+pos/128, pos%128, itemsize, buf); if (r != 1 && !ignoreError) @@ -89,18 +87,18 @@ static int read_indx (Records p, int sysno, void *buf, int itemsize, return r; } -static void write_indx (Records p, int sysno, void *buf, int itemsize) +static void write_indx (Records p, SYSNO sysno, void *buf, int itemsize) { - int pos = (sysno-1)*itemsize; + zint pos = (sysno-1)*itemsize; bf_write (p->index_BFile, 1+pos/128, pos%128, itemsize, buf); } -static void rec_release_blocks (Records p, int sysno) +static void rec_release_blocks (Records p, SYSNO sysno) { struct record_index_entry entry; - int freeblock; - char block_and_ref[sizeof(short) + sizeof(int)]; + zint freeblock; + char block_and_ref[sizeof(short) + sizeof(zint)]; int dst_type; int first = 1; @@ -123,9 +121,9 @@ static void rec_release_blocks (Records p, int sysno) if (first) { short ref; - memcpy (&ref, block_and_ref + sizeof(int), sizeof(ref)); + memcpy (&ref, block_and_ref + sizeof(freeblock), sizeof(ref)); --ref; - memcpy (block_and_ref + sizeof(int), &ref, sizeof(ref)); + memcpy (block_and_ref + sizeof(freeblock), &ref, sizeof(ref)); if (ref) { if (bf_write (p->data_BFile[dst_type], freeblock, 0, @@ -146,7 +144,7 @@ static void rec_release_blocks (Records p, int sysno) exit (1); } p->head.block_free[dst_type] = freeblock; - memcpy (&freeblock, block_and_ref, sizeof(int)); + memcpy (&freeblock, block_and_ref, sizeof(freeblock)); p->head.block_used[dst_type]--; } @@ -165,12 +163,12 @@ static void rec_delete_single (Records p, Record rec) write_indx (p, rec->sysno, &entry, sizeof(entry)); } -static void rec_write_tmp_buf (Records p, int size, int *sysnos) +static void rec_write_tmp_buf (Records p, int size, SYSNO *sysnos) { struct record_index_entry entry; int no_written = 0; char *cptr = p->tmp_buf; - int block_prev = -1, block_free; + zint block_prev = -1, block_free; int dst_type = 0; int i; @@ -186,7 +184,7 @@ static void rec_write_tmp_buf (Records p, int size, int *sysnos) block_free, 0, sizeof(*p->head.block_free), &p->head.block_free[dst_type]) != 1) { - logf (LOG_FATAL|LOG_ERRNO, "read in %s at free block %d", + logf (LOG_FATAL|LOG_ERRNO, "read in %s at free block " ZINT_FORMAT, p->data_fname[dst_type], block_free); exit (1); } @@ -206,19 +204,19 @@ static void rec_write_tmp_buf (Records p, int size, int *sysnos) } else { - memcpy (cptr, &block_free, sizeof(int)); + memcpy (cptr, &block_free, sizeof(block_free)); bf_write (p->data_BFile[dst_type], block_prev, 0, 0, cptr); cptr = p->tmp_buf + no_written; } block_prev = block_free; - no_written += p->head.block_size[dst_type] - sizeof(int); + no_written += p->head.block_size[dst_type] - sizeof(zint); p->head.block_used[dst_type]++; } assert (block_prev != -1); block_free = 0; - memcpy (cptr, &block_free, sizeof(int)); + memcpy (cptr, &block_free, sizeof(block_free)); bf_write (p->data_BFile[dst_type], block_prev, 0, - sizeof(int) + (p->tmp_buf+size) - cptr, cptr); + sizeof(block_free) + (p->tmp_buf+size) - cptr, cptr); } Records rec_open (BFiles bfs, int rw, int compression_method) @@ -337,6 +335,36 @@ static void rec_decode_unsigned(unsigned *np, unsigned char *buf, int *len) *np = n; } +static void rec_encode_zint (zint n, unsigned char *buf, int *len) +{ + (*len) = 0; + while (n > 127) + { + buf[*len] = 128 + (n & 127); + n = n >> 7; + (*len)++; + } + buf[*len] = n; + (*len)++; +} + +static void rec_decode_zint(zint *np, unsigned char *buf, int *len) +{ + zint n = 0; + zint w = 1; + (*len) = 0; + + while (buf[*len] > 127) + { + n += w*(buf[*len] & 127); + w = w << 7; + (*len)++; + } + n += w * buf[*len]; + (*len)++; + *np = n; +} + static void rec_cache_flush_block1 (Records p, Record rec, Record last_rec, char **out_buf, int *out_size, int *out_offset) @@ -358,7 +386,7 @@ static void rec_cache_flush_block1 (Records p, Record rec, Record last_rec, } if (i == 0) { - rec_encode_unsigned (rec->sysno, *out_buf + *out_offset, &len); + rec_encode_zint (rec->sysno, *out_buf + *out_offset, &len); (*out_offset) += len; } if (rec->size[i] == 0) @@ -391,8 +419,8 @@ static void rec_write_multiple (Records p, int saveCount) int out_size = 1000; int out_offset = 0; char *out_buf = (char *) xmalloc (out_size); - int *sysnos = (int *) xmalloc (sizeof(*sysnos) * (p->cache_cur + 1)); - int *sysnop = sysnos; + SYSNO *sysnos = (SYSNO *) xmalloc (sizeof(*sysnos) * (p->cache_cur + 1)); + SYSNO *sysnop = sysnos; for (i = 0; icache_cur - saveCount; i++) { @@ -441,7 +469,7 @@ static void rec_write_multiple (Records p, int saveCount) #else i = bzBuffToBuffCompress #endif - (p->tmp_buf+sizeof(int)+sizeof(short)+ + (p->tmp_buf+sizeof(zint)+sizeof(short)+ sizeof(char), &csize, out_buf, out_offset, 1, 0, 30); if (i != BZ_OK) @@ -461,13 +489,13 @@ static void rec_write_multiple (Records p, int saveCount) /* either no compression or compression not supported ... */ csize = out_offset; rec_tmp_expand (p, csize); - memcpy (p->tmp_buf + sizeof(int) + sizeof(short) + sizeof(char), + memcpy (p->tmp_buf + sizeof(zint) + sizeof(short) + sizeof(char), out_buf, out_offset); csize = out_offset; compression_method = REC_COMPRESS_NONE; } - memcpy (p->tmp_buf + sizeof(int), &ref_count, sizeof(ref_count)); - memcpy (p->tmp_buf + sizeof(int)+sizeof(short), + memcpy (p->tmp_buf + sizeof(zint), &ref_count, sizeof(ref_count)); + memcpy (p->tmp_buf + sizeof(zint)+sizeof(short), &compression_method, sizeof(compression_method)); /* -------- compression */ @@ -498,7 +526,7 @@ static void rec_cache_flush (Records p, int saveCount) p->cache_cur = saveCount; } -static Record *rec_cache_lookup (Records p, int sysno, +static Record *rec_cache_lookup (Records p, SYSNO sysno, enum recordCacheFlag flag) { int i; @@ -569,12 +597,13 @@ void rec_close (Records *pp) *pp = NULL; } -static Record rec_get_int (Records p, int sysno) +static Record rec_get_int (Records p, SYSNO sysno) { int i, in_size, r; Record rec, *recp; struct record_index_entry entry; - int freeblock, dst_type; + zint freeblock; + int dst_type; char *nptr, *cptr; char *in_buf = 0; char *bz_buf = 0; @@ -611,7 +640,7 @@ static Record rec_get_int (Records p, int sysno) while (freeblock) { - int tmp; + zint tmp; cptr += p->head.block_size[dst_type] - sizeof(freeblock); @@ -625,9 +654,9 @@ static Record rec_get_int (Records p, int sysno) rec = (Record) xmalloc (sizeof(*rec)); rec->sysno = sysno; - memcpy (&compression_method, p->tmp_buf + sizeof(int) + sizeof(short), + memcpy (&compression_method, p->tmp_buf + sizeof(zint) + sizeof(short), sizeof(compression_method)); - in_buf = p->tmp_buf + sizeof(int) + sizeof(short) + sizeof(char); + in_buf = p->tmp_buf + sizeof(zint) + sizeof(short) + sizeof(char); in_size = entry.size - sizeof(short) - sizeof(char); switch (compression_method) { @@ -666,9 +695,9 @@ static Record rec_get_int (Records p, int sysno) nptr = in_buf; /* skip ref count */ while (nptr < in_buf + in_size) { - int this_sysno; + zint this_sysno; int len; - rec_decode_unsigned (&this_sysno, nptr, &len); + rec_decode_zint (&this_sysno, nptr, &len); nptr += len; for (i = 0; i < REC_NO_INFO; i++) @@ -712,7 +741,7 @@ static Record rec_get_int (Records p, int sysno) return rec; } -Record rec_get (Records p, int sysno) +Record rec_get (Records p, SYSNO sysno) { Record rec; zebra_mutex_lock (&p->mutex); @@ -724,7 +753,8 @@ Record rec_get (Records p, int sysno) static Record rec_new_int (Records p) { - int sysno, i; + int i; + SYSNO sysno; Record rec; assert (p); diff --git a/index/recindex.h b/index/recindex.h index 8818bd0..15201a2 100644 --- a/index/recindex.h +++ b/index/recindex.h @@ -1,5 +1,5 @@ -/* $Id: recindex.h,v 1.20 2002-10-23 14:28:20 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: recindex.h,v 1.21 2004-08-04 08:35:23 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,8 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #ifndef RECINDEX_H #define RECINDEX_H @@ -33,7 +31,7 @@ YAZ_BEGIN_CDECL #define REC_NO_INFO 8 typedef struct record_info { - int sysno; + SYSNO sysno; int newFlag; char *info[REC_NO_INFO]; size_t size[REC_NO_INFO]; @@ -49,7 +47,7 @@ void rec_del (Records p, Record *recpp); void rec_rm (Record *recpp); void rec_put (Records p, Record *recpp); Record rec_new (Records p); -Record rec_get (Records p, int sysno); +Record rec_get (Records p, SYSNO sysno); void rec_close (Records *p); Records rec_open (BFiles bfs, int rw, int compression_method); char *rec_strdup (const char *s, size_t *len); diff --git a/index/recindxp.h b/index/recindxp.h index b6b8a28..1e4da12 100644 --- a/index/recindxp.h +++ b/index/recindxp.h @@ -1,5 +1,5 @@ -/* $Id: recindxp.h,v 1.12 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: recindxp.h,v 1.13 2004-08-04 08:35:23 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,8 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #include "recindex.h" #include @@ -30,7 +28,7 @@ YAZ_BEGIN_CDECL #define REC_BLOCK_TYPES 2 #define REC_HEAD_MAGIC "recindex" -#define REC_VERSION 4 +#define REC_VERSION 5 struct records_info { int rw; @@ -55,16 +53,16 @@ struct records_info { struct records_head { char magic[8]; char version[4]; - int block_size[REC_BLOCK_TYPES]; - int block_free[REC_BLOCK_TYPES]; - int block_last[REC_BLOCK_TYPES]; - int block_used[REC_BLOCK_TYPES]; - int block_move[REC_BLOCK_TYPES]; + zint block_size[REC_BLOCK_TYPES]; + zint block_free[REC_BLOCK_TYPES]; + zint block_last[REC_BLOCK_TYPES]; + zint block_used[REC_BLOCK_TYPES]; + zint block_move[REC_BLOCK_TYPES]; - int total_bytes; - int index_last; - int index_free; - int no_records; + zint total_bytes; + zint index_last; + zint index_free; + zint no_records; } head; }; @@ -78,8 +76,8 @@ struct record_cache_entry { }; struct record_index_entry { - int next; /* first block of record info / next free entry */ - int size; /* size of record or 0 if free entry */ + zint next; /* first block of record info / next free entry */ + int size; /* size of record or 0 if free entry */ }; YAZ_END_CDECL diff --git a/index/recstat.c b/index/recstat.c index 59e76ce..b14f5a2 100644 --- a/index/recstat.c +++ b/index/recstat.c @@ -1,5 +1,5 @@ -/* $Id: recstat.c,v 1.8 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: recstat.c,v 1.9 2004-08-04 08:35:23 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. @@ -33,26 +33,28 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA void rec_prstat (Records records) { int i; - int total_bytes = 0; + zint total_bytes = 0; logf (LOG_LOG, - "Total records %8d", + "Total records %8" ZINT_FORMAT0, records->head.no_records); for (i = 0; i< REC_BLOCK_TYPES; i++) { - logf (LOG_LOG, "Record blocks of size %d", + logf (LOG_LOG, "Record blocks of size " ZINT_FORMAT, records->head.block_size[i]); logf (LOG_LOG, - " Used/Total/Bytes used %d/%d/%d", + " Used/Total/Bytes used " + ZINT_FORMAT "/" ZINT_FORMAT "/" ZINT_FORMAT, records->head.block_used[i], records->head.block_last[i]-1, records->head.block_used[i] * records->head.block_size[i]); total_bytes += records->head.block_used[i] * records->head.block_size[i]; } logf (LOG_LOG, - "Total size of record index in bytes %8d", + "Total size of record index in bytes %8" ZINT_FORMAT0, records->head.total_bytes); logf (LOG_LOG, - "Total size with overhead %8d", total_bytes); + "Total size with overhead %8" ZINT_FORMAT0, + total_bytes); } diff --git a/index/retrieve.c b/index/retrieve.c index 073be37..909c41f 100644 --- a/index/retrieve.c +++ b/index/retrieve.c @@ -1,4 +1,4 @@ -/* $Id: retrieve.c,v 1.21 2004-05-27 09:28:01 adam Exp $ +/* $Id: retrieve.c,v 1.22 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -82,7 +82,7 @@ void zebra_record_int_end (void *fh, off_t off) fc->offset_end = off; } -int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, +int zebra_record_fetch (ZebraHandle zh, SYSNO sysno, int score, ODR stream, oid_value input_format, Z_RecordComposition *comp, oid_value *output_format, char **rec_bufp, int *rec_lenp, char **basenamep) @@ -100,7 +100,7 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, rec = rec_get (zh->reg->records, sysno); if (!rec) { - logf (LOG_DEBUG, "rec_get fail on sysno=%d", sysno); + logf (LOG_DEBUG, "rec_get fail on sysno=" ZINT_FORMAT, sysno); *basenamep = 0; return 14; } @@ -124,7 +124,7 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, logf (LOG_WARN, "Retrieve: Cannot handle type %s", file_type); return 14; } - logf (LOG_DEBUG, "retrieve localno=%d score=%d", sysno, score); + logf (LOG_DEBUG, "retrieve localno=" ZINT_FORMAT " score=%d", sysno,score); retrieveCtrl.fh = &fc; fc.fd = -1; retrieveCtrl.fname = fname; diff --git a/index/sortidx.c b/index/sortidx.c index fe55828..e5f2435 100644 --- a/index/sortidx.c +++ b/index/sortidx.c @@ -1,5 +1,5 @@ -/* $Id: sortidx.c,v 1.8 2002-12-10 12:54:24 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: sortidx.c,v 1.9 2004-08-04 08:35:23 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. @@ -31,7 +31,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #define SORT_IDX_BLOCKSIZE 64 struct sortFileHead { - int sysno_max; + SYSNO sysno_max; }; struct sortFile { @@ -44,7 +44,7 @@ struct sortFile { struct sortIdx { BFiles bfs; int write_flag; - int sysno; + SYSNO sysno; char *entry_buf; struct sortFile *current_file; struct sortFile *files; @@ -114,7 +114,7 @@ int sortIdx_type (SortIdx si, int type) return 0; } -void sortIdx_sysno (SortIdx si, int sysno) +void sortIdx_sysno (SortIdx si, SYSNO sysno) { si->sysno = sysno; } diff --git a/index/trunc.c b/index/trunc.c index 958eb28..c166c94 100644 --- a/index/trunc.c +++ b/index/trunc.c @@ -1,4 +1,4 @@ -/* $Id: trunc.c,v 1.28 2003-03-26 16:41:48 adam Exp $ +/* $Id: trunc.c,v 1.29 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -32,7 +32,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#include #include #if NEW_TRUNC #include @@ -328,62 +327,6 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, heap_close (ti); xfree (ispt); } - - else if (zi->reg->isamd) - { - ISAMD_PP *ispt; - int i; - struct trunc_info *ti; - - ispt = (ISAMD_PP *) xmalloc (sizeof(*ispt) * (to-from)); - - ti = heap_init (to-from, sizeof(struct it_key), - key_compare_it); - for (i = to-from; --i >= 0; ) - { - logf(LOG_FATAL, "isam_d does not (currently) support truncs"); - abort(); - /*ispt[i] = isamd_pp_open (zi->reg->isamd, isam_p[from+i]); */ - if (isamd_pp_read (ispt[i], ti->tmpbuf)) - heap_insert (ti, ti->tmpbuf, i); - else - isamd_pp_close (ispt[i]); - } - while (ti->heapnum) - { - int n = ti->indx[ti->ptr[1]]; - - rset_write (result, result_rsfd, ti->heap[ti->ptr[1]]); - nn++; -#if 0 -/* section that preserve all keys */ - heap_delete (ti); - if (isamd_pp_read (ispt[n], ti->tmpbuf)) - heap_insert (ti, ti->tmpbuf, n); - else - isamd_pp_close (ispt[n]); -#else -/* section that preserve all keys with unique sysnos */ - while (1) - { - if (!isamd_pp_read (ispt[n], ti->tmpbuf)) - { - heap_delete (ti); - isamd_pp_close (ispt[n]); - break; - } - if ((*ti->cmp)(ti->tmpbuf, ti->heap[ti->ptr[1]]) > 1) - { - heap_delete (ti); - heap_insert (ti, ti->tmpbuf, n); - break; - } - } -#endif - } - heap_close (ti); - xfree (ispt); - } else if (zi->reg->isams) { ISAMS_PP *ispt; @@ -522,17 +465,6 @@ static int isamc_trunc_cmp (const void *p1, const void *p2) return d; return isc_block (i1) - isc_block (i2); } -static int isamd_trunc_cmp (const void *p1, const void *p2) -{ - ISAMD_P i1 = *(ISAMD_P*) p1; - ISAMD_P i2 = *(ISAMD_P*) p2; - int d; - - d = isamd_type (i1) - isamd_type (i2); - if (d) - return d; - return isamd_block (i1) - isamd_block (i2); -} RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, const char *term, int length, const char *flags, @@ -605,38 +537,6 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, #endif qsort (isam_p, no, sizeof(*isam_p), isamc_trunc_cmp); } - else if (zi->reg->isamd) - { - if (no == 1) - { - rset_isamd_parms parms; - - logf(LOG_FATAL, "isam_d does not (currently) support truncs"); - abort(); - /* parms.pos = *isam_p; */ - parms.is = zi->reg->isamd; - parms.rset_term = rset_term_create (term, length, flags, - term_type); - return rset_create (rset_kind_isamd, &parms); - } -#if NEW_TRUNC_NOT_DONE_FOR_ISAM_D - else if (no < 10000) - { - rset_m_or_parms parms; - - parms.key_size = sizeof(struct it_key); - parms.cmp = key_compare_it; - parms.isc = 0; - parms.isamd=zi->reg->isamd; - parms.isam_positions = isam_p; - parms.no_isam_positions = no; - parms.no_save_positions = 100000; - parms.rset_term = rset_term_create (term, length, flags); - return rset_create (rset_kind_m_or, &parms); - } -#endif - qsort (isam_p, no, sizeof(*isam_p), isamd_trunc_cmp); - } else if (zi->reg->isamb) { if (no == 1) @@ -651,7 +551,7 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, term_type); return rset_create (rset_kind_isamb, &parms); } - qsort (isam_p, no, sizeof(*isam_p), isamd_trunc_cmp); + qsort (isam_p, no, sizeof(*isam_p), isamc_trunc_cmp); } else { diff --git a/index/zebraapi.c b/index/zebraapi.c index 0b854ea..b99874f 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.120 2004-07-28 08:15:45 adam Exp $ +/* $Id: zebraapi.c,v 1.121 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -249,6 +249,10 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, reg->keys.buf_max = 0; reg->keys.buf = 0; +#if IT_KEY_NEW + reg->keys.codec_handle = iscz1_start(); +#endif + reg->sortKeys.buf = 0; reg->sortKeys.buf_max = 0; @@ -259,7 +263,6 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, reg->matchDict = 0; reg->isam = 0; reg->isamc = 0; - reg->isamd = 0; reg->isamb = 0; reg->zei = 0; reg->matchDict = 0; @@ -324,17 +327,6 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, return 0; } } - if (res_get_match (res, "isam", "d", ISAM_DEFAULT)) - { - struct ISAMD_M_s isamd_m; - - if (!(reg->isamd = isamd_open (reg->bfs, FNAME_ISAMD, - rw, key_isamd_m(res, &isamd_m)))) - { - logf (LOG_WARN, "isamd_open"); - return 0; - } - } if (res_get_match (res, "isam", "b", ISAM_DEFAULT)) { struct ISAMC_M_s isamc_m; @@ -424,8 +416,6 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg) is_close (reg->isam); if (reg->isamc) isc_close (reg->isamc); - if (reg->isamd) - isamd_close (reg->isamd); if (reg->isamb) isamb_close (reg->isamb); rec_close (®->records); @@ -439,6 +429,10 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg) xfree (reg->sortKeys.buf); xfree (reg->keys.buf); +#if IT_KEY_NEW + if (reg->keys.codec_handle) + iscz1_stop(reg->keys.codec_handle); +#endif xfree (reg->key_buf); xfree (reg->name); @@ -1028,7 +1022,7 @@ int zebra_admin_import_end (ZebraHandle zh) int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment) { - int sysno; + SYSNO sysno; int i; ASSERTZH; yaz_log(LOG_API,"zebra_admin_import_segment"); @@ -1072,7 +1066,7 @@ int zebra_admin_exchange_record (ZebraHandle zh, /* 3 = delete. Fail if does not exist */ /* 4 = update. Insert/replace */ { - int sysno = 0; + SYSNO sysno = 0; char *rinfo = 0; char recid_z[256]; ASSERTZH; @@ -1948,17 +1942,17 @@ NOTE: Now returns 0 at success and updates sysno, which is an int* int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size) { - int sysno = 0; + SYSNO sysno = 0; return zebra_update_record(zh, 0, &sysno, 0, 0, buf, buf_size, 0); } int zebra_insert_record (ZebraHandle zh, const char *recordType, - int *sysno, const char *match, const char *fname, + SYSNO *sysno, const char *match, const char *fname, const char *buf, int buf_size, int force_update) { int res; - yaz_log(LOG_API,"zebra_insert_record sysno=%d", *sysno); + yaz_log(LOG_API,"zebra_insert_record sysno=" ZINT_FORMAT, *sysno); if (buf_size < 1) buf_size = strlen(buf); @@ -1978,13 +1972,13 @@ int zebra_insert_record (ZebraHandle zh, int zebra_update_record (ZebraHandle zh, const char *recordType, - int* sysno, const char *match, const char *fname, + SYSNO* sysno, const char *match, const char *fname, const char *buf, int buf_size, int force_update) { int res; - yaz_log(LOG_API,"zebra_update_record sysno=%d", *sysno); + yaz_log(LOG_API,"zebra_update_record sysno=" ZINT_FORMAT, *sysno); if (buf_size < 1) buf_size = strlen(buf); @@ -2005,12 +1999,12 @@ int zebra_update_record (ZebraHandle zh, int zebra_delete_record (ZebraHandle zh, const char *recordType, - int *sysno, const char *match, const char *fname, + SYSNO *sysno, const char *match, const char *fname, const char *buf, int buf_size, int force_update) { int res; - yaz_log(LOG_API,"zebra_delete_record sysno=%d", *sysno); + yaz_log(LOG_API,"zebra_delete_record sysno=" ZINT_FORMAT, *sysno); if (buf_size < 1) buf_size = strlen(buf); diff --git a/index/zebrash.c b/index/zebrash.c index 4a1f992..3ad9819 100644 --- a/index/zebrash.c +++ b/index/zebrash.c @@ -1,4 +1,4 @@ -/* $Id: zebrash.c,v 1.27 2004-07-28 08:15:45 adam Exp $ +/* $Id: zebrash.c,v 1.28 2004-08-04 08:35:23 adam Exp $ Copyright (C) 2002,2003,2004 Index Data Aps @@ -347,7 +347,7 @@ static int cmd_end_trans( char *args[], WRBUF outbuff) static int cmd_record_insert( char *args[], WRBUF outbuff) { - int sysno=0; + SYSNO sysno=0; int rc; char *rec=restargs(args,1); diff --git a/index/zinfo.c b/index/zinfo.c index 67060ef..d40fbc3 100644 --- a/index/zinfo.c +++ b/index/zinfo.c @@ -1,5 +1,5 @@ -/* $Id: zinfo.c,v 1.37 2003-06-30 19:37:12 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: zinfo.c,v 1.38 2004-08-04 08:35:23 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. @@ -44,7 +44,7 @@ struct zebSUInfoB { typedef struct zebAccessObjectB *zebAccessObject; struct zebAccessObjectB { void *handle; - int sysno; + SYSNO sysno; Odr_oid *oid; zebAccessObject next; }; @@ -57,7 +57,7 @@ struct zebAccessInfoB { typedef struct { struct zebSUInfoB *SUInfo; - int sysno; + SYSNO sysno; int dirty; int readFlag; data1_node *data1_tree; @@ -67,9 +67,9 @@ struct zebDatabaseInfoB { zebAttributeDetails attributeDetails; char *databaseName; data1_node *data1_database; - int recordCount; /* records in db */ - int recordBytes; /* size of records */ - int sysno; /* sysno of database info */ + zint recordCount; /* records in db */ + zint recordBytes; /* size of records */ + SYSNO sysno; /* sysno of database info */ int readFlag; /* 1: read is needed when referenced; 0 if not */ int dirty; /* 1: database is dirty: write is needed */ struct zebDatabaseInfoB *next; @@ -84,14 +84,14 @@ struct zebraExplainAttset { struct zebraCategoryListInfo { int dirty; - int sysno; + SYSNO sysno; data1_node *data1_categoryList; }; struct zebraExplainInfo { - int ordinalSU; - int runNumber; - int dirty; + int ordinalSU; + zint runNumber; + int dirty; int write_flag; Records records; data1_handle dh; @@ -132,7 +132,7 @@ static void zebraExplain_writeCategoryList (ZebraExplainInfo zei, int key_flush); -static Record createRecord (Records records, int *sysno) +static Record createRecord (Records records, SYSNO *sysno) { Record rec; if (*sysno) @@ -437,12 +437,12 @@ ZebraExplainInfo zebraExplain_open ( memcpy ((*zdip)->databaseName, node_name->u.data.data, node_name->u.data.len); (*zdip)->databaseName[node_name->u.data.len] = '\0'; - (*zdip)->sysno = atoi_n (node_id->u.data.data, - node_id->u.data.len); + (*zdip)->sysno = atoi_zn (node_id->u.data.data, + node_id->u.data.len); (*zdip)->attributeDetails = (zebAttributeDetails) nmem_malloc (zei->nmem, sizeof(*(*zdip)->attributeDetails)); - (*zdip)->attributeDetails->sysno = atoi_n (node_aid->u.data.data, - node_aid->u.data.len); + (*zdip)->attributeDetails->sysno = atoi_zn (node_aid->u.data.data, + node_aid->u.data.len); (*zdip)->attributeDetails->readFlag = 1; (*zdip)->attributeDetails->dirty = 0; (*zdip)->attributeDetails->SUInfo = NULL; @@ -461,8 +461,8 @@ ZebraExplainInfo zebraExplain_open ( "runNumber"); np = np->child; assert (np && np->which == DATA1N_data); - zei->runNumber = atoi_n (np->u.data.data, np->u.data.len); - yaz_log (LOG_DEBUG, "read runnumber = %d", zei->runNumber); + zei->runNumber = atoi_zn (np->u.data.data, np->u.data.len); + yaz_log (LOG_DEBUG, "read runnumber=" ZINT_FORMAT, zei->runNumber); *zdip = NULL; } rec_rm (&trec); @@ -627,16 +627,16 @@ static void zebraExplain_readDatabase (ZebraExplainInfo zei, && (np = data1_search_tag (zei->dh, node_zebra->child, "recordBytes")) && np->child && np->child->which == DATA1N_data) - zdi->recordBytes = atoi_n (np->child->u.data.data, - np->child->u.data.len); + zdi->recordBytes = atoi_zn (np->child->u.data.data, + np->child->u.data.len); if ((np = data1_search_tag (zei->dh, node_dbinfo->child, "recordCount")) && (np = data1_search_tag (zei->dh, np->child, "recordCountActual")) && np->child->which == DATA1N_data) { - zdi->recordCount = atoi_n (np->child->u.data.data, - np->child->u.data.len); + zdi->recordCount = atoi_zn (np->child->u.data.data, + np->child->u.data.len); } zdi->readFlag = 0; rec_rm (&rec); @@ -900,7 +900,7 @@ static void zebraExplain_writeCategoryList (ZebraExplainInfo zei, int i; Record drec; data1_node *node_ci, *node_categoryList; - int sysno = 0; + SYSNO sysno = 0; static char *category[] = { "CategoryList", "TargetInfo", @@ -1117,13 +1117,13 @@ static void zebraExplain_writeDatabase (ZebraExplainInfo zei, /* record count */ node_count = data1_mk_tag_uni (zei->dh, zei->nmem, "recordCount", node_dbinfo); - data1_mk_tag_data_int (zei->dh, node_count, "recordCountActual", - zdi->recordCount, zei->nmem); + data1_mk_tag_data_zint (zei->dh, node_count, "recordCountActual", + zdi->recordCount, zei->nmem); /* zebra info (private) */ node_zebra = data1_mk_tag_uni (zei->dh, zei->nmem, "zebraInfo", node_dbinfo); - data1_mk_tag_data_int (zei->dh, node_zebra, + data1_mk_tag_data_zint (zei->dh, node_zebra, "recordBytes", zdi->recordBytes, zei->nmem); /* convert to "SGML" and write it */ #if ZINFO_DEBUG @@ -1275,16 +1275,16 @@ static void zebraExplain_writeTarget (ZebraExplainInfo zei, int key_flush) "database", 0 /* attr */, node_list); data1_mk_tag_data_text (zei->dh, node_db, "name", zdi->databaseName, zei->nmem); - data1_mk_tag_data_int (zei->dh, node_db, "id", - zdi->sysno, zei->nmem); - data1_mk_tag_data_int (zei->dh, node_db, "attributeDetailsId", - zdi->attributeDetails->sysno, zei->nmem); + data1_mk_tag_data_zint (zei->dh, node_db, "id", + zdi->sysno, zei->nmem); + data1_mk_tag_data_zint (zei->dh, node_db, "attributeDetailsId", + zdi->attributeDetails->sysno, zei->nmem); } data1_mk_tag_data_int (zei->dh, node_zebra, "ordinalSU", zei->ordinalSU, zei->nmem); - data1_mk_tag_data_int (zei->dh, node_zebra, "runNumber", - zei->runNumber, zei->nmem); + data1_mk_tag_data_zint (zei->dh, node_zebra, "runNumber", + zei->runNumber, zei->nmem); #if ZINFO_DEBUG data1_pr_tree (zei->dh, zei->data1_target, stderr); diff --git a/index/zrpn.c b/index/zrpn.c index adde9d4..7fefb9b 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -1,4 +1,4 @@ -/* $Id: zrpn.c,v 1.141 2004-08-03 12:15:44 heikki Exp $ +/* $Id: zrpn.c,v 1.142 2004-08-04 08:35:23 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -164,7 +164,7 @@ struct grep_info { #ifdef TERM_COUNT int *term_no; #endif - ISAMS_P *isam_p_buf; + ISAMC_P *isam_p_buf; int isam_p_size; int isam_p_indx; ZebraHandle zh; @@ -194,12 +194,12 @@ static void add_isam_p (const char *name, const char *info, { if (p->isam_p_indx == p->isam_p_size) { - ISAMS_P *new_isam_p_buf; + ISAMC_P *new_isam_p_buf; #ifdef TERM_COUNT int *new_term_no; #endif p->isam_p_size = 2*p->isam_p_size + 100; - new_isam_p_buf = (ISAMS_P *) xmalloc (sizeof(*new_isam_p_buf) * + new_isam_p_buf = (ISAMC_P *) xmalloc (sizeof(*new_isam_p_buf) * p->isam_p_size); if (p->isam_p_buf) { @@ -1365,7 +1365,7 @@ static RSET rpn_search_APT_phrase (ZebraHandle zh, { char term_dst[IT_MAX_WORD+1]; RSET rset[60], result; - int rset_no = 0; + int rset_no = 0; struct grep_info grep_info; char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type); const char *termp = termz; @@ -1787,6 +1787,7 @@ static RSET rpn_search_APT_local (ZebraHandle zh, Z_AttributesPlusTerm *zapt, RSET result; RSFD rsfd; struct it_key key; + int sys; rset_temp_parms parms; parms.rset_term = rset_term_create (termz, -1, rank_type, @@ -1797,10 +1798,19 @@ static RSET rpn_search_APT_local (ZebraHandle zh, Z_AttributesPlusTerm *zapt, result = rset_create (rset_kind_temp, &parms); rsfd = rset_open (result, RSETF_WRITE); - key.sysno = atoi (termz); + sys = atoi(termz); + if (sys <= 0) + sys = 1; +#if IT_KEY_NEW + key.mem[0] = sys; + key.mem[1] = 1; + key.len = 2; +#else + key.sysno = sys; key.seqno = 1; if (key.sysno <= 0) key.sysno = 1; +#endif rset_write (result, rsfd, &key); rset_close (result, rsfd); return result; @@ -2390,7 +2400,7 @@ RSET rpn_search (ZebraHandle zh, NMEM nmem, struct scan_info_entry { char *term; - ISAMS_P isam_p; + ISAMC_P isam_p; }; struct scan_info { @@ -2414,8 +2424,8 @@ static int scan_handle (char *name, const char *info, int pos, void *client) scan_info->list[idx].term = (char *) odr_malloc (scan_info->odr, strlen(name + len_prefix)+1); strcpy (scan_info->list[idx].term, name + len_prefix); - assert (*info == sizeof(ISAMS_P)); - memcpy (&scan_info->list[idx].isam_p, info+1, sizeof(ISAMS_P)); + assert (*info == sizeof(ISAMC_P)); + memcpy (&scan_info->list[idx].isam_p, info+1, sizeof(ISAMC_P)); return 0; } @@ -2465,11 +2475,19 @@ static void count_set (RSET r, int *count) rfd = rset_open (r, RSETF_READ); while (rset_read (r, rfd, &key, &term_index)) { +#if IT_KEY_NEW + if (key.mem[0] != psysno) + { + psysno = key.mem[0]; + (*count)++; + } +#else if (key.sysno != psysno) { psysno = key.sysno; (*count)++; } +#endif kno++; } rset_close (r, rfd); diff --git a/index/zserver.c b/index/zserver.c index c6dad72..4a44d06 100644 --- a/index/zserver.c +++ b/index/zserver.c @@ -1,4 +1,4 @@ -/* $Id: zserver.c,v 1.117 2004-08-02 10:12:06 adam Exp $ +/* $Id: zserver.c,v 1.118 2004-08-04 08:35:24 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -542,7 +542,7 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr) Z_External *rec = notToKeep->elements[i]->record; struct oident *oident = 0; Odr_oct *opaque_recid = 0; - int sysno = 0; + SYSNO sysno = 0; if (notToKeep->elements[i]->u.opaque) { diff --git a/index/zsets.c b/index/zsets.c index d543abd..a26ac40 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -1,4 +1,4 @@ -/* $Id: zsets.c,v 1.49 2004-06-13 18:45:25 adam Exp $ +/* $Id: zsets.c,v 1.50 2004-08-04 08:35:24 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -58,7 +58,7 @@ struct zebra_set { }; struct zset_sort_entry { - int sysno; + zint sysno; int score; char buf[ZSET_SORT_MAX_LEVEL][SORT_IDX_ENTRYSIZE]; }; @@ -384,7 +384,7 @@ ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name, { int position = 0; int num_i = 0; - int psysno = 0; + zint psysno = 0; int term_index; RSFD rfd; struct it_key key; @@ -396,9 +396,14 @@ ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name, rfd = rset_open (rset, RSETF_READ); while (num_i < num && rset_read (rset, rfd, &key, &term_index)) { - if (key.sysno != psysno) +#if IT_KEY_NEW + zint this_sys = key.mem[0]; +#else + zint this_sys = key.sysno; +#endif + if (this_sys != psysno) { - psysno = key.sysno; + psysno = this_sys; if (sort_info) { /* determine we alreay have this in our set */ @@ -438,7 +443,7 @@ struct sortKeyInfo { void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, struct sortKeyInfo *criteria, int num_criteria, - int sysno) + zint sysno) { struct zset_sort_entry this_entry; struct zset_sort_entry *new_entry = NULL; @@ -512,7 +517,7 @@ void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, } void resultSetInsertRank (ZebraHandle zh, struct zset_sort_info *sort_info, - int sysno, int score, int relation) + zint sysno, int score, int relation) { struct zset_sort_entry *new_entry = NULL; int i, j; @@ -603,7 +608,8 @@ void resultSetSortSingle (ZebraHandle zh, NMEM nmem, ZebraSet sset, RSET rset, Z_SortKeySpecList *sort_sequence, int *sort_status) { - int i, psysno = 0; + int i; + zint psysno = 0; struct it_key key; struct sortKeyInfo sort_criteria[3]; int num_criteria; @@ -675,10 +681,15 @@ void resultSetSortSingle (ZebraHandle zh, NMEM nmem, rfd = rset_open (rset, RSETF_READ); while (rset_read (rset, rfd, &key, &term_index)) { - if (key.sysno != psysno) +#if IT_KEY_NEW + zint this_sys = key.mem[0]; +#else + zint this_sys = key.sysno; +#endif + if (this_sys != psysno) { (sset->hits)++; - psysno = key.sysno; + psysno = this_sys; resultSetInsertSort (zh, sset, sort_criteria, num_criteria, psysno); } @@ -733,23 +744,32 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset) if (rset_read (rset, rfd, &key, &term_index)) { - int psysno = key.sysno; +#if IT_KEY_NEW + zint psysno = key.mem[0]; +#else + zint psysno = key.sysno; +#endif int score; void *handle = (*rc->begin) (zh->reg, rank_class->class_handle, rset); (zebraSet->hits)++; do { +#if IT_KEY_NEW + zint this_sys = key.mem[0]; +#else + zint this_sys = key.sysno; +#endif kno++; - if (key.sysno != psysno) + if (this_sys != psysno) { score = (*rc->calc) (handle, psysno); resultSetInsertRank (zh, sort_info, psysno, score, 'A'); (zebraSet->hits)++; - psysno = key.sysno; + psysno = this_sys; } - (*rc->add) (handle, key.seqno, term_index); + (*rc->add) (handle, this_sys, term_index); } while (rset_read (rset, rfd, &key, &term_index)); score = (*rc->calc) (handle, psysno); diff --git a/index/zvrank.c b/index/zvrank.c index 4c1c4b7..4322dda 100644 --- a/index/zvrank.c +++ b/index/zvrank.c @@ -1,4 +1,4 @@ -/* $Id: zvrank.c,v 1.7 2004-06-13 18:44:57 adam Exp $ +/* $Id: zvrank.c,v 1.8 2004-08-04 08:35:24 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -757,7 +757,7 @@ static void zv_add (void *rsi, int seqno, int i) { * score should be between 0 and 1000. If score cannot be obtained * -1 should be returned. */ -static int zv_calc (void *rsi, int sysno) +static int zv_calc (void *rsi, zint sysno) { int i, veclen; int score=0; @@ -776,7 +776,7 @@ static int zv_calc (void *rsi, int sysno) dscore=rs->sim_fct(rs->qdoc, rs->rdoc); } score = dscore * 1000; - yaz_log (LOG_LOG, "sysno=%d score=%d", sysno, score); + yaz_log (LOG_LOG, "sysno=" ZINT_FORMAT " score=%d", sysno, score); if (score > 1000) /* should not happen */ score = 1000; return score; diff --git a/isamb/isamb.c b/isamb/isamb.c index 2ee7cb1..ebf0bd2 100644 --- a/isamb/isamb.c +++ b/isamb/isamb.c @@ -1,4 +1,4 @@ -/* $Id: isamb.c,v 1.47 2004-08-03 14:54:41 heikki Exp $ +/* $Id: isamb.c,v 1.48 2004-08-04 08:35:24 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -31,11 +31,11 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #endif struct ISAMB_head { - int first_block; - int last_block; + zint first_block; + zint last_block; int block_size; int block_max; - int free_list; + zint free_list; }; #define ISAMB_DATA_OFFSET 3 @@ -56,7 +56,7 @@ struct ISAMB_head { #define CAT_NO 4 /* ISAMB_PTR_CODEC=1 var, =0 fixed */ -#define ISAMB_PTR_CODEC 0 +#define ISAMB_PTR_CODEC 0 struct ISAMB_cache_entry { ISAMB_P pos; @@ -119,7 +119,7 @@ struct ISAMB_PP_s { #if ISAMB_PTR_CODEC -static void encode_ptr (char **dst, unsigned pos) +static void encode_ptr (char **dst, zint pos) { unsigned char *bp = (unsigned char*) *dst; @@ -132,7 +132,7 @@ static void encode_ptr (char **dst, unsigned pos) *dst = (char *) bp; } #else -static void encode_ptr (char **dst, unsigned pos) +static void encode_ptr (char **dst, zint pos) { memcpy(*dst, &pos, sizeof(pos)); (*dst) += sizeof(pos); @@ -140,23 +140,23 @@ static void encode_ptr (char **dst, unsigned pos) #endif #if ISAMB_PTR_CODEC -static void decode_ptr (char **src1, int *pos) +static void decode_ptr (const char **src1, zint *pos) { - unsigned char **src = (unsigned char **) src1; - unsigned d = 0; + const unsigned char **src = (const unsigned char **) src1; + zint d = 0; unsigned char c; unsigned r = 0; while (((c = *(*src)++) & 128)) { - d += ((c & 127) << r); + d += ((zint) (c & 127) << r); r += 7; } - d += (c << r); + d += ((zint) c << r); *pos = d; } #else -static void decode_ptr (char **src, int *pos) +static void decode_ptr (const char **src, zint *pos) { memcpy (pos, *src, sizeof(*pos)); (*src) += sizeof(*pos); @@ -355,14 +355,15 @@ static struct ISAMB_block *open_block (ISAMB b, ISAMC_P pos) p->size = (p->buf[1] + 256 * p->buf[2]) - ISAMB_DATA_OFFSET; if (p->size < 0) { - yaz_log (LOG_FATAL, "Bad block size %d in pos=%d\n", p->size, pos); + yaz_log (LOG_FATAL, "Bad block size %d in pos=" ZINT_FORMAT "\n", + p->size, pos); } assert (p->size >= 0); p->offset = 0; p->dirty = 0; p->deleted = 0; - p->decodeClientData = (*b->method->code_start)(ISAMC_DECODE); - yaz_log (LOG_DEBUG, "isamb_open_block: Opened block %d ofs=%d",pos, p->offset); + p->decodeClientData = (*b->method->codec.start)(); + yaz_log (LOG_DEBUG, "isamb_open_block: Opened block " ZINT_FORMAT " ofs=%d",pos, p->offset); return p; } @@ -393,7 +394,7 @@ struct ISAMB_block *new_block (ISAMB b, int leaf, int cat) abort (); } } - yaz_log (b->log_freelist, "got block %d from freelist %d:%d", p->pos, + yaz_log (b->log_freelist, "got block " ZINT_FORMAT " from freelist %d:" ZINT_FORMAT, p->pos, cat, p->pos/CAT_MAX); memcpy (&b->file[cat].head.free_list, p->buf, sizeof(int)); } @@ -406,7 +407,7 @@ struct ISAMB_block *new_block (ISAMB b, int leaf, int cat) p->dirty = 1; p->deleted = 0; p->offset = 0; - p->decodeClientData = (*b->method->code_start)(ISAMC_DECODE); + p->decodeClientData = (*b->method->codec.start)(); return p; } @@ -431,17 +432,17 @@ static void check_block (ISAMB b, struct ISAMB_block *p) { /* sanity check */ char *startp = p->bytes; - char *src = startp; + const char *src = startp; char *endp = p->bytes + p->size; - int pos; + ISAMB_P pos; decode_ptr (&src, &pos); assert ((pos&CAT_MASK) == p->cat); while (src != endp) { - int item_len; + zint item_len; decode_ptr (&src, &item_len); - assert (item_len > 0 && item_len < 30); + assert (item_len > 0 && item_len < 80); src += item_len; decode_ptr (&src, &pos); assert ((pos&CAT_MASK) == p->cat); @@ -455,7 +456,7 @@ void close_block (ISAMB b, struct ISAMB_block *p) return; if (p->deleted) { - yaz_log (b->log_freelist, "release block %d from freelist %d:%d", + yaz_log (b->log_freelist, "release block " ZINT_FORMAT " from freelist %d:" ZINT_FORMAT, p->pos, p->cat, p->pos/CAT_MAX); memcpy (p->buf, &b->file[p->cat].head.free_list, sizeof(int)); b->file[p->cat].head.free_list = p->pos; @@ -479,7 +480,7 @@ void close_block (ISAMB b, struct ISAMB_block *p) bf_write (b->file[p->cat].bf, p->pos/CAT_MAX, 0, 0, p->buf); } } - (*b->method->code_stop)(ISAMC_DECODE, p->decodeClientData); + (*b->method->codec.stop)(p->decodeClientData); xfree (p->buf); xfree (p); } @@ -489,17 +490,17 @@ int insert_sub (ISAMB b, struct ISAMB_block **p, ISAMC_I *stream, struct ISAMB_block **sp, void *sub_item, int *sub_size, - void *max_item); + const void *max_item); int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item, int *mode, ISAMC_I *stream, struct ISAMB_block **sp, - void *split_item, int *split_size, void *last_max_item) + void *split_item, int *split_size, const void *last_max_item) { char *startp = p->bytes; - char *src = startp; + const char *src = startp; char *endp = p->bytes + p->size; - int pos; + ISAMB_P pos; struct ISAMB_block *sub_p1 = 0, *sub_p2 = 0; char sub_item[DST_ITEM_MAX]; int sub_size; @@ -511,9 +512,9 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item, decode_ptr (&src, &pos); while (src != endp) { - int item_len; + zint item_len; int d; - char *src0 = src; + const char *src0 = src; decode_ptr (&src, &item_len); d = (*b->method->compare_item)(src, lookahead_item); if (d > 0) @@ -542,7 +543,7 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item, char dst_buf[DST_BUF_SIZE]; char *dst = dst_buf; - assert (sub_size < 30 && sub_size > 1); + assert (sub_size < 80 && sub_size > 1); memcpy (dst, startp, src - startp); @@ -567,8 +568,9 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item, } else { + zint split_size_tmp; int p_new_size; - char *half; + const char *half; src = dst_buf; endp = dst; @@ -576,14 +578,17 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item, decode_ptr (&src, &pos); while (src <= half) { - decode_ptr (&src, split_size); + decode_ptr (&src, &split_size_tmp); + *split_size = split_size_tmp; + src += *split_size; decode_ptr (&src, &pos); } p_new_size = src - dst_buf; memcpy (p->bytes, dst_buf, p_new_size); - decode_ptr (&src, split_size); + decode_ptr (&src, &split_size_tmp); + *split_size = split_size_tmp; memcpy (split_item, src, *split_size); src += *split_size; @@ -600,19 +605,19 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item, return more; } - int insert_leaf (ISAMB b, struct ISAMB_block **sp1, void *lookahead_item, int *lookahead_mode, ISAMC_I *stream, struct ISAMB_block **sp2, void *sub_item, int *sub_size, - void *max_item) + const void *max_item) { struct ISAMB_block *p = *sp1; - char *src = 0, *endp = 0; + char *endp = 0; + const char *src = 0; char dst_buf[DST_BUF_SIZE], *dst = dst_buf; int new_size; - void *c1 = (*b->method->code_start)(ISAMC_DECODE); - void *c2 = (*b->method->code_start)(ISAMC_ENCODE); + void *c1 = (*b->method->codec.start)(); + void *c2 = (*b->method->codec.start)(); int more = 1; int quater = b->file[b->no_cat-1].head.block_max / CAT_MAX; char *cut = dst_buf + quater * 2; @@ -629,10 +634,10 @@ int insert_leaf (ISAMB b, struct ISAMB_block **sp1, void *lookahead_item, src = p->bytes; endp = p->bytes + p->size; - (*b->method->code_item)(ISAMC_DECODE, c1, &file_item, &src); + (*b->method->codec.decode)(c1, &file_item, &src); while (1) { - char *dst_item = 0; + const char *dst_item = 0; char *dst_0 = dst; char *lookahead_next; int d = -1; @@ -657,18 +662,19 @@ int insert_leaf (ISAMB b, struct ISAMB_block **sp1, void *lookahead_item, } else if (!half1 && dst > cut) { - char *dst_item_0 = dst_item; + const char *dst_item_0 = dst_item; half1 = dst; /* candidate for splitting */ - (*b->method->code_item)(ISAMC_ENCODE, c2, &dst, &dst_item); + (*b->method->codec.encode)(c2, &dst, &dst_item); cut_item_size = dst_item - dst_item_0; + assert(cut_item_size > 0); memcpy (cut_item_buf, dst_item_0, cut_item_size); half2 = dst; } else - (*b->method->code_item)(ISAMC_ENCODE, c2, &dst, &dst_item); + (*b->method->codec.encode)(c2, &dst, &dst_item); if (d > 0) { if (dst > maxp) @@ -708,21 +714,22 @@ int insert_leaf (ISAMB b, struct ISAMB_block **sp1, void *lookahead_item, if (src == endp) break; file_item = file_item_buf; - (*b->method->code_item)(ISAMC_DECODE, c1, &file_item, &src); + (*b->method->codec.decode)(c1, &file_item, &src); } else { if (src == endp) break; file_item = file_item_buf; - (*b->method->code_item)(ISAMC_DECODE, c1, &file_item, &src); + (*b->method->codec.decode)(c1, &file_item, &src); } } } maxp = dst_buf + b->file[b->no_cat-1].head.block_max + quater; while (lookahead_item) { - char *dst_item = lookahead_item; + char *dst_item; + const char *src = lookahead_item; char *dst_0 = dst; if (max_item && @@ -738,18 +745,19 @@ int insert_leaf (ISAMB b, struct ISAMB_block **sp1, void *lookahead_item, } else if (!half1 && dst > cut) { - char *dst_item_0 = dst_item; + const char *src_0 = src; half1 = dst; /* candidate for splitting */ - (*b->method->code_item)(ISAMC_ENCODE, c2, &dst, &dst_item); + (*b->method->codec.encode)(c2, &dst, &src); - cut_item_size = dst_item - dst_item_0; - memcpy (cut_item_buf, dst_item_0, cut_item_size); + cut_item_size = src - src_0; + assert(cut_item_size > 0); + memcpy (cut_item_buf, src_0, cut_item_size); half2 = dst; } else - (*b->method->code_item)(ISAMC_ENCODE, c2, &dst, &dst_item); + (*b->method->codec.encode)(c2, &dst, &src); if (dst > maxp) { @@ -789,23 +797,25 @@ int insert_leaf (ISAMB b, struct ISAMB_block **sp1, void *lookahead_item, if (new_size > b->file[p->cat].head.block_max) { char *first_dst; - char *cut_item = cut_item_buf; + const char *cut_item = cut_item_buf; assert (half1); assert (half2); - /* first half */ + assert(cut_item_size > 0); + + /* first half */ p->size = half1 - dst_buf; memcpy (p->bytes, dst_buf, half1 - dst_buf); /* second half */ *sp2 = new_leaf (b, p->cat); - (*b->method->code_reset)(c2); + (*b->method->codec.reset)(c2); first_dst = (*sp2)->bytes; - (*b->method->code_item)(ISAMC_ENCODE, c2, &first_dst, &cut_item); + (*b->method->codec.encode)(c2, &first_dst, &cut_item); memcpy (first_dst, half2, dst - half2); @@ -820,8 +830,8 @@ int insert_leaf (ISAMB b, struct ISAMB_block **sp1, void *lookahead_item, memcpy (p->bytes, dst_buf, dst - dst_buf); p->size = new_size; } - (*b->method->code_stop)(ISAMC_DECODE, c1); - (*b->method->code_stop)(ISAMC_ENCODE, c2); + (*b->method->codec.stop)(c1); + (*b->method->codec.stop)(c2); *sp1 = p; return more; } @@ -831,7 +841,7 @@ int insert_sub (ISAMB b, struct ISAMB_block **p, void *new_item, ISAMC_I *stream, struct ISAMB_block **sp, void *sub_item, int *sub_size, - void *max_item) + const void *max_item) { if (!*p || (*p)->leaf) return insert_leaf (b, p, new_item, mode, stream, sp, sub_item, @@ -851,9 +861,9 @@ int isamb_unlink (ISAMB b, ISAMC_P pos) p1->deleted = 1; if (!p1->leaf) { - int sub_p; - int item_len; - char *src = p1->bytes + p1->offset; + zint sub_p; + zint item_len; + const char *src = p1->bytes + p1->offset; decode_ptr(&src, &sub_p); isamb_unlink(b, sub_p); @@ -870,7 +880,7 @@ int isamb_unlink (ISAMB b, ISAMC_P pos) return 0; } -int isamb_merge (ISAMB b, ISAMC_P pos, ISAMC_I *stream) +ISAMB_P isamb_merge (ISAMB b, ISAMC_P pos, ISAMC_I *stream) { char item_buf[DST_ITEM_MAX]; char *item_ptr; @@ -906,7 +916,7 @@ int isamb_merge (ISAMB b, ISAMC_P pos, ISAMC_I *stream) char *dst = p2->bytes + p2->size; encode_ptr (&dst, p->pos); - assert (sub_size < 20); + assert (sub_size < 40); encode_ptr (&dst, sub_size); memcpy (dst, sub_item, sub_size); dst += sub_size; @@ -944,7 +954,7 @@ ISAMB_PP isamb_pp_open_x (ISAMB isamb, ISAMB_P pos, int *level) while (1) { struct ISAMB_block *p = open_block (isamb, pos); - char *src = p->bytes + p->offset; + const char *src = p->bytes + p->offset; pp->block[pp->level] = p; pp->total_size += p->size; @@ -1019,18 +1029,17 @@ static void isamb_dump_r (ISAMB b, ISAMB_P pos, void (*pr)(const char *str), if (pos) { struct ISAMB_block *p = open_block (b, pos); - sprintf(prefix_str, "%*s %d cat=%d size=%d max=%d", level*2, "", + sprintf(prefix_str, "%*s " ZINT_FORMAT " cat=%d size=%d max=%d", level*2, "", pos, p->cat, p->size, b->file[p->cat].head.block_max); (*pr)(prefix_str); - sprintf(prefix_str, "%*s %d", level*2, "", pos); + sprintf(prefix_str, "%*s " ZINT_FORMAT, level*2, "", pos); if (p->leaf) { while (p->offset < p->size) { - char *src = p->bytes + p->offset; + const char *src = p->bytes + p->offset; char *dst = buf; - (*b->method->code_item)(ISAMC_DECODE, p->decodeClientData, - &dst, &src); + (*b->method->codec.decode)(p->decodeClientData, &dst, &src); (*b->method->log_item)(LOG_DEBUG, buf, prefix_str); p->offset = src - (char*) p->bytes; } @@ -1038,9 +1047,9 @@ static void isamb_dump_r (ISAMB b, ISAMB_P pos, void (*pr)(const char *str), } else { - char *src = p->bytes + p->offset; - int sub; - int item_len; + const char *src = p->bytes + p->offset; + ISAMB_P sub; + zint item_len; decode_ptr (&src, &sub); p->offset = src - (char*) p->bytes; @@ -1125,7 +1134,7 @@ int isamb_pp_read (ISAMB_PP pp, void *buf) assert (p->offset < p->size); assert (p->leaf); src = p->bytes + p->offset; - (*pp->isamb->method->code_item)(ISAMC_DECODE, p->decodeClientData, + (*pp->isamb->method->codec.code_item)(ISAMC_DECODE, p->decodeClientData, &dst, &src); p->offset = src - (char*) p->bytes; /* key_logdump_txt(LOG_DEBUG,buf, "isamb_pp_read returning 1"); */ @@ -1135,7 +1144,7 @@ int isamb_pp_read (ISAMB_PP pp, void *buf) #else int isamb_pp_read (ISAMB_PP pp, void *buf) { - return isamb_pp_forward(pp,buf,0); + return isamb_pp_forward(pp, buf, 0); } #endif @@ -1153,8 +1162,8 @@ static int isamb_pp_on_right_node(ISAMB_PP pp, int level, const void *untilbuf) /* call with pp->level to begin with */ struct ISAMB_block *p; int cmp; - char *src; - int item_len; + const char *src; + zint item_len; assert(level>=0); if ( level == 0) { #if ISAMB_DEBUG @@ -1169,10 +1178,10 @@ static int isamb_pp_on_right_node(ISAMB_PP pp, int level, const void *untilbuf) { assert(p->offset>0); src=p->bytes + p->offset; - decode_ptr(&src,&item_len); + decode_ptr(&src, &item_len); #if ISAMB_DEBUG - (*pp->isamb->method->log_item)(LOG_DEBUG,untilbuf,"on_leaf: until"); - (*pp->isamb->method->log_item)(LOG_DEBUG,src,"on_leaf: value"); + (*pp->isamb->method->codec.log_item)(LOG_DEBUG,untilbuf,"on_leaf: until"); + (*pp->isamb->method->codec.log_item)(LOG_DEBUG,src,"on_leaf: value"); #endif cmp=(*pp->isamb->method->compare_item)(untilbuf,src); if (cmp<2) { @@ -1203,7 +1212,7 @@ static int isamb_pp_read_on_leaf(ISAMB_PP pp, void *buf) { /* reads the next item on the current leaf, returns 0 if end of leaf*/ struct ISAMB_block *p = pp->block[pp->level]; char *dst; - char *src; + const char *src; assert(pp); assert(buf); if (p->offset == p->size) { @@ -1214,12 +1223,11 @@ static int isamb_pp_read_on_leaf(ISAMB_PP pp, void *buf) } src=p->bytes + p->offset; dst=buf; - (*pp->isamb->method->code_item) - (ISAMC_DECODE, p->decodeClientData,&dst, &src); + (*pp->isamb->method->codec.decode)(p->decodeClientData,&dst, &src); p->offset = src - (char*) p->bytes; /* #if ISAMB_DEBUG - (*pp->isamb->method->log_item)(LOG_DEBUG, buf, "read_on_leaf returning 1"); + (*pp->isamb->method->codec.log_item)(LOG_DEBUG, buf, "read_on_leaf returning 1"); #endif */ return 1; @@ -1250,12 +1258,12 @@ static int isamb_pp_forward_on_leaf(ISAMB_PP pp, void *buf, const void *untilbuf } } /* forward_on_leaf */ -static int isamb_pp_climb_level(ISAMB_PP pp, int *pos) +static int isamb_pp_climb_level(ISAMB_PP pp, ISAMB_P *pos) { /* climbs higher in the tree, until finds a level with data left */ /* returns the node to (consider to) descend to in *pos) */ struct ISAMB_block *p = pp->block[pp->level]; - char *src; - int item_len; + const char *src; + zint item_len; #if ISAMB_DEBUG logf(LOG_DEBUG,"isamb_pp_climb_level starting " "at level %d node %d ofs=%d sz=%d", @@ -1315,10 +1323,10 @@ static int isamb_pp_forward_unode(ISAMB_PP pp, int pos, const void *untilbuf) /* parent node, but that gets messy. Presumably the cost is */ /* pretty low anyway */ struct ISAMB_block *p = pp->block[pp->level]; - char *src=p->bytes + p->offset; - int item_len; + const char *src=p->bytes + p->offset; + zint item_len; int cmp; - int nxtpos; + zint nxtpos; #if ISAMB_DEBUG int skips=0; logf(LOG_DEBUG,"isamb_pp_forward_unode starting " @@ -1365,10 +1373,10 @@ static int isamb_pp_forward_unode(ISAMB_PP pp, int pos, const void *untilbuf) } /* forward_unode */ -static void isamb_pp_descend_to_leaf(ISAMB_PP pp, int pos, const void *untilbuf) +static void isamb_pp_descend_to_leaf(ISAMB_PP pp, ISAMB_P pos, const void *untilbuf) { /* climbs down the tree, from pos, to the leftmost leaf */ struct ISAMB_block *p = pp->block[pp->level]; - char *src; + const char *src; assert(!p->leaf); #if ISAMB_DEBUG logf(LOG_DEBUG,"isamb_pp_descend_to_leaf " @@ -1404,7 +1412,7 @@ static void isamb_pp_descend_to_leaf(ISAMB_PP pp, int pos, const void *untilbuf) static int isamb_pp_find_next_leaf(ISAMB_PP pp) { /* finds the next leaf by climbing up and down */ - int pos; + ISAMB_P pos; if (!isamb_pp_climb_level(pp,&pos)) return 0; isamb_pp_descend_to_leaf(pp, pos,0); @@ -1413,7 +1421,7 @@ static int isamb_pp_find_next_leaf(ISAMB_PP pp) static int isamb_pp_climb_desc(ISAMB_PP pp, void *buf, const void *untilbuf) { /* climbs up and descends to a leaf where values >= *untilbuf are found */ - int pos; + ISAMB_P pos; #if ISAMB_DEBUG struct ISAMB_block *p = pp->block[pp->level]; logf(LOG_DEBUG,"isamb_pp_climb_desc starting " @@ -1523,7 +1531,7 @@ int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf) * in the node just read. */ char *dst = buf; - char *src; + const char *src; struct ISAMB_block *p = pp->block[pp->level]; int cmp; int item_len; @@ -1535,8 +1543,8 @@ int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf) #if ISAMB_DEBUG logf(LOG_DEBUG,"isamb_pp_forward starting [%p] p=%d",pp,p->pos); - (*pp->isamb->method->log_item)(LOG_DEBUG, untilbuf, "until"); - (*pp->isamb->method->log_item)(LOG_DEBUG, buf, "buf"); + (*pp->isamb->method->codec.log_item)(LOG_DEBUG, untilbuf, "until"); + (*pp->isamb->method->codec.log_item)(LOG_DEBUG, buf, "buf"); #endif while (1) @@ -1571,7 +1579,7 @@ int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf) src = p->bytes + p->offset; decode_ptr(&src, &item_len); #if ISAMB_DEBUG - (*pp->isamb->method->log_item)(LOG_DEBUG, src, + (*pp->isamb->method->codec.log_item)(LOG_DEBUG, src, " isamb_pp_forward " "climb skipping old key"); #endif @@ -1596,7 +1604,7 @@ int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf) logf(LOG_DEBUG,"isamb_pp_forward (B) on a high node. " "ofs=%d sz=%d nxtpos=%d ", p->offset,p->size,pos); - (*pp->isamb->method->log_item)(LOG_DEBUG, src, ""); + (*pp->isamb->method->codec.log_item)(LOG_DEBUG, src, ""); #endif if (untilbuf) cmp=(*pp->isamb->method->compare_item)(untilbuf,src); @@ -1655,7 +1663,7 @@ int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf) assert (p->offset < p->size); src = p->bytes + p->offset; dst=buf; - (*pp->isamb->method->code_item)(ISAMC_DECODE, p->decodeClientData, + (*pp->isamb->method->codec.decode)(p->decodeClientData, &dst, &src); p->offset = src - (char*) p->bytes; if (untilbuf) @@ -1665,19 +1673,19 @@ int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf) #if ISAMB_DEBUG logf(LOG_DEBUG,"isamb_pp_forward on a leaf. cmp=%d", cmp); - (*pp->isamb->method->log_item)(LOG_DEBUG, buf, ""); + (*pp->isamb->method->codec.log_item)(LOG_DEBUG, buf, ""); #endif if (cmp <2) { #if ISAMB_DEBUG if (untilbuf) { - (*pp->isamb->method->log_item)( + (*pp->isamb->method->codec.log_item)( LOG_DEBUG, buf, "isamb_pp_forward returning 1"); } else { - (*pp->isamb->method->log_item)( + (*pp->isamb->method->codec.log_item)( LOG_DEBUG, buf, "isamb_pp_read returning 1 (fwd)"); } #endif @@ -1696,7 +1704,7 @@ int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf) int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilb) { char *dst = buf; - char *src; + const char *src; struct ISAMB_block *p = pp->block[pp->level]; if (!p) return 0; @@ -1777,8 +1785,7 @@ again: { char *dst0 = dst; src = p->bytes + p->offset; - (*pp->isamb->method->code_item)(ISAMC_DECODE, p->decodeClientData, - &dst, &src); + (*pp->isamb->method->codec.decode)(p->decodeClientData, &dst, &src); p->offset = src - (char*) p->bytes; if (!untilb || (*pp->isamb->method->compare_item)(untilb, dst0) <= 1) break; @@ -1800,7 +1807,7 @@ static void isamb_pp_leaf_pos( ISAMB_PP pp, int *current, int *total, void *dummybuf ) { struct ISAMB_block *p = pp->block[pp->level]; - char *src=p->bytes; + const char *src=p->bytes; char *end=p->bytes+p->size; char *cur=p->bytes+p->offset; char *dst; @@ -1812,8 +1819,7 @@ static void isamb_pp_leaf_pos( ISAMB_PP pp, while(src < end) { dst=dummybuf; - (*pp->isamb->method->code_item) - (ISAMC_DECODE, p->decodeClientData,&dst, &src); + (*pp->isamb->method->codec.decode)(p->decodeClientData,&dst, &src); assert(dst<(char*) dummybuf+100); /*FIXME */ (*total)++; if (src<=cur) @@ -1828,25 +1834,25 @@ static void isamb_pp_upper_pos( ISAMB_PP pp, int *current, int *total, int size, int level ) { /* estimates total/current occurrences from here up, excl leaf */ struct ISAMB_block *p = pp->block[level]; - char *src=p->bytes; + const char *src=p->bytes; char *end=p->bytes+p->size; char *cur=p->bytes+p->offset; - int item_size; - int child; + zint item_size; + ISAMB_P child; assert(level>=0); assert(!p->leaf); logf(LOG_DEBUG,"isamb_pp_upper_pos at beginning l=%d " - "cur=%d tot=%d ofs=%d sz=%d pos=%d", + "cur=%d tot=%d ofs=%d sz=%d pos=" ZINT_FORMAT, level, *current, *total, p->offset, p->size, p->pos); assert (p->offset <= p->size); - decode_ptr (&src, &child ); /* first child */ + decode_ptr (&src, &child ); /* first child */ while(src < end) { if (src!=cur) { *total += size; if (src < cur) *current +=size; } - decode_ptr (&src, &item_size ); + decode_ptr (&src, &item_size ); assert(src+item_size<=end); src += item_size; decode_ptr (&src, &child ); diff --git a/isamb/tstisamb.c b/isamb/tstisamb.c index 253bc1f..3ea1d92 100644 --- a/isamb/tstisamb.c +++ b/isamb/tstisamb.c @@ -1,4 +1,4 @@ -/* $Id: tstisamb.c,v 1.7 2004-08-03 14:54:41 heikki Exp $ +/* $Id: tstisamb.c,v 1.8 2004-08-04 08:35:24 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -47,12 +47,12 @@ int compare_item(const void *a, const void *b) return ia - ib; } -void *code_start(int mode) +void *code_start() { return 0; } -void code_item(int mode, void *p, char **dst, char **src) +void code_item(void *p, char **dst, const char **src) { memcpy (*dst, *src, sizeof(int)); (*dst) += sizeof(int); @@ -62,7 +62,7 @@ void code_item(int mode, void *p, char **dst, char **src) void code_reset(void *p) { } -void code_stop(int mode, void *p) +void code_stop(void *p) { } @@ -199,10 +199,11 @@ int main(int argc, char **argv) /* setup method (attributes) */ method.compare_item = compare_item; method.log_item = log_item; - method.code_start = code_start; - method.code_item = code_item; - method.code_reset = code_reset; - method.code_stop = code_stop; + method.codec.start = code_start; + method.codec.encode = code_item; + method.codec.decode = code_item; + method.codec.reset = code_reset; + method.codec.stop = code_stop; /* create block system */ bfs = bfs_create(0, 0); diff --git a/isamc/Makefile.am b/isamc/Makefile.am index 7e13e43..debc464 100644 --- a/isamc/Makefile.am +++ b/isamc/Makefile.am @@ -1,8 +1,8 @@ -## $Id: Makefile.am,v 1.4 2004-06-16 20:49:18 adam Exp $ +## $Id: Makefile.am,v 1.5 2004-08-04 08:35:24 adam Exp $ noinst_LIBRARIES = libisamc.a -libisamc_a_SOURCES = isamc.c isamd.c merge.c merge-d.c isamc-p.h isamd-p.h +libisamc_a_SOURCES = isamc.c merge.c isamc-p.h AM_CPPFLAGS = -I$(srcdir)/../include -I$(srcdir)/../index $(YAZINC) diff --git a/isamc/isamc-p.h b/isamc/isamc-p.h index d2af549..02d212a 100644 --- a/isamc/isamc-p.h +++ b/isamc/isamc-p.h @@ -1,5 +1,5 @@ -/* $Id: isamc-p.h,v 1.9 2003-06-23 15:36:11 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: isamc-p.h,v 1.10 2004-08-04 08:35:24 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. @@ -25,13 +25,11 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#ifdef __cplusplus -extern "C" { -#endif +YAZ_BEGIN_CDECL typedef struct { - int lastblock; - int freelist; + zint lastblock; + zint freelist; } ISAMC_head; typedef unsigned ISAMC_BLOCK_SIZE; @@ -76,22 +74,33 @@ struct ISAMC_PP_s { ISAMC_BLOCK_SIZE offset; ISAMC_BLOCK_SIZE size; int cat; - int pos; - int next; + zint pos; + zint next; ISAMC is; void *decodeClientData; int deleteFlag; - int numKeys; + zint numKeys; }; -#define ISAMC_BLOCK_OFFSET_N (sizeof(int)+sizeof(ISAMC_BLOCK_SIZE)) -#define ISAMC_BLOCK_OFFSET_1 (sizeof(int)+sizeof(ISAMC_BLOCK_SIZE)+sizeof(int)) -int isc_alloc_block (ISAMC is, int cat); -void isc_release_block (ISAMC is, int cat, int pos); -int isc_read_block (ISAMC is, int cat, int pos, char *dst); -int isc_write_block (ISAMC is, int cat, int pos, char *src); +/* + first block consists of + next pointer : zint + size : ISAMC_BLOCK_SIZE (int) + numkeys : zint + data + other blocks consists of + next pointer : zint + size : ISAMC_BLOCK_SIZE (int) + data +*/ +#define ISAMC_BLOCK_OFFSET_1 (sizeof(zint)+sizeof(ISAMC_BLOCK_SIZE)+sizeof(zint)) +#define ISAMC_BLOCK_OFFSET_N (sizeof(zint)+sizeof(ISAMC_BLOCK_SIZE)) + +zint isc_alloc_block (ISAMC is, int cat); +void isc_release_block (ISAMC is, int cat, zint pos); +int isc_read_block (ISAMC is, int cat, zint pos, char *dst); +int isc_write_block (ISAMC is, int cat, zint pos, char *src); + +YAZ_END_CDECL -#ifdef __cplusplus -} -#endif diff --git a/isamc/isamc.c b/isamc/isamc.c index 9374da3..0a0d53c 100644 --- a/isamc/isamc.c +++ b/isamc/isamc.c @@ -1,5 +1,5 @@ -/* $Id: isamc.c,v 1.24 2004-06-01 12:56:39 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: isamc.c,v 1.25 2004-08-04 08:35:24 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,8 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - /* * TODO: * Reduction to lower categories in isc_merge @@ -38,7 +36,7 @@ static void flush_block (ISAMC is, int cat); static void release_fc (ISAMC is, int cat); static void init_fc (ISAMC is, int cat); -#define ISAMC_FREELIST_CHUNK 1 +#define ISAMC_FREELIST_CHUNK 0 #define SMALL_TEST 0 @@ -50,7 +48,7 @@ void isc_getmethod (ISAMC_M *m) { 32, 28, 0, 3 }, { 64, 54, 30, 0 }, #else - { 32, 26, 20, 10 }, + { 64, 56, 40, 5 }, { 128, 120, 100, 10 }, { 512, 490, 350, 10 }, { 2048, 1900, 1700, 10 }, @@ -60,10 +58,11 @@ void isc_getmethod (ISAMC_M *m) }; m->filecat = def_cat; - m->code_start = NULL; - m->code_item = NULL; - m->code_stop = NULL; - m->code_reset = NULL; + m->codec.start = NULL; + m->codec.decode = NULL; + m->codec.encode = NULL; + m->codec.stop = NULL; + m->codec.reset = NULL; m->compare_item = NULL; m->log_item = NULL; @@ -133,7 +132,7 @@ ISAMC isc_open (BFiles bfs, const char *name, int writeflag, ISAMC_M *method) } is->files[i].alloc_entries_num = 0; is->files[i].alloc_entries_max = - is->method->filecat[i].bsize / sizeof(int) - 1; + is->method->filecat[i].bsize / sizeof(zint) - 1; is->files[i].alloc_buf = (char *) xmalloc (is->method->filecat[i].bsize); is->files[i].no_writes = 0; @@ -154,7 +153,7 @@ ISAMC isc_open (BFiles bfs, const char *name, int writeflag, ISAMC_M *method) return is; } -int isc_block_used (ISAMC is, int type) +zint isc_block_used (ISAMC is, int type) { if (type < 0 || type >= is->no_files) return -1; @@ -217,30 +216,30 @@ int isc_close (ISAMC is) return 0; } -int isc_read_block (ISAMC is, int cat, int pos, char *dst) +int isc_read_block (ISAMC is, int cat, zint pos, char *dst) { ++(is->files[cat].no_reads); return bf_read (is->files[cat].bf, pos, 0, 0, dst); } -int isc_write_block (ISAMC is, int cat, int pos, char *src) +int isc_write_block (ISAMC is, int cat, zint pos, char *src) { ++(is->files[cat].no_writes); if (is->method->debug > 2) - logf (LOG_LOG, "isc: write_block %d %d", cat, pos); + logf (LOG_LOG, "isc: write_block %d " ZINT_FORMAT, cat, pos); return bf_write (is->files[cat].bf, pos, 0, 0, src); } -int isc_write_dblock (ISAMC is, int cat, int pos, char *src, - int nextpos, int offset) +int isc_write_dblock (ISAMC is, int cat, zint pos, char *src, + zint nextpos, int offset) { ISAMC_BLOCK_SIZE size = offset + ISAMC_BLOCK_OFFSET_N; if (is->method->debug > 2) - logf (LOG_LOG, "isc: write_dblock. size=%d nextpos=%d", + logf (LOG_LOG, "isc: write_dblock. size=%d nextpos=" ZINT_FORMAT, (int) size, nextpos); src -= ISAMC_BLOCK_OFFSET_N; - memcpy (src, &nextpos, sizeof(int)); - memcpy (src + sizeof(int), &size, sizeof(size)); + memcpy (src, &nextpos, sizeof(nextpos)); + memcpy (src + sizeof(nextpos), &size, sizeof(size)); return isc_write_block (is, cat, pos, src); } @@ -248,19 +247,19 @@ int isc_write_dblock (ISAMC is, int cat, int pos, char *src, static void flush_block (ISAMC is, int cat) { char *abuf = is->files[cat].alloc_buf; - int block = is->files[cat].head.freelist; + zint block = is->files[cat].head.freelist; if (block && is->files[cat].alloc_entries_num) { - memcpy (abuf, &is->files[cat].alloc_entries_num, sizeof(int)); + memcpy (abuf, &is->files[cat].alloc_entries_num, sizeof(block)); bf_write (is->files[cat].bf, block, 0, 0, abuf); is->files[cat].alloc_entries_num = 0; } xfree (abuf); } -static int alloc_block (ISAMC is, int cat) +static zint alloc_block (ISAMC is, int cat) { - int block = is->files[cat].head.freelist; + zint block = is->files[cat].head.freelist; char *abuf = is->files[cat].alloc_buf; (is->files[cat].no_allocated)++; @@ -285,7 +284,7 @@ static int alloc_block (ISAMC is, int cat) if (!is->files[cat].alloc_entries_num) /* last one in block? */ { memcpy (&is->files[cat].head.freelist, abuf + sizeof(int), - sizeof(int)); + sizeof(zint)); is->files[cat].head_is_dirty = 1; if (is->files[cat].head.freelist) @@ -298,16 +297,16 @@ static int alloc_block (ISAMC is, int cat) } } else - memcpy (&block, abuf + sizeof(int) + sizeof(int) * - is->files[cat].alloc_entries_num, sizeof(int)); + memcpy (&block, abuf + sizeof(zint) + sizeof(int) * + is->files[cat].alloc_entries_num, sizeof(zint)); } return block; } -static void release_block (ISAMC is, int cat, int pos) +static void release_block (ISAMC is, int cat, zint pos) { char *abuf = is->files[cat].alloc_buf; - int block = is->files[cat].head.freelist; + zint block = is->files[cat].head.freelist; (is->files[cat].no_released)++; @@ -328,15 +327,15 @@ static void release_block (ISAMC is, int cat, int pos) } if (!is->files[cat].alloc_entries_num) /* make new buffer? */ { - memcpy (abuf + sizeof(int), &block, sizeof(int)); + memcpy (abuf + sizeof(int), &block, sizeof(zint)); is->files[cat].head.freelist = pos; is->files[cat].head_is_dirty = 1; } else { memcpy (abuf + sizeof(int) + - is->files[cat].alloc_entries_num*sizeof(int), - &pos, sizeof(int)); + is->files[cat].alloc_entries_num*sizeof(zint), + &pos, sizeof(zint)); } is->files[cat].alloc_entries_num++; } @@ -347,42 +346,43 @@ static void flush_block (ISAMC is, int cat) xfree (abuf); } -static int alloc_block (ISAMC is, int cat) +static zint alloc_block (ISAMC is, int cat) { - int block; - char buf[sizeof(int)]; + zint block; + char buf[sizeof(zint)]; is->files[cat].head_is_dirty = 1; (is->files[cat].no_allocated)++; if ((block = is->files[cat].head.freelist)) { - bf_read (is->files[cat].bf, block, 0, sizeof(int), buf); - memcpy (&is->files[cat].head.freelist, buf, sizeof(int)); + bf_read (is->files[cat].bf, block, 0, sizeof(zint), buf); + memcpy (&is->files[cat].head.freelist, buf, sizeof(zint)); } else block = (is->files[cat].head.lastblock)++; return block; } -static void release_block (ISAMC is, int cat, int pos) +static void release_block (ISAMC is, int cat, zint pos) { - char buf[sizeof(int)]; + char buf[sizeof(zint)]; (is->files[cat].no_released)++; is->files[cat].head_is_dirty = 1; - memcpy (buf, &is->files[cat].head.freelist, sizeof(int)); + memcpy (buf, &is->files[cat].head.freelist, sizeof(zint)); is->files[cat].head.freelist = pos; - bf_write (is->files[cat].bf, pos, 0, sizeof(int), buf); + bf_write (is->files[cat].bf, pos, 0, sizeof(zint), buf); } #endif -int isc_alloc_block (ISAMC is, int cat) +zint isc_alloc_block (ISAMC is, int cat) { - int block = 0; + zint block = 0; if (is->files[cat].fc_list) { - int j, nb; + int j; + zint nb; for (j = 0; j < is->files[cat].fc_max; j++) if ((nb = is->files[cat].fc_list[j]) && (!block || nb < block)) { @@ -394,14 +394,14 @@ int isc_alloc_block (ISAMC is, int cat) if (!block) block = alloc_block (is, cat); if (is->method->debug > 3) - logf (LOG_LOG, "isc: alloc_block in cat %d: %d", cat, block); + logf (LOG_LOG, "isc: alloc_block in cat %d: " ZINT_FORMAT, cat, block); return block; } -void isc_release_block (ISAMC is, int cat, int pos) +void isc_release_block (ISAMC is, int cat, zint pos) { if (is->method->debug > 3) - logf (LOG_LOG, "isc: release_block in cat %d: %d", cat, pos); + logf (LOG_LOG, "isc: release_block in cat %d:" ZINT_FORMAT, cat, pos); if (is->files[cat].fc_list) { int j; @@ -442,7 +442,7 @@ void isc_pp_close (ISAMC_PP pp) { ISAMC is = pp->is; - (*is->method->code_stop)(ISAMC_DECODE, pp->decodeClientData); + (*is->method->codec.stop)(pp->decodeClientData); xfree (pp->buf); xfree (pp); } @@ -461,7 +461,7 @@ ISAMC_PP isc_pp_open (ISAMC is, ISAMC_P ipos) pp->size = 0; pp->offset = 0; pp->is = is; - pp->decodeClientData = (*is->method->code_start)(ISAMC_DECODE); + pp->decodeClientData = (*is->method->codec.start)(); pp->deleteFlag = 0; pp->numKeys = 0; @@ -475,12 +475,17 @@ ISAMC_PP isc_pp_open (ISAMC is, ISAMC_P ipos) src += sizeof(pp->size); memcpy (&pp->numKeys, src, sizeof(pp->numKeys)); src += sizeof(pp->numKeys); - assert (pp->next != pp->pos); + if (pp->next == pp->pos) + { + yaz_log(LOG_FATAL|LOG_LOG, "pp->next = " ZINT_FORMAT, pp->next); + yaz_log(LOG_FATAL|LOG_LOG, "pp->pos = " ZINT_FORMAT, pp->pos); + assert (pp->next != pp->pos); + } pp->offset = src - pp->buf; assert (pp->offset == ISAMC_BLOCK_OFFSET_1); if (is->method->debug > 2) - logf (LOG_LOG, "isc: read_block size=%d %d %d next=%d", - pp->size, pp->cat, pp->pos, pp->next); + logf (LOG_LOG, "isc: read_block size=%d %d " ZINT_FORMAT " next=" + ZINT_FORMAT, pp->size, pp->cat, pp->pos, pp->next); } return pp; } @@ -488,7 +493,8 @@ ISAMC_PP isc_pp_open (ISAMC is, ISAMC_P ipos) /* returns non-zero if item could be read; 0 otherwise */ int isc_pp_read (ISAMC_PP pp, void *buf) { - return isc_read_item (pp, (char **) &buf); + char *cp = buf; + return isc_read_item (pp, &cp); } /* read one item from file - decode and store it in *dst. @@ -499,7 +505,7 @@ int isc_pp_read (ISAMC_PP pp, void *buf) int isc_read_item (ISAMC_PP pp, char **dst) { ISAMC is = pp->is; - char *src = pp->buf + pp->offset; + const char *src = pp->buf + pp->offset; if (pp->offset >= pp->size) { @@ -532,29 +538,36 @@ int isc_read_item (ISAMC_PP pp, char **dst) pp->pos = pp->next; src = pp->buf; /* read block and save 'next' and 'size' entry */ - isc_read_block (is, pp->cat, pp->pos, src); + isc_read_block (is, pp->cat, pp->pos, pp->buf); memcpy (&pp->next, src, sizeof(pp->next)); src += sizeof(pp->next); memcpy (&pp->size, src, sizeof(pp->size)); src += sizeof(pp->size); /* assume block is non-empty */ assert (src - pp->buf == ISAMC_BLOCK_OFFSET_N); - assert (pp->next != pp->pos); + + if (pp->next == pp->pos) + { + yaz_log(LOG_FATAL|LOG_LOG, "pp->next = " ZINT_FORMAT, pp->next); + yaz_log(LOG_FATAL|LOG_LOG, "pp->pos = " ZINT_FORMAT, pp->pos); + assert (pp->next != pp->pos); + } + if (pp->deleteFlag) isc_release_block (is, pp->cat, pp->pos); - (*is->method->code_item)(ISAMC_DECODE, pp->decodeClientData, dst, &src); + (*is->method->codec.decode)(pp->decodeClientData, dst, &src); pp->offset = src - pp->buf; if (is->method->debug > 2) - logf (LOG_LOG, "isc: read_block size=%d %d %d next=%d", - pp->size, pp->cat, pp->pos, pp->next); + logf (LOG_LOG, "isc: read_block size=%d %d " ZINT_FORMAT " next=" + ZINT_FORMAT, pp->size, pp->cat, pp->pos, pp->next); return 2; } - (*is->method->code_item)(ISAMC_DECODE, pp->decodeClientData, dst, &src); + (*is->method->codec.decode)(pp->decodeClientData, dst, &src); pp->offset = src - pp->buf; return 1; } -int isc_pp_num (ISAMC_PP pp) +zint isc_pp_num (ISAMC_PP pp) { return pp->numKeys; } diff --git a/isamc/merge.c b/isamc/merge.c index 7bfdf05..5b5669f 100644 --- a/isamc/merge.c +++ b/isamc/merge.c @@ -1,5 +1,5 @@ -/* $Id: merge.c,v 1.23 2003-06-23 15:36:11 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: merge.c,v 1.24 2004-08-04 08:35:24 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,8 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #include #include #include @@ -31,7 +29,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA struct isc_merge_block { int offset; /* offset in r_buf */ - int block; /* block number of file (0 if none) */ + zint block; /* block number of file (0 if none) */ int dirty; /* block is different from that on file */ }; @@ -66,8 +64,8 @@ static void opt_blocks (ISAMC is, struct isc_merge_block *mb, int ptr, #endif static void flush_blocks (ISAMC is, struct isc_merge_block *mb, int ptr, - char *r_buf, int *firstpos, int cat, int last, - int *numkeys) + char *r_buf, zint *firstpos, int cat, int last, + zint *numkeys) { int i; @@ -105,7 +103,7 @@ static void flush_blocks (ISAMC is, struct isc_merge_block *mb, int ptr, if (!*firstpos) *firstpos = mb[i].block; if (is->method->debug > 2) - logf (LOG_LOG, "isc: skip ptr=%d size=%d %d %d", + logf (LOG_LOG, "isc: skip ptr=%d size=%d %d " ZINT_FORMAT, i, ssize, cat, mb[i].block); ++(is->files[cat].no_skip_writes); continue; @@ -118,22 +116,21 @@ static void flush_blocks (ISAMC is, struct isc_merge_block *mb, int ptr, src = r_buf + mb[i].offset - ISAMC_BLOCK_OFFSET_1; ssize += ISAMC_BLOCK_OFFSET_1; - memcpy (src+sizeof(int)+sizeof(ssize), numkeys, - sizeof(*numkeys)); + memcpy (src+sizeof(zint)+sizeof(ssize), numkeys, sizeof(*numkeys)); if (is->method->debug > 2) - logf (LOG_LOG, "isc: flush ptr=%d numk=%d size=%d nextpos=%d", - i, *numkeys, (int) ssize, mb[i+1].block); + logf (LOG_LOG, "isc: flush ptr=%d numk=" ZINT_FORMAT " size=%d nextpos=" + ZINT_FORMAT, i, *numkeys, (int) ssize, mb[i+1].block); } else { src = r_buf + mb[i].offset - ISAMC_BLOCK_OFFSET_N; ssize += ISAMC_BLOCK_OFFSET_N; if (is->method->debug > 2) - logf (LOG_LOG, "isc: flush ptr=%d size=%d nextpos=%d", + logf (LOG_LOG, "isc: flush ptr=%d size=%d nextpos=" ZINT_FORMAT, i, (int) ssize, mb[i+1].block); } - memcpy (src, &mb[i+1].block, sizeof(int)); - memcpy (src+sizeof(int), &ssize, sizeof(ssize)); + memcpy (src, &mb[i+1].block, sizeof(zint)); + memcpy (src+sizeof(zint), &ssize, sizeof(ssize)); isc_write_block (is, cat, mb[i].block, src); } } @@ -168,7 +165,7 @@ ISAMC_P isc_merge (ISAMC is, ISAMC_P ipos, ISAMC_I *data) struct isc_merge_block mb[200]; - int firstpos = 0; + zint firstpos = 0; int cat = 0; char r_item_buf[128]; /* temporary result output */ char *r_buf; /* block with resulting data */ @@ -176,9 +173,9 @@ ISAMC_P isc_merge (ISAMC is, ISAMC_P ipos, ISAMC_I *data) int ptr = 0; /* pointer */ void *r_clientData; /* encode client data */ int border; - int numKeys = 0; + zint numKeys = 0; - r_clientData = (*is->method->code_start)(ISAMC_ENCODE); + r_clientData = (*is->method->codec.start)(); r_buf = is->merge_buf + 128; pp = isc_pp_open (is, ipos); @@ -190,7 +187,7 @@ ISAMC_P isc_merge (ISAMC is, ISAMC_P ipos, ISAMC_I *data) cat = pp->cat; if (debug > 1) - logf (LOG_LOG, "isc: isc_merge begin %d %d", cat, pp->pos); + logf (LOG_LOG, "isc: isc_merge begin %d " ZINT_FORMAT, cat, pp->pos); /* read first item from i */ i_item_ptr = i_item; @@ -337,10 +334,10 @@ ISAMC_P isc_merge (ISAMC is, ISAMC_P ipos, ISAMC_I *data) if (r_item) /* insert resulting item? */ { char *r_out_ptr = r_buf + r_offset; + const char *src = r_item; int new_offset; - (*is->method->code_item)(ISAMC_ENCODE, r_clientData, - &r_out_ptr, &r_item); + (*is->method->codec.encode)(r_clientData, &r_out_ptr, &src); new_offset = r_out_ptr - r_buf; numKeys++; @@ -456,7 +453,7 @@ ISAMC_P isc_merge (ISAMC is, ISAMC_P ipos, ISAMC_I *data) if (numKeys != isc_pp_num (pp)) { if (debug > 2) - logf (LOG_LOG, "isc: patch num keys firstpos=%d num=%d", + logf (LOG_LOG, "isc: patch num keys firstpos=" ZINT_FORMAT " num=" ZINT_FORMAT, firstpos, numKeys); bf_write (is->files[cat].bf, firstpos, ISAMC_BLOCK_OFFSET_N, sizeof(numKeys), &numKeys); @@ -471,88 +468,12 @@ ISAMC_P isc_merge (ISAMC is, ISAMC_P ipos, ISAMC_I *data) /* flush rest of block(s) in r_buf */ flush_blocks (is, mb, ptr, r_buf, &firstpos, cat, 1, &numKeys); - (*is->method->code_stop)(ISAMC_ENCODE, r_clientData); + (*is->method->codec.stop)(r_clientData); if (!firstpos) cat = 0; if (debug > 1) - logf (LOG_LOG, "isc: isc_merge return %d %d", cat, firstpos); + logf (LOG_LOG, "isc: isc_merge return %d " ZINT_FORMAT, cat, firstpos); isc_pp_close (pp); return cat + firstpos * 8; } -/* - * $Log: merge.c,v $ - * Revision 1.23 2003-06-23 15:36:11 adam - * Implemented isamb_unlink. - * - * Revision 1.22 2003/03/05 16:41:10 adam - * Fix GCC warnings - * - * Revision 1.21 2002/08/02 19:26:56 adam - * Towards GPL - * - * Revision 1.20 1999/11/30 13:48:04 adam - * Improved installation. Updated for inclusion of YAZ header files. - * - * Revision 1.19 1999/07/14 12:12:07 heikki - * Large-block isam-h (may not work too well... Abandoning for isam-d) - * - * Revision 1.17 1999/07/13 14:22:17 heikki - * Better allocation strategy in isamh_merge - * - * Revision 1.16 1999/07/08 14:23:27 heikki - * Fixed a bug in isamh_pp_read and cleaned up a bit - * - * Revision 1.15 1999/07/07 09:36:04 heikki - * Fixed an assertion in isamh - * - * Revision 1.13 1999/07/06 09:37:05 heikki - * Working on isamh - not ready yet. - * - * Revision 1.12 1999/06/30 15:03:55 heikki - * first take on isamh, the append-only isam structure - * - * Revision 1.11 1999/05/26 07:49:14 adam - * C++ compilation. - * - * Revision 1.10 1998/03/19 12:22:09 adam - * Minor change. - * - * Revision 1.9 1998/03/19 10:04:38 adam - * Minor changes. - * - * Revision 1.8 1998/03/18 09:23:55 adam - * Blocks are stored in chunks on free list - up to factor 2 in speed. - * Fixed bug that could occur in block category rearrangemen. - * - * Revision 1.7 1998/03/11 11:18:18 adam - * Changed the isc_merge to take into account the mfill (minimum-fill). - * - * Revision 1.6 1998/03/06 13:54:03 adam - * Fixed two nasty bugs in isc_merge. - * - * Revision 1.5 1997/02/12 20:42:43 adam - * Bug fix: during isc_merge operations, some pages weren't marked dirty - * even though they should be. At this point the merge operation marks - * a page dirty if the previous page changed at all. A better approach is - * to mark it dirty if the last key written changed in previous page. - * - * Revision 1.4 1996/11/08 11:15:31 adam - * Number of keys in chain are stored in first block and the function - * to retrieve this information, isc_pp_num is implemented. - * - * Revision 1.3 1996/11/04 14:08:59 adam - * Optimized free block usage. - * - * Revision 1.2 1996/11/01 13:36:46 adam - * New element, max_blocks_mem, that control how many blocks of max size - * to store in memory during isc_merge. - * Function isc_merge now ignores delete/update of identical keys and - * the proper blocks are then non-dirty and not written in flush_blocks. - * - * Revision 1.1 1996/11/01 08:59:15 adam - * First version of isc_merge that supports update/delete. - * - */ - - diff --git a/isams/isams.c b/isams/isams.c index 7994294..44c4a33 100644 --- a/isams/isams.c +++ b/isams/isams.c @@ -1,5 +1,5 @@ -/* $Id: isams.c,v 1.5 2004-06-01 12:56:39 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: isams.c,v 1.6 2004-08-04 08:35:24 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. @@ -59,9 +59,11 @@ struct ISAMS_PP_s { void isams_getmethod (ISAMS_M *m) { - m->code_start = NULL; - m->code_item = NULL; - m->code_stop = NULL; + m->codec.start = NULL; + m->codec.decode = NULL; + m->codec.encode = NULL; + m->codec.stop = NULL; + m->codec.reset = NULL; m->compare_item = NULL; m->log_item = NULL; @@ -111,14 +113,14 @@ int isams_close (ISAMS is) ISAMS_P isams_merge (ISAMS is, ISAMS_I data) { - char i_item[128], *i_item_ptr; + char i_item[128]; int i_more, i_mode; void *r_clientData; int first_block = is->head.last_block; int first_offset = is->head.last_offset; int count = 0; - r_clientData = (*is->method->code_start)(ISAMC_ENCODE); + r_clientData = (*is->method->codec.start)(); is->head.last_offset += sizeof(int); if (is->head.last_offset > is->block_size) @@ -133,8 +135,8 @@ ISAMS_P isams_merge (ISAMS is, ISAMS_I data) } while (1) { - i_item_ptr = i_item; - i_more = (*data->read_item)(data->clientData, &i_item_ptr, &i_mode); + char *tmp_ptr = i_item; + i_more = (*data->read_item)(data->clientData, &tmp_ptr, &i_mode); assert (i_mode); if (!i_more) @@ -143,9 +145,8 @@ ISAMS_P isams_merge (ISAMS is, ISAMS_I data) { char *r_out_ptr = is->merge_buf + is->head.last_offset; - i_item_ptr = i_item; - (*is->method->code_item)(ISAMC_ENCODE, r_clientData, - &r_out_ptr, &i_item_ptr); + const char *i_item_ptr = i_item; + (*is->method->codec.encode)(r_clientData, &r_out_ptr, &i_item_ptr); is->head.last_offset = r_out_ptr - is->merge_buf; if (is->head.last_offset > is->block_size) { @@ -158,7 +159,7 @@ ISAMS_P isams_merge (ISAMS is, ISAMS_I data) count++; } } - (*is->method->code_stop)(ISAMC_ENCODE, r_clientData); + (*is->method->codec.stop)(r_clientData); if (first_block == is->head.last_block) memcpy(is->merge_buf + first_offset, &count, sizeof(int)); else if (first_block == is->head.last_block-1) @@ -189,7 +190,7 @@ ISAMS_PP isams_pp_open (ISAMS is, ISAMS_P pos) if (is->debug > 1) logf (LOG_LOG, "isams: isams_pp_open pos=%ld", (long) pos); pp->is = is; - pp->decodeClientData = (*is->method->code_start)(ISAMC_DECODE); + pp->decodeClientData = (*is->method->codec.start)(); pp->numKeys = 0; pp->numRead = 0; pp->buf = (char *) xmalloc(is->block_size*2); @@ -212,7 +213,7 @@ ISAMS_PP isams_pp_open (ISAMS is, ISAMS_P pos) void isams_pp_close (ISAMS_PP pp) { - (*pp->is->method->code_stop)(ISAMC_DECODE, pp->decodeClientData); + (*pp->is->method->codec.stop)(pp->decodeClientData); xfree(pp->buf); xfree(pp); } @@ -224,12 +225,13 @@ int isams_pp_num (ISAMS_PP pp) int isams_pp_read (ISAMS_PP pp, void *buf) { - return isams_read_item (pp, (char **) &buf); + char *cp = buf; + return isams_read_item (pp, &cp); } int isams_read_item (ISAMS_PP pp, char **dst) { - char *src; + const char *src; if (pp->numRead >= pp->numKeys) return 0; (pp->numRead)++; @@ -242,8 +244,7 @@ int isams_read_item (ISAMS_PP pp, char **dst) pp->buf + pp->is->block_size); } src = pp->buf + pp->block_offset; - (*pp->is->method->code_item)(ISAMC_DECODE, pp->decodeClientData, - dst, &src); + (*pp->is->method->codec.decode)(pp->decodeClientData, dst, &src); pp->block_offset = src - pp->buf; return 1; } diff --git a/perl/IDZebra.i b/perl/IDZebra.i index c1f1ec2..c9294ae 100644 --- a/perl/IDZebra.i +++ b/perl/IDZebra.i @@ -99,7 +99,7 @@ typedef struct { char *errString; /* error string */ int position; /* position of record in result set (1,2,..) */ char *base; - int sysno; + long long sysno; int score; char *format; /* record syntax */ RetrievalRecordBuf *buf; @@ -273,11 +273,11 @@ void zebra_repository_show (ZebraHandle zh, const char *path); If not, and match_criteria is provided, then sysno is guessed If not, and a record is provided, then sysno is got from there */ -%apply int *REFERENCE { int *sysno }; +%apply int *REFERENCE { long long *sysno }; %name(insert_record) int zebra_insert_record (ZebraHandle zh, const char *recordType, - int *sysno, + long long *sysno, const char *match, const char *fname, const char *buf, @@ -287,7 +287,7 @@ int zebra_insert_record (ZebraHandle zh, %name(update_record) int zebra_update_record (ZebraHandle zh, const char *recordType, - int *sysno, + long long *sysno, const char *match, const char *fname, const char *buf, @@ -297,7 +297,7 @@ int zebra_update_record (ZebraHandle zh, %name(delete_record) int zebra_delete_record (ZebraHandle zh, const char *recordType, - int *sysno, + long long *sysno, const char *match, const char *fname, const char *buf, diff --git a/perl/lib/IDZebra.pm b/perl/lib/IDZebra.pm index e1c7cf1..7528315 100644 --- a/perl/lib/IDZebra.pm +++ b/perl/lib/IDZebra.pm @@ -23,6 +23,18 @@ sub FIRSTKEY { } sub NEXTKEY { } +sub FETCH { + my ($self,$field) = @_; + my $member_func = "swig_${field}_get"; + $self->$member_func(); +} + +sub STORE { + my ($self,$field,$newval) = @_; + my $member_func = "swig_${field}_set"; + $self->$member_func($newval); +} + sub this { my $ptr = shift; return tied(%$ptr); @@ -79,14 +91,7 @@ package IDZebra; *resultSetTerms = *IDZebrac::resultSetTerms; *sort = *IDZebrac::sort; *scan_PQF = *IDZebrac::scan_PQF; -sub getScanEntry { - my @args = @_; - my $result = IDZebrac::getScanEntry(@args); - return undef if (!defined($result)); - my %resulthash; - tie %resulthash, ref($result), $result; - return bless \%resulthash, ref($result); -} +*getScanEntry = *IDZebrac::getScanEntry; *nmem_create = *IDZebrac::nmem_create; *nmem_destroy = *IDZebrac::nmem_destroy; *data1_create = *IDZebrac::data1_create; @@ -178,9 +183,6 @@ sub getScanEntry { package IDZebra::RetrievalObj; @ISA = qw( IDZebra ); %OWNER = (); -%BLESSEDMEMBERS = ( -); - %ITERATORS = (); *swig_noOfRecords_get = *IDZebrac::RetrievalObj_noOfRecords_get; *swig_noOfRecords_set = *IDZebrac::RetrievalObj_noOfRecords_set; @@ -188,13 +190,8 @@ package IDZebra::RetrievalObj; *swig_records_set = *IDZebrac::RetrievalObj_records_set; sub new { my $pkg = shift; - my @args = @_; - my $self = IDZebrac::new_RetrievalObj(@args); - return undef if (!defined($self)); - $OWNER{$self} = 1; - my %retval; - tie %retval, "IDZebra::RetrievalObj", $self; - return bless \%retval, $pkg; + my $self = IDZebrac::new_RetrievalObj(@_); + bless $self, $pkg if defined($self); } sub DESTROY { @@ -212,35 +209,12 @@ sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; - }; +} sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; - }; - -sub FETCH { - my ($self,$field) = @_; - my $member_func = "swig_${field}_get"; - my $val = $self->$member_func(); - if (exists $BLESSEDMEMBERS{$field}) { - return undef if (!defined($val)); - my %retval; - tie %retval,$BLESSEDMEMBERS{$field},$val; - return bless \%retval, $BLESSEDMEMBERS{$field}; - } - return $val; -} - -sub STORE { - my ($self,$field,$newval) = @_; - my $member_func = "swig_${field}_set"; - if (exists $BLESSEDMEMBERS{$field}) { - $self->$member_func(tied(%{$newval})); - } else { - $self->$member_func($newval); - } } @@ -249,9 +223,6 @@ sub STORE { package IDZebra::RetrievalRecord; @ISA = qw( IDZebra ); %OWNER = (); -%BLESSEDMEMBERS = ( -); - %ITERATORS = (); *swig_errCode_get = *IDZebrac::RetrievalRecord_errCode_get; *swig_errCode_set = *IDZebrac::RetrievalRecord_errCode_set; @@ -271,13 +242,8 @@ package IDZebra::RetrievalRecord; *swig_buf_set = *IDZebrac::RetrievalRecord_buf_set; sub new { my $pkg = shift; - my @args = @_; - my $self = IDZebrac::new_RetrievalRecord(@args); - return undef if (!defined($self)); - $OWNER{$self} = 1; - my %retval; - tie %retval, "IDZebra::RetrievalRecord", $self; - return bless \%retval, $pkg; + my $self = IDZebrac::new_RetrievalRecord(@_); + bless $self, $pkg if defined($self); } sub DESTROY { @@ -295,35 +261,12 @@ sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; - }; +} sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; - }; - -sub FETCH { - my ($self,$field) = @_; - my $member_func = "swig_${field}_get"; - my $val = $self->$member_func(); - if (exists $BLESSEDMEMBERS{$field}) { - return undef if (!defined($val)); - my %retval; - tie %retval,$BLESSEDMEMBERS{$field},$val; - return bless \%retval, $BLESSEDMEMBERS{$field}; - } - return $val; -} - -sub STORE { - my ($self,$field,$newval) = @_; - my $member_func = "swig_${field}_set"; - if (exists $BLESSEDMEMBERS{$field}) { - $self->$member_func(tied(%{$newval})); - } else { - $self->$member_func($newval); - } } @@ -332,9 +275,6 @@ sub STORE { package IDZebra::scanEntry; @ISA = qw( IDZebra ); %OWNER = (); -%BLESSEDMEMBERS = ( -); - %ITERATORS = (); *swig_occurrences_get = *IDZebrac::scanEntry_occurrences_get; *swig_occurrences_set = *IDZebrac::scanEntry_occurrences_set; @@ -342,13 +282,8 @@ package IDZebra::scanEntry; *swig_term_set = *IDZebrac::scanEntry_term_set; sub new { my $pkg = shift; - my @args = @_; - my $self = IDZebrac::new_scanEntry(@args); - return undef if (!defined($self)); - $OWNER{$self} = 1; - my %retval; - tie %retval, "IDZebra::scanEntry", $self; - return bless \%retval, $pkg; + my $self = IDZebrac::new_scanEntry(@_); + bless $self, $pkg if defined($self); } sub DESTROY { @@ -366,35 +301,12 @@ sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; - }; +} sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; - }; - -sub FETCH { - my ($self,$field) = @_; - my $member_func = "swig_${field}_get"; - my $val = $self->$member_func(); - if (exists $BLESSEDMEMBERS{$field}) { - return undef if (!defined($val)); - my %retval; - tie %retval,$BLESSEDMEMBERS{$field},$val; - return bless \%retval, $BLESSEDMEMBERS{$field}; - } - return $val; -} - -sub STORE { - my ($self,$field,$newval) = @_; - my $member_func = "swig_${field}_set"; - if (exists $BLESSEDMEMBERS{$field}) { - $self->$member_func(tied(%{$newval})); - } else { - $self->$member_func($newval); - } } @@ -403,10 +315,6 @@ sub STORE { package IDZebra::ScanObj; @ISA = qw( IDZebra ); %OWNER = (); -%BLESSEDMEMBERS = ( - entries => 'IDZebra::scanEntry', -); - %ITERATORS = (); *swig_num_entries_get = *IDZebrac::ScanObj_num_entries_get; *swig_num_entries_set = *IDZebrac::ScanObj_num_entries_set; @@ -418,13 +326,8 @@ package IDZebra::ScanObj; *swig_entries_set = *IDZebrac::ScanObj_entries_set; sub new { my $pkg = shift; - my @args = @_; - my $self = IDZebrac::new_ScanObj(@args); - return undef if (!defined($self)); - $OWNER{$self} = 1; - my %retval; - tie %retval, "IDZebra::ScanObj", $self; - return bless \%retval, $pkg; + my $self = IDZebrac::new_ScanObj(@_); + bless $self, $pkg if defined($self); } sub DESTROY { @@ -442,35 +345,12 @@ sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; - }; +} sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; - }; - -sub FETCH { - my ($self,$field) = @_; - my $member_func = "swig_${field}_get"; - my $val = $self->$member_func(); - if (exists $BLESSEDMEMBERS{$field}) { - return undef if (!defined($val)); - my %retval; - tie %retval,$BLESSEDMEMBERS{$field},$val; - return bless \%retval, $BLESSEDMEMBERS{$field}; - } - return $val; -} - -sub STORE { - my ($self,$field,$newval) = @_; - my $member_func = "swig_${field}_set"; - if (exists $BLESSEDMEMBERS{$field}) { - $self->$member_func(tied(%{$newval})); - } else { - $self->$member_func($newval); - } } @@ -479,9 +359,6 @@ sub STORE { package IDZebra::ZebraTransactionStatus; @ISA = qw( IDZebra ); %OWNER = (); -%BLESSEDMEMBERS = ( -); - %ITERATORS = (); *swig_processed_get = *IDZebrac::ZebraTransactionStatus_processed_get; *swig_processed_set = *IDZebrac::ZebraTransactionStatus_processed_set; @@ -497,13 +374,8 @@ package IDZebra::ZebraTransactionStatus; *swig_stime_set = *IDZebrac::ZebraTransactionStatus_stime_set; sub new { my $pkg = shift; - my @args = @_; - my $self = IDZebrac::new_ZebraTransactionStatus(@args); - return undef if (!defined($self)); - $OWNER{$self} = 1; - my %retval; - tie %retval, "IDZebra::ZebraTransactionStatus", $self; - return bless \%retval, $pkg; + my $self = IDZebrac::new_ZebraTransactionStatus(@_); + bless $self, $pkg if defined($self); } sub DESTROY { @@ -521,35 +393,12 @@ sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; - }; +} sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; - }; - -sub FETCH { - my ($self,$field) = @_; - my $member_func = "swig_${field}_get"; - my $val = $self->$member_func(); - if (exists $BLESSEDMEMBERS{$field}) { - return undef if (!defined($val)); - my %retval; - tie %retval,$BLESSEDMEMBERS{$field},$val; - return bless \%retval, $BLESSEDMEMBERS{$field}; - } - return $val; -} - -sub STORE { - my ($self,$field,$newval) = @_; - my $member_func = "swig_${field}_set"; - if (exists $BLESSEDMEMBERS{$field}) { - $self->$member_func(tied(%{$newval})); - } else { - $self->$member_func($newval); - } } diff --git a/perl/zebra_perl.h b/perl/zebra_perl.h index cae6857..9af24a7 100644 --- a/perl/zebra_perl.h +++ b/perl/zebra_perl.h @@ -34,7 +34,7 @@ typedef struct { char *errString; /* error string */ int position; /* position of record in result set (1,2,..) */ char *base; - int sysno; + SYSNO sysno; int score; char *format; /* record syntax */ RetrievalRecordBuf *buf; diff --git a/recctrl/regxread.c b/recctrl/regxread.c index 4b26b8a..7c9919f 100644 --- a/recctrl/regxread.c +++ b/recctrl/regxread.c @@ -1,4 +1,4 @@ -/* $Id: regxread.c,v 1.50 2004-05-25 12:13:15 adam Exp $ +/* $Id: regxread.c,v 1.51 2004-08-04 08:35:25 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -1033,14 +1033,14 @@ static char *regxStrz (const char *src, int len, char *str) #if HAVE_TCL_H static int cmd_tcl_begin (ClientData clientData, Tcl_Interp *interp, - int argc, char **argv) + int argc, const char **argv) { struct lexSpec *spec = (struct lexSpec *) clientData; if (argc < 2) return TCL_ERROR; if (!strcmp(argv[1], "record") && argc == 3) { - char *absynName = argv[2]; + const char *absynName = argv[2]; data1_node *res; #if REGX_DEBUG @@ -1089,7 +1089,7 @@ static int cmd_tcl_begin (ClientData clientData, Tcl_Interp *interp, } static int cmd_tcl_end (ClientData clientData, Tcl_Interp *interp, - int argc, char **argv) + int argc, const char **argv) { struct lexSpec *spec = (struct lexSpec *) clientData; if (argc < 2) @@ -1110,7 +1110,7 @@ static int cmd_tcl_end (ClientData clientData, Tcl_Interp *interp, else if (!strcmp (argv[1], "element")) { int min_level = 2; - char *element = 0; + const char *element = 0; if (argc >= 3 && !strcmp(argv[2], "-record")) { min_level = 0; @@ -1143,7 +1143,7 @@ static int cmd_tcl_end (ClientData clientData, Tcl_Interp *interp, } static int cmd_tcl_data (ClientData clientData, Tcl_Interp *interp, - int argc, char **argv) + int argc, const char **argv) { int argi = 1; int textFlag = 0; @@ -1187,7 +1187,7 @@ static int cmd_tcl_data (ClientData clientData, Tcl_Interp *interp, } static int cmd_tcl_unread (ClientData clientData, Tcl_Interp *interp, - int argc, char **argv) + int argc, const char **argv) { struct lexSpec *spec = (struct lexSpec *) clientData; int argi = 1; diff --git a/rset/Makefile.am b/rset/Makefile.am index be7c936..1d26827 100644 --- a/rset/Makefile.am +++ b/rset/Makefile.am @@ -1,7 +1,7 @@ -## $Id: Makefile.am,v 1.6 2004-06-16 20:49:18 adam Exp $ +## $Id: Makefile.am,v 1.7 2004-08-04 08:35:26 adam Exp $ noinst_LIBRARIES = librset.a librset_a_SOURCES = rset.c rstemp.c rsisam.c rsnull.c rsbool.c rsbetween.c \ - rsisamc.c rsm_or.c rsisams.c rsisamd.c rsisamb.c rsprox.c + rsisamc.c rsm_or.c rsisams.c rsisamb.c rsprox.c AM_CPPFLAGS = -I$(srcdir)/../include $(YAZINC) diff --git a/test/api/t5.c b/test/api/t5.c index cd9e0e6..7163650 100644 --- a/test/api/t5.c +++ b/test/api/t5.c @@ -1,4 +1,4 @@ -/* $Id: t5.c,v 1.4 2004-07-28 08:15:47 adam Exp $ +/* $Id: t5.c,v 1.5 2004-08-04 08:35:26 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -52,7 +52,7 @@ static void expect(ZebraHandle zh, const char *pqf, int hits_expect, int main(int argc, char **argv) { - int i, hits = -1; + int i; int exit_code = 0; ZebraService zs; ZebraHandle zh; diff --git a/test/codec/tstcodec.c b/test/codec/tstcodec.c index 029cb50..cf19056 100644 --- a/test/codec/tstcodec.c +++ b/test/codec/tstcodec.c @@ -1,28 +1,130 @@ -#include "../index/index.h" +/* $Id: tstcodec.c,v 1.2 2004-08-04 08:35:26 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. -void tst_encode(int num) +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 "../../index/index.h" + +char *prog = ""; + +int tst_encode(int num) { struct it_key key; int i; - void *codec_handle =iscz1_code_start(ISAMC_ENCODE); + void *codec_handle =iscz1_start(); + char *dst_buf = malloc(200 + num * 10); + char *dst = dst_buf; + if (!dst_buf) + { + printf ("%s: out of memory (num=%d)\n", prog, num); + return 10; + } for (i = 0; i> 8; + key.mem[1] = i & 255; +#else key.sysno = num; key.seqno = 1; - iscz1_code_item (ISAMC_ENCODE, codec_handle, &dst, &src); +#endif + iscz1_encode (codec_handle, &dst, &src); + if (dst > dst_buf + num*10) + { + printf ("%s: i=%d size overflow\n", prog, i); + return 1; + } } - iscz1_code_stop(ISAMC_ENCODE, codec_handle); + iscz1_stop(codec_handle); + + codec_handle =iscz1_start(); + + if (1) + { + const char *src = dst_buf; + for (i = 0; i>8)) + { + printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected " + "%d\n", prog, i, key.mem[0], i>>8); + while (src0 != src) + { + printf (" %02X (%d decimal)", *src0, *src0); + src0++; + } + printf ("\n"); + return 3; + } + if (key.mem[1] != (i&255)) + { + printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected %d\n", + prog, i, key.mem[1], i&255); + while (src0 != src) + { + printf (" %02X (%d decimal)", *src0, *src0); + src0++; + } + printf ("\n"); + return 4; + } +#else + +#endif + } + } + + iscz1_stop(codec_handle); + free(dst_buf); + return 0; } int main(int argc, char **argv) { - tst_encode(1000000); - exit(0); + int num = 0; + prog = *argv; + if (argc > 1) + num = atoi(argv[1]); + if (num < 1 || num > 100000000) + num = 10000; + exit(tst_encode(num)); } diff --git a/util/Makefile.am b/util/Makefile.am index b10d269..10ee531 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.8 2004-06-16 20:49:18 adam Exp $ +## $Id: Makefile.am,v 1.9 2004-08-04 08:35:27 adam Exp $ noinst_LIBRARIES = libutil.a @@ -9,6 +9,6 @@ EXTRA_DIST = zebrasrv.rh AM_CPPFLAGS = -I$(srcdir)/../include $(YAZINC) -DDEFAULT_PROFILE_PATH=\"$(pkgdatadir)/tab\" LDADD = libutil.a $(YAZLIB) $(TCL_LIB) -libutil_a_SOURCES = res.c charmap.c zebramap.c passwddb.c zebra-lock.c dirent.c xpath.c +libutil_a_SOURCES = res.c charmap.c zebramap.c passwddb.c zebra-lock.c dirent.c xpath.c atoi_zn.c passtest_SOURCES = passtest.c diff --git a/util/atoi_zn.c b/util/atoi_zn.c new file mode 100644 index 0000000..51a75aa --- /dev/null +++ b/util/atoi_zn.c @@ -0,0 +1,39 @@ +/* $Id: atoi_zn.c,v 1.1 2004-08-04 08:35:27 adam Exp $ + Copyright (C) 2003,2004 + 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 +#include +#include + +zint atoi_zn (const char *buf, zint len) +{ + zint val = 0; + + while (--len >= 0) + { + if (isdigit (*buf)) + val = val*10 + (*buf - '0'); + buf++; + } + return val; +} + -- 1.7.10.4