From: Adam Dickmeiss Date: Mon, 13 May 1996 14:23:03 +0000 (+0000) Subject: Work on compaction of set/use bytes in dictionary. X-Git-Tag: ZEBRA.1.0~464 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=bad279c5dd1ae783ef9393775f0483cc3228cdbb Work on compaction of set/use bytes in dictionary. --- diff --git a/index/Makefile b/index/Makefile index ab81dec..9246d15 100644 --- a/index/Makefile +++ b/index/Makefile @@ -1,7 +1,7 @@ # Copyright (C) 1995, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.33 1996-05-01 13:46:35 adam Exp $ +# $Id: Makefile,v 1.34 1996-05-13 14:23:03 adam Exp $ SHELL=/bin/sh RANLIB=ranlib @@ -20,7 +20,7 @@ TPROG3=zebrasrv DEFS=$(INCLUDE) O1 = main.o dir.o dirs.o trav.o extract.o kinput.o kcompare.o \ symtab.o text.o recctrl.o structrec.o recindex.o regxread.o recstat.o \ - lockutil.o lockidx.o + lockutil.o lockidx.o zinfo.o O2 = kdump.o O3 = zserver.o kcompare.o zrpn.o zsets.o text.o recctrl.o structrec.o \ attribute.o recindex.o zlogs.o regxread.o lockutil.o locksrv.o diff --git a/index/extract.c b/index/extract.c index 42e86de..62a7613 100644 --- a/index/extract.c +++ b/index/extract.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: extract.c,v $ - * Revision 1.56 1996-05-09 09:54:42 adam + * Revision 1.57 1996-05-13 14:23:04 adam + * Work on compaction of set/use bytes in dictionary. + * + * Revision 1.56 1996/05/09 09:54:42 adam * Server supports maps from one logical attributes to a list of physical * attributes. * The extraction process doesn't make space consuming 'any' keys. @@ -213,7 +216,7 @@ #include #include "index.h" -#include "recindex.h" +#include "zinfo.h" static Dict matchDict; @@ -230,6 +233,8 @@ static int records_updated = 0; static int records_deleted = 0; static int records_processed = 0; +static ZebTargetInfo *zti = NULL; + static void logRecord (int showFlag) { if (!showFlag) @@ -260,6 +265,9 @@ void key_open (int mem) } assert (!records); records = rec_open (1); +#if 1 + zti = zebTargetInfo_open (records, 1); +#endif } struct encode_info { @@ -373,6 +381,9 @@ int key_close (void) { key_flush (); xfree (key_buf); +#if 1 + zebTargetInfo_close (zti, 1); +#endif rec_close (&records); dict_close (matchDict); @@ -461,6 +472,14 @@ static void flushRecordKeys (SYSNO sysno, int cmd, struct recKeys *reckeys, char attrSet = -1; short attrUse = -1; int off = 0; + +#if 1 + if (zebTargetInfo_curDatabase (zti, databaseName)) + { + if (zebTargetInfo_newDatabase (zti, databaseName)) + abort (); + } +#endif while (off < reckeys->buf_used) { const char *src = reckeys->buf + off; @@ -483,8 +502,16 @@ static void flushRecordKeys (SYSNO sysno, int cmd, struct recKeys *reckeys, key_flush (); ++ptr_i; key_buf[ptr_top-ptr_i] = (char*)key_buf + key_buf_used; +#if 1 + lead = zebTargetInfo_lookupSU (zti, attrSet, attrUse); + if (lead < 0) + lead = zebTargetInfo_addSU (zti, attrSet, attrUse); + assert (lead > 0); + ((char*) key_buf) [key_buf_used++] = lead; +#else key_buf_used += index_word_prefix ((char*)key_buf + key_buf_used, attrSet, attrUse, databaseName); +#endif while (*src) ((char*)key_buf) [key_buf_used++] = index_char_cvt (*src++); src++; diff --git a/index/kcompare.c b/index/kcompare.c index 878f491..3ca6daa 100644 --- a/index/kcompare.c +++ b/index/kcompare.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: kcompare.c,v $ - * Revision 1.15 1995-11-20 16:59:46 adam + * Revision 1.16 1996-05-13 14:23:05 adam + * Work on compaction of set/use bytes in dictionary. + * + * Revision 1.15 1995/11/20 16:59:46 adam * New update method: the 'old' keys are saved for each records. * * Revision 1.14 1995/10/30 15:08:08 adam @@ -126,6 +129,7 @@ int index_char_cvt (int c) return tolower (c); } +#if 1 int index_word_prefix (char *string, int attset_ordinal, int local_attribute, const char *databaseName) @@ -137,4 +141,4 @@ int index_word_prefix (char *string, int attset_ordinal, string[i] = index_char_cvt (string[i]); return i; } - +#endif diff --git a/index/recindex.c b/index/recindex.c index ab5e687..936f6e0 100644 --- a/index/recindex.c +++ b/index/recindex.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: recindex.c,v $ - * Revision 1.14 1996-02-01 20:48:15 adam + * Revision 1.15 1996-05-13 14:23:06 adam + * Work on compaction of set/use bytes in dictionary. + * + * Revision 1.14 1996/02/01 20:48:15 adam * The total size of records are always checked in rec_cache_insert to * reduce memory usage. * @@ -552,6 +555,9 @@ void rec_put (Records p, Record *recpp) void rec_rm (Record *recpp) { int i; + + if (!*recpp) + return ; for (i = 0; i < REC_NO_INFO; i++) xfree ((*recpp)->info[i]); xfree (*recpp); diff --git a/index/zinfo.c b/index/zinfo.c new file mode 100644 index 0000000..4f34867 --- /dev/null +++ b/index/zinfo.c @@ -0,0 +1,263 @@ +/* + * Copyright (C) 1994-1996, Index Data I/S + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: zinfo.c,v $ + * Revision 1.1 1996-05-13 14:23:07 adam + * Work on compaction of set/use bytes in dictionary. + * + */ + +#include +#include + +#include "zinfo.h" + +struct zebSUInfo { + int set; + int use; + int ordinal; +}; + +struct zebSUInfoB { + struct zebSUInfo info; + struct zebSUInfoB *next; +}; + +struct zebDatabaseInfo { + struct zebSUInfoB *SUInfo; + char *databaseName; + int sysno; + int readFlag; + struct zebDatabaseInfo *next; +}; + +struct zebTargetInfo { + int dictNum; + int dirty; + Records records; + struct zebDatabaseInfo *databaseInfo; + struct zebDatabaseInfo *curDatabaseInfo; +}; + +void zebTargetInfo_close (ZebTargetInfo *zti, int writeFlag) +{ + struct zebDatabaseInfo *zdi, *zdi1; + + if (writeFlag) + { + Record grec; + char p0[4096], *p = p0; + + memcpy (p, &zti->dictNum, sizeof(zti->dictNum)); + p += sizeof(zti->dictNum); + for (zdi = zti->databaseInfo; zdi; zdi=zdi->next) + { + if (zdi->readFlag || !zdi->sysno) + { + char q0[4096], *q = q0; + struct zebSUInfoB *zsui; + Record drec; + int no = 0; + + if (zdi->sysno) + drec = rec_get (zti->records, zdi->sysno); + else + { + drec = rec_new (zti->records); + zdi->sysno = drec->sysno; + } + assert (drec); + for (zsui = zdi->SUInfo; zsui; zsui=zsui->next) + no++; + memcpy (q, &no, sizeof(no)); + q += sizeof(no); + for (zsui = zdi->SUInfo; zsui; zsui=zsui->next) + { + memcpy (q, &zsui->info, sizeof(zsui->info)); + q += sizeof(zsui->info); + } + xfree (drec->info[0]); + drec->size[0] = q-q0; + drec->info[0] = xmalloc (drec->size[0]); + memcpy (drec->info[0], q0, drec->size[0]); + rec_put (zti->records, &drec); + } + strcpy (p, zdi->databaseName); + p += strlen(p)+1; + memcpy (p, &zdi->sysno, sizeof(zdi->sysno)); + p += sizeof(zdi->sysno); + } + *p = '\0'; + grec = rec_get (zti->records, 1); + xfree (grec->info[0]); + grec->size[0] = p-p0; + grec->info[0] = xmalloc (grec->size[0]); + memcpy (grec->info[0], p0, grec->size[0]); + rec_put (zti->records, &grec); + } + for (zdi = zti->databaseInfo; zdi; zdi = zdi1) + { + struct zebSUInfoB *zsui, *zsui1; + + zdi1 = zdi->next; + for (zsui = zdi->SUInfo; zsui; zsui = zsui1) + { + zsui1 = zsui->next; + xfree (zsui); + } + xfree (zdi->databaseName); + xfree (zdi); + } + xfree (zti); +} + +ZebTargetInfo *zebTargetInfo_open (Records records, int writeFlag) +{ + Record rec; + ZebTargetInfo *zti; + struct zebDatabaseInfo **zdi; + + zti = xmalloc (sizeof(*zti)); + zti->dirty = 0; + zti->curDatabaseInfo = NULL; + zti->records = records; + + zdi = &zti->databaseInfo; + + rec = rec_get (records, 1); + if (rec) + { + const char *p; + + p = rec->info[0]; + + memcpy (&zti->dictNum, p, sizeof(zti->dictNum)); + p += sizeof(zti->dictNum); + while (*p) + { + *zdi = xmalloc (sizeof(**zdi)); + (*zdi)->SUInfo = NULL; + (*zdi)->databaseName = xstrdup (p); + p += strlen(p)+1; + memcpy (&(*zdi)->sysno, p, sizeof((*zdi)->sysno)); + p += sizeof((*zdi)->sysno); + (*zdi)->readFlag = 1; + zdi = &(*zdi)->next; + } + assert (p - rec->info[0] == rec->size[0]-1); + } + else + { + zti->dictNum = 1; + if (writeFlag) + { + rec = rec_new (records); + rec->info[0] = xmalloc (1+sizeof(zti->dictNum)); + memcpy (rec->info[0], &zti->dictNum, sizeof(zti->dictNum)); + rec->info[0][sizeof(zti->dictNum)] = '\0'; + rec_put (records, &rec); + } + } + *zdi = NULL; + rec_rm (&rec); + return zti; +} + +static void zebTargetInfo_readDatabase (ZebTargetInfo *zti, + struct zebDatabaseInfo *zdi) +{ + const char *p; + struct zebSUInfoB **zsuip = &zdi->SUInfo; + int i, no; + Record rec; + + rec = rec_get (zti->records, zdi->sysno); + assert (rec); + p = rec->info[0]; + memcpy (&no, p, sizeof(no)); + p += sizeof(no); + for (i = 0; iinfo, p, sizeof((*zsuip)->info)); + p += sizeof((*zsuip)->info); + zsuip = &(*zsuip)->next; + } + *zsuip = NULL; + zdi->readFlag = 0; + rec_rm (&rec); +} + +int zebTargetInfo_curDatabase (ZebTargetInfo *zti, const char *database) +{ + struct zebDatabaseInfo *zdi; + + assert (zti); + if (zti->curDatabaseInfo && + !strcmp (zti->curDatabaseInfo->databaseName, database)) + return 0; + for (zdi = zti->databaseInfo; zdi; zdi=zdi->next) + { + if (!strcmp (zdi->databaseName, database)) + break; + } + if (!zdi) + return -1; + if (zdi->readFlag) + zebTargetInfo_readDatabase (zti, zdi); + zti->curDatabaseInfo = zdi; + return 0; +} + +int zebTargetInfo_newDatabase (ZebTargetInfo *zti, const char *database) +{ + struct zebDatabaseInfo *zdi; + + assert (zti); + for (zdi = zti->databaseInfo; zdi; zdi=zdi->next) + { + if (!strcmp (zdi->databaseName, database)) + break; + } + if (zdi) + return -1; + zdi = xmalloc (sizeof(*zdi)); + zdi->next = zti->databaseInfo; + zti->databaseInfo = zdi; + zdi->sysno = 0; + zdi->readFlag = 0; + zdi->databaseName = xstrdup (database); + zdi->SUInfo = NULL; + zti->curDatabaseInfo = zdi; + return 0; +} + +int zebTargetInfo_lookupSU (ZebTargetInfo *zti, int set, int use) +{ + struct zebSUInfoB *zsui; + + assert (zti->curDatabaseInfo); + for (zsui = zti->curDatabaseInfo->SUInfo; zsui; zsui=zsui->next) + if (zsui->info.use == use && zsui->info.set == set) + return zsui->info.ordinal; + return -1; +} + +int zebTargetInfo_addSU (ZebTargetInfo *zti, int set, int use) +{ + struct zebSUInfoB *zsui; + + assert (zti->curDatabaseInfo); + for (zsui = zti->curDatabaseInfo->SUInfo; zsui; zsui=zsui->next) + if (zsui->info.use == use && zsui->info.set == set) + return -1; + zsui = xmalloc (sizeof(*zsui)); + zsui->next = zti->curDatabaseInfo->SUInfo; + zti->curDatabaseInfo->SUInfo = zsui; + zsui->info.set = set; + zsui->info.use = use; + zsui->info.ordinal = (zti->dictNum)++; + return zsui->info.ordinal; +} diff --git a/index/zinfo.h b/index/zinfo.h new file mode 100644 index 0000000..09368d4 --- /dev/null +++ b/index/zinfo.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 1994-1996, Index Data I/S + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: zinfo.h,v $ + * Revision 1.1 1996-05-13 14:23:07 adam + * Work on compaction of set/use bytes in dictionary. + * + */ + +#include "recindex.h" + +typedef struct zebTargetInfo ZebTargetInfo; + +ZebTargetInfo *zebTargetInfo_open (Records records, int writeFlag); +void zebTargetInfo_close (ZebTargetInfo *zti, int writeFlag); +int zebTargetInfo_curDatabase (ZebTargetInfo *zti, const char *database); +int zebTargetInfo_newDatabase (ZebTargetInfo *zti, const char *database); +int zebTargetInfo_lookupSU (ZebTargetInfo *zti, int set, int use); +int zebTargetInfo_addSU (ZebTargetInfo *zti, int set, int use);