From: Adam Dickmeiss Date: Wed, 17 Aug 1994 13:32:18 +0000 (+0000) Subject: Use cache in dict - not in bfile. X-Git-Tag: ZEBRA.1.0~918 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=cf0045decc8edc53834fffc1eadf8a634cf81381 Use cache in dict - not in bfile. --- diff --git a/dict/Makefile b/dict/Makefile index a4c366a..cfe927c 100644 --- a/dict/Makefile +++ b/dict/Makefile @@ -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) diff --git a/dict/close.c b/dict/close.c index 3c8cddf..2d499d6 100644 --- a/dict/close.c +++ b/dict/close.c @@ -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; } diff --git a/dict/insert.c b/dict/insert.c index 94fe205..8d1cffb 100644 --- a/dict/insert.c +++ b/dict/insert.c @@ -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); } diff --git a/dict/open.c b/dict/open.c index fda7f4f..8068454 100644 --- a/dict/open.c +++ b/dict/open.c @@ -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; } diff --git a/include/bfile.h b/include/bfile.h index bae4b03..2262915 100644 --- a/include/bfile.h +++ b/include/bfile.h @@ -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 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 diff --git a/include/dict.h b/include/dict.h index 42431a0..8ca8378 100644 --- a/include/dict.h +++ b/include/dict.h @@ -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