Work on dict_compact routine.
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 9 Mar 1999 13:07:05 +0000 (13:07 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 9 Mar 1999 13:07:05 +0000 (13:07 +0000)
dict/Makefile.in
dict/dcompact.c [new file with mode: 0644]
dict/open.c
include/dict.h

index 6cc7efe..620863d 100644 (file)
@@ -1,7 +1,7 @@
 # Copyright (C) 1994-1998, Index Data 
 # All rights reserved.
 # Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile.in,v 1.2 1998-10-28 15:20:46 adam Exp $
+# $Id: Makefile.in,v 1.3 1999-03-09 13:07:05 adam Exp $
 
 SHELL=/bin/sh
 
@@ -20,7 +20,7 @@ TPROG2=dictext
 DEFS=$(CDEFS) $(INCLUDE)
 LIB=../lib/dict.a 
 PO = scan.o dopen.o dclose.o drdwr.o open.o close.o insert.o lookup.o \
- lookupec.o lookgrep.o delete.o
+ lookupec.o lookgrep.o delete.o dcompact.o
 
 all: $(LIB)
 
diff --git a/dict/dcompact.c b/dict/dcompact.c
new file mode 100644 (file)
index 0000000..6dd4165
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 1994-1999, Index Data
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: dcompact.c,v $
+ * Revision 1.1  1999-03-09 13:07:06  adam
+ * Work on dict_compact routine.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <log.h>
+#include <dict.h>
+
+int dict_compact (BFiles bfs, const char *from_name, const char *to_name)
+{
+    int no_dir = 0;
+    Dict from, to;
+    int *map, i;
+    map = xmalloc (100);
+    from = dict_open (bfs, from_name, 0, 0);
+    if (!from)
+       return -1;
+    map = xmalloc ((from->head.last+1) * sizeof(*map));
+    for (i = 0; i <= from->head.last; i++)
+       map[i] = -1;
+    to = dict_open (bfs, to_name, 0, 1);
+    if (!to)
+       return -1;
+    map[0] = 0;
+    map[1] = DICT_pagesize(from);
+    
+    for (i = 1; i < from->head.last; i++)
+    {
+       void *buf;
+       logf (LOG_LOG, "map[%d] = %d", i, map[i]);
+       dict_bf_readp (from->dbf, i, &buf);
+       map[i+1] = map[i] + DICT_size(buf);
+       no_dir += DICT_nodir(buf);
+    }
+    logf (LOG_LOG, "map[%d] = %d", i, map[i]);
+    logf (LOG_LOG, "nodir = %d", no_dir);
+    dict_close (from);
+    dict_close (to);
+    return 0;
+}
index ad42795..a38076b 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: open.c,v $
- * Revision 1.13  1999-02-02 14:50:27  adam
+ * Revision 1.14  1999-03-09 13:07:06  adam
+ * Work on dict_compact routine.
+ *
+ * Revision 1.13  1999/02/02 14:50:27  adam
  * Updated WIN32 code specific sections. Changed header.
  *
  * Revision 1.12  1997/09/17 12:19:07  adam
@@ -64,6 +67,8 @@ Dict dict_open (BFiles bfs, const char *name, int cache, int rw)
 
     dict = xmalloc (sizeof(*dict));
 
+    if (cache < 5)
+       cache = 5;
     sprintf (resource_str, "dict.%s.pagesize", name);
 
     dict->grep_cmap = NULL;
index 6e4daf5..4b75eea 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: dict.h,v $
- * Revision 1.27  1999-02-02 14:50:32  adam
+ * Revision 1.28  1999-03-09 13:07:06  adam
+ * Work on dict_compact routine.
+ *
+ * Revision 1.27  1999/02/02 14:50:32  adam
  * Updated WIN32 code specific sections. Changed header.
  *
  * Revision 1.26  1997/09/18 08:59:18  adam
@@ -184,6 +187,7 @@ int    dict_scan (Dict dict, char *str,
 void       dict_grep_cmap (Dict dict, void *vp,
                            const char **(*cmap)(void *vp,
                                                const char **from, int len));
+int        dict_compact (BFiles bfs, const char *from, const char *to);
 
 
 #define DICT_EOS        0