aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNot Zed <NotZed@HelixCode.com>2000-10-24 10:33:08 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-10-24 10:33:08 +0800
commit04780422995146b73e64c37ad79f42516c77d52e (patch)
tree12663cb6be8533f50e7820563f1b705f2c5f6231
parentbdb308067c223640c2c14ebd92205e0ae1d20326 (diff)
downloadgsoc2013-evolution-04780422995146b73e64c37ad79f42516c77d52e.tar
gsoc2013-evolution-04780422995146b73e64c37ad79f42516c77d52e.tar.gz
gsoc2013-evolution-04780422995146b73e64c37ad79f42516c77d52e.tar.bz2
gsoc2013-evolution-04780422995146b73e64c37ad79f42516c77d52e.tar.lz
gsoc2013-evolution-04780422995146b73e64c37ad79f42516c77d52e.tar.xz
gsoc2013-evolution-04780422995146b73e64c37ad79f42516c77d52e.tar.zst
gsoc2013-evolution-04780422995146b73e64c37ad79f42516c77d52e.zip
Dumps the contents of indexs.
2000-10-24 Not Zed <NotZed@HelixCode.com> * dumpindex.c: Dumps the contents of indexs. * hash.c (ibex_hash_dump_rec): Also print the word count. * wordindex.c (unindex_name): Cross-check the cache as well. svn path=/trunk/; revision=6139
-rw-r--r--libibex/ChangeLog8
-rw-r--r--libibex/Makefile.am6
-rw-r--r--libibex/dumpindex.c32
-rw-r--r--libibex/hash.c20
-rw-r--r--libibex/wordindex.c31
5 files changed, 91 insertions, 6 deletions
diff --git a/libibex/ChangeLog b/libibex/ChangeLog
index ec753aa483..212169fcfa 100644
--- a/libibex/ChangeLog
+++ b/libibex/ChangeLog
@@ -1,3 +1,11 @@
+2000-10-24 Not Zed <NotZed@HelixCode.com>
+
+ * dumpindex.c: Dumps the contents of indexs.
+
+ * hash.c (ibex_hash_dump_rec): Also print the word count.
+
+ * wordindex.c (unindex_name): Cross-check the cache as well.
+
2000-10-12 Not Zed <NotZed@HelixCode.com>
* ibex_internal.h (struct ibex): Bumped ibex rev.
diff --git a/libibex/Makefile.am b/libibex/Makefile.am
index cfd8a1b4d5..fdde10aca3 100644
--- a/libibex/Makefile.am
+++ b/libibex/Makefile.am
@@ -21,10 +21,10 @@ INCLUDES = -I$(srcdir) $(GLIB_CFLAGS) $(UNICODE_CFLAGS) \
-DG_LOG_DOMAIN=\"libibex\"
-#noinst_PROGRAMS = hash
+noinst_PROGRAMS = dumpindex
-#hash_SOURCES = disktail.c
-#hash_LDADD = libibex.la $(GLIB_LIBS) $(UNICODE_LIBS)
+dumpindex_SOURCES = dumpindex.c
+dumpindex_LDADD = libibex.la $(GLIB_LIBS) $(UNICODE_LIBS)
#noinst_PROGRAMS = mkindex lookup
#
diff --git a/libibex/dumpindex.c b/libibex/dumpindex.c
new file mode 100644
index 0000000000..92f4b08845
--- /dev/null
+++ b/libibex/dumpindex.c
@@ -0,0 +1,32 @@
+/*
+ Dump the hash tables from an ibex file.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "ibex_internal.h"
+
+extern void ibex_hash_dump(struct _IBEXIndex *index);
+
+int main(int argc, char **argv)
+{
+ ibex *ib;
+
+ if (argc != 2) {
+ printf("Usage: %s ibexfile\n", argv[0]);
+ return 1;
+ }
+ ib = ibex_open(argv[1], O_RDONLY, 0);
+ if (ib == NULL) {
+ perror("Opening ibex file\n");
+ return 1;
+ }
+
+ ibex_hash_dump(ib->words->wordindex);
+ ibex_hash_dump(ib->words->nameindex);
+
+ ibex_close(ib);
+
+ return 0;
+}
diff --git a/libibex/hash.c b/libibex/hash.c
index 25a6e92ef9..9395e1e00b 100644
--- a/libibex/hash.c
+++ b/libibex/hash.c
@@ -622,9 +622,20 @@ hash_insert(struct _IBEXIndex *index, const char *key, int keylen)
/* debug */
void ibex_hash_dump(struct _IBEXIndex *index);
+static void ibex_hash_dump_rec(struct _IBEXIndex *index, int *words, int *wordslen);
-void
-ibex_hash_dump(struct _IBEXIndex *index)
+void ibex_hash_dump(struct _IBEXIndex *index)
+{
+ int words = 0, wordslen=0;
+
+ ibex_hash_dump_rec(index, &words, &wordslen);
+
+ printf("Total words = %d, bytes = %d, ave length = %f\n", words, wordslen, (double)wordslen/(double)words);
+}
+
+
+static void
+ibex_hash_dump_rec(struct _IBEXIndex *index, int *words, int *wordslen)
{
int i;
struct _hashtableblock *table;
@@ -643,6 +654,8 @@ ibex_hash_dump(struct _IBEXIndex *index)
while (hashbucket) {
int len;
+ *words = *words + 1;
+
bucket = (struct _hashblock *)ibex_block_read(index->blocks, HASH_BLOCK(hashbucket));
printf(" bucket %d: [used %d]", hashbucket, bucket->used);
if (HASH_INDEX(hashbucket) == 0) {
@@ -655,6 +668,9 @@ ibex_hash_dump(struct _IBEXIndex *index)
printf("'%.*s' = %d next=%d\n", len, &bucket->hb_keydata[bucket->hb_keys[HASH_INDEX(hashbucket)].keyoffset],
bucket->hb_keys[HASH_INDEX(hashbucket)].root,
bucket->hb_keys[HASH_INDEX(hashbucket)].next);
+
+ *wordslen = *wordslen + len;
+
ibex_diskarray_dump(index->blocks,
bucket->hb_keys[HASH_INDEX(hashbucket)].root << BLOCK_BITS,
bucket->hb_keys[HASH_INDEX(hashbucket)].tail);
diff --git a/libibex/wordindex.c b/libibex/wordindex.c
index da25389b27..62e8859e15 100644
--- a/libibex/wordindex.c
+++ b/libibex/wordindex.c
@@ -145,6 +145,8 @@ static void unindex_name(struct _IBEXWord *idx, const char *name)
int i;
nameid_t nameid, wordid;
blockid_t nameblock, wordblock, newblock, nametail, wordtail, newtail;
+ char *word;
+ struct _wordcache *cache;
d(printf("unindexing %s\n", name));
@@ -168,7 +170,34 @@ static void unindex_name(struct _IBEXWord *idx, const char *name)
if (newblock != wordblock || newtail != wordtail)
idx->wordindex->klass->set_data(idx->wordindex, wordid, newblock, newtail);
- /* FIXME: check cache as well */
+ /* now check the cache as well */
+ word = idx->nameindex->klass->get_key(idx->wordindex, wordid, NULL);
+ if (word) {
+ cache = g_hash_table_lookup(idx->wordcache, word);
+ if (cache) {
+ /* its there, update our head/tail pointers */
+ cache->wordblock = newblock;
+ cache->wordtail = newtail;
+
+ /* now check that we have a data entry in it */
+ if (cache->filealloc == 0 && cache->filecount == 1) {
+ if (cache->file.file0 == nameid) {
+ cache->filecount = 0;
+ }
+ } else {
+ int j;
+
+ for (j=0;j<cache->filecount;j++) {
+ if (cache->file.files[j] == nameid) {
+ cache->file.files[j] = cache->file.files[cache->filecount-1];
+ cache->filecount--;
+ break;
+ }
+ }
+ }
+ }
+ g_free(word);
+ }
}
g_array_free(words, TRUE);