Use cache in dict - not in bfile.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 17 Aug 1994 13:32:18 +0000 (13:32 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 17 Aug 1994 13:32:18 +0000 (13:32 +0000)
dict/Makefile
dict/close.c
dict/insert.c
dict/open.c
include/bfile.h
include/dict.h

index a4c366a..cfe927c 100644 (file)
@@ -1,7 +1,7 @@
 # Copyright (C) 1994, Index Data I/S 
 # All rights reserved.
 # Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile,v 1.1 1994-08-16 16:26:46 adam Exp $
+# $Id: Makefile,v 1.2 1994-08-17 13:32:18 adam Exp $
 
 SHELL=/bin/sh
 INCLUDE=-I../include
@@ -9,7 +9,7 @@ TPROG=dicttest
 CFLAGS=-g -Wall
 DEFS=$(INCLUDE)
 LIB=../lib/dict.a 
-PO = open.o close.o insert.o lookup.o
+PO = dopen.o dclose.o drdwr.o open.o close.o insert.o lookup.o 
 CPP=cc -E
 
 all: $(LIB)
index 3c8cddf..2d499d6 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: close.c,v $
- * Revision 1.1  1994-08-16 16:26:47  adam
+ * Revision 1.2  1994-08-17 13:32:19  adam
+ * Use cache in dict - not in bfile.
+ *
+ * Revision 1.1  1994/08/16  16:26:47  adam
  * Added dict.
  *
  */
@@ -20,7 +23,7 @@ int dict_close (Dict dict)
 {
     assert (dict);
     
-    bf_close (dict->bf);
+    dict_bf_close (dict->dbf);
     free (dict);
     return 0;
 }
index 94fe205..8d1cffb 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: insert.c,v $
- * Revision 1.1  1994-08-16 16:26:48  adam
+ * Revision 1.2  1994-08-17 13:32:19  adam
+ * Use cache in dict - not in bfile.
+ *
+ * Revision 1.1  1994/08/16  16:26:48  adam
  * Added dict.
  *
  */
@@ -24,11 +27,11 @@ static Dict_ptr new_page (Dict dict, Dict_ptr back_ptr, void **pp)
     {
         dict->head.free_list++;
         dict->head.last = dict->head.free_list;
-        bf_newp (dict->bf, ptr, &p);
+        dict_bf_newp (dict->dbf, ptr, &p);
     }
     else
     {
-        bf_readp (dict->bf, dict->head.free_list, &p);
+        dict_bf_readp (dict->dbf, dict->head.free_list, &p);
         dict->head.free_list = DICT_nextptr(p);
         if (dict->head.free_list == 0)
             dict->head.free_list = dict->head.last;
@@ -70,7 +73,7 @@ static int dict_ins (Dict dict, const Dict_char *str, Dict_ptr back_ptr,
                 if (memcmp (info+sizeof(Dict_ptr), userinfo, sizeof(userinfo)))
                 {
                     memcpy (info+sizeof(Dict_ptr), userinfo, sizeof(userinfo));
-                    bf_touch (dict->bf, ptr);
+                    dict_bf_touch (dict->dbf, ptr);
                 }
                 return 0;
             }
@@ -93,7 +96,7 @@ static int dict_ins (Dict dict, const Dict_char *str, Dict_ptr back_ptr,
                 {
                     subptr = new_page (dict, ptr, &pp);
                     memcpy (info, &subptr, sizeof(subptr));
-                    bf_touch (dict->bf, ptr);
+                    dict_bf_touch (dict->dbf, ptr);
                 }
                 return dict_ins (dict, str+1, ptr, pp, userinfo);
             }
index fda7f4f..8068454 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: open.c,v $
- * Revision 1.1  1994-08-16 16:26:49  adam
+ * Revision 1.2  1994-08-17 13:32:20  adam
+ * Use cache in dict - not in bfile.
+ *
+ * Revision 1.1  1994/08/16  16:26:49  adam
  * Added dict.
  *
  */
@@ -24,21 +27,18 @@ Dict dict_open (const char *name, int cache, int rw)
 
     dict = xmalloc (sizeof(*dict));
 
-    if (rw)
-        dict->bf = bf_open_w (name, DICT_PAGESIZE, cache);
-    else
-        dict->bf = bf_open (name, DICT_PAGESIZE, cache);
+    dict->dbf = dict_bf_open (name, DICT_PAGESIZE, cache, rw);
 
-    if(!dict->bf)
+    if(!dict->dbf)
     {
         free (dict);
         return NULL;
     }
-    if (bf_read (dict->bf, 0, &head_buf) <= 0)
+    if (dict_bf_readp (dict->dbf, 0, &head_buf) <= 0)
     {
         if (rw) 
         {   /* create header with information (page 0) */
-            bf_newp (dict->bf, 0, &head_buf);
+            dict_bf_newp (dict->dbf, 0, &head_buf);
             dh = (struct Dict_head *) head_buf;
             strcpy(dh->magic_str, DICT_MAGIC);
             dh->free_list = dh->last = 1;
@@ -56,13 +56,13 @@ Dict dict_open (const char *name, int cache, int rw)
         dh = (struct Dict_head *) head_buf;
         if (!strcmp (dh->magic_str, DICT_MAGIC))
         {
-            bf_close (dict->bf);
+            dict_bf_close (dict->dbf);
             free (dict);
             return NULL;
         }
         if (dh->page_size != DICT_PAGESIZE)
         {
-            bf_close (dict->bf);
+            dict_bf_close (dict->dbf);
             free (dict);
             return NULL;
         }
index bae4b03..2262915 100644 (file)
@@ -4,53 +4,27 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: bfile.h,v $
- * Revision 1.1  1994-08-16 16:16:02  adam
+ * Revision 1.2  1994-08-17 13:32:33  adam
+ * Use cache in dict - not in bfile.
+ *
+ * Revision 1.1  1994/08/16  16:16:02  adam
  * bfile header created.
  *
  */
 
 #ifndef BFILE_H
 #define BFILE_H
-struct BFile_block
-{
-    struct BFile_block *h_next, **h_prev;
-    struct BFile_block *lru_next, *lru_prev;
-    void *data;
-    int dirty;
-    int no;
-};
+#include <util.h>
 
 typedef struct BFile_struct
 {
     int fd;
     int block_size;
-    int cache;
-    struct BFile_block *all_blocks;
-    struct BFile_block *free_list;
-    struct BFile_block **hash_array;
-
-    struct BFile_block *lru_back, *lru_front;
-    int hash_size;
-    void *all_data;
-
-    int  hits;
-    int  misses;
 } *BFile;
 
 int bf_close (BFile);
-BFile bf_open (const char *name, int block_size, int cache);
-BFile bf_open_w (const char *name, int block_size, int cache);
+BFile bf_open (const char *name, int block_size, int rw);
 int bf_read (BFile bf, int no, void *buf);
 int bf_write (BFile bf, int no, const void *buf);
 
-int bf_readp (BFile bf, int no, void **bufp);
-int bf_newp (BFile bf, int no, void **bufp);
-int bf_touch (BFile bf, int no);
-void bf_flush_blocks (BFile bf, int no_to_flush);
-
-void *xmalloc_f (size_t size);
-#define xmalloc(x) xmalloc_f(x)
-
-extern char *prog;
-
 #endif
index 42431a0..8ca8378 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: dict.h,v $
- * Revision 1.1  1994-08-16 16:26:53  adam
+ * Revision 1.2  1994-08-17 13:32:33  adam
+ * Use cache in dict - not in bfile.
+ *
+ * Revision 1.1  1994/08/16  16:26:53  adam
  * Added dict.
  *
  */
@@ -23,11 +26,43 @@ struct Dict_head {
     Dict_ptr free_list, last;
 };
 
-typedef struct Dict_struct {
+struct Dict_file_block
+{
+    struct Dict_file_block *h_next, **h_prev;
+    struct Dict_file_block *lru_next, *lru_prev;
+    void *data;
+    int dirty;
+    int no;
+};
+
+typedef struct Dict_file_struct
+{
+    int cache;
     BFile bf;
+
+    struct Dict_file_block *all_blocks;
+    struct Dict_file_block *free_list;
+    struct Dict_file_block **hash_array;
+
+    struct Dict_file_block *lru_back, *lru_front;
+    int hash_size;
+    void *all_data;
+
+    int  hits;
+    int  misses;
+} *Dict_BFile;
+
+typedef struct Dict_struct {
+    Dict_BFile dbf;
     struct Dict_head head;
 } *Dict;
 
+int dict_bf_readp (Dict_BFile bf, int no, void **bufp);
+int dict_bf_newp (Dict_BFile bf, int no, void **bufp);
+int dict_bf_touch (Dict_BFile bf, int no);
+void dict_bf_flush_blocks (Dict_BFile bf, int no_to_flush);
+Dict_BFile dict_bf_open (const char *name, int block_size, int cache, int rw);
+int dict_bf_close (Dict_BFile dbf);
 #define DICT_MAGIC "dict00"
 
 typedef int Dict_info;
@@ -51,7 +86,6 @@ int dict_strlen (const Dict_char *s);
 
 #define DICT_to_str(x)  sizeof(Dict_info)+sizeof(Dict_ptr)
 
-
 /*
    type            type of page
    backptr         pointer to parent