From: Adam Dickmeiss Date: Wed, 5 Oct 1994 12:16:48 +0000 (+0000) Subject: Pagesize is a resource now. X-Git-Tag: ZEBRA.1.0~818 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=30bfffa1e13e0ebd1d7eac84518705e2fbcd955b;p=idzebra-moved-to-github.git Pagesize is a resource now. --- diff --git a/dict/insert.c b/dict/insert.c index ff99b66..70a18b4 100644 --- a/dict/insert.c +++ b/dict/insert.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: insert.c,v $ - * Revision 1.9 1994-09-16 15:39:13 adam + * Revision 1.10 1994-10-05 12:16:48 adam + * Pagesize is a resource now. + * + * Revision 1.9 1994/09/16 15:39:13 adam * Initial code of lookup - not tested yet. * * Revision 1.8 1994/09/16 12:35:01 adam @@ -90,7 +93,7 @@ static int split_page (Dict dict, Dict_ptr ptr, void *p) int best_no = -1, no_current = 1; /* determine splitting char... */ - indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short)); for (i = DICT_nodir (p); --i >= 0; --indxp) { if (*indxp > 0) /* tail string here! */ @@ -163,8 +166,8 @@ static void clean_page (Dict dict, Dict_ptr ptr, void *p, Dict_char *out, short *indxp1, *indxp2; char *info1, *info2; - indxp1 = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); - indxp2 = (short*) ((char*) np+DICT_PAGESIZE); + indxp1 = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short)); + indxp2 = (short*) ((char*) np+DICT_pagesize(dict)); info2 = (char*) np + DICT_infoffset; for (i = DICT_nodir (p); --i >= 0; --indxp1) { @@ -221,7 +224,7 @@ static void clean_page (Dict dict, Dict_ptr ptr, void *p, Dict_char *out, ++no; } memcpy ((char*)p+DICT_infoffset, (char*)np+DICT_infoffset, - DICT_PAGESIZE-DICT_infoffset); + DICT_pagesize(dict)-DICT_infoffset); DICT_size(p) = info2 - np; DICT_type(p) = 0; DICT_nodir(p) = no; @@ -254,7 +257,7 @@ static int dict_ins (Dict dict, const Dict_char *str, mid = lo = 0; hi = DICT_nodir(p)-1; - indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short)); while (lo <= hi) { mid = (lo+hi)/2; @@ -333,7 +336,7 @@ static int dict_ins (Dict dict, const Dict_char *str, } if (DICT_size(p)+sizeof(Dict_char)+sizeof(Dict_ptr)+ userlen >= - DICT_PAGESIZE - (1+DICT_nodir(p))*sizeof(short)) + DICT_pagesize(dict) - (1+DICT_nodir(p))*sizeof(short)) { if (DICT_type(p) == 1) { @@ -388,7 +391,7 @@ static int dict_ins (Dict dict, const Dict_char *str, --indxp; slen = (dict_strlen(str)+1)*sizeof(Dict_char); if (DICT_size(p)+slen+userlen >= - DICT_PAGESIZE - (1+DICT_nodir(p))*sizeof(short)) /* overflow? */ + DICT_pagesize(dict) - (1+DICT_nodir(p))*sizeof(short)) /* overflow? */ { split_page (dict, ptr, p); return dict_ins (dict, str, ptr, userlen, userinfo); @@ -397,12 +400,12 @@ static int dict_ins (Dict dict, const Dict_char *str, { short *indxp1; (DICT_nodir(p))++; - indxp1 = (short*)((char*) p + DICT_PAGESIZE + indxp1 = (short*)((char*) p + DICT_pagesize(dict) - DICT_nodir(p)*sizeof(short)); for (; indxp1 != indxp; indxp1++) indxp1[0] = indxp1[1]; #if CHECK - indxp1 = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + indxp1 = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short)); for (i = DICT_nodir (p); --i >= 0; --indxp1) { if (*indxp1 < 0) diff --git a/dict/lookgrep.c b/dict/lookgrep.c index b464e95..f4ba71a 100644 --- a/dict/lookgrep.c +++ b/dict/lookgrep.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lookgrep.c,v $ - * Revision 1.2 1994-10-04 12:08:07 adam + * Revision 1.3 1994-10-05 12:16:50 adam + * Pagesize is a resource now. + * + * Revision 1.2 1994/10/04 12:08:07 adam * Some bug fixes and some optimizations. * * Revision 1.1 1994/10/03 17:23:04 adam @@ -233,7 +236,7 @@ static int dict_grep (Dict dict, Dict_ptr ptr, MatchContext *mc, dict_bf_readp (dict->dbf, ptr, &p); lo = 0; hi = DICT_nodir(p)-1; - indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short)); while (lo <= hi) { @@ -313,7 +316,8 @@ static int dict_grep (Dict dict, Dict_ptr ptr, MatchContext *mc, dict_grep (dict, subptr, mc, Rj1, pos+1, userfunc, prefix, dfas); dict_bf_readp (dict->dbf, ptr, &p); - indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + indxp = (short*) ((char*) p+DICT_pagesize(dict) + -sizeof(short)); } } } diff --git a/dict/lookup.c b/dict/lookup.c index 9f2a21e..19eaf9a 100644 --- a/dict/lookup.c +++ b/dict/lookup.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lookup.c,v $ - * Revision 1.3 1994-09-26 10:17:25 adam + * Revision 1.4 1994-10-05 12:16:51 adam + * Pagesize is a resource now. + * + * Revision 1.3 1994/09/26 10:17:25 adam * Minor changes. * * Revision 1.2 1994/09/16 15:39:14 adam @@ -34,7 +37,7 @@ static char *dict_look (Dict dict, Dict_char *str) dict_bf_readp (dict->dbf, ptr, &p); mid = lo = 0; hi = DICT_nodir(p)-1; - indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short)); while (lo <= hi) { mid = (lo+hi)/2; @@ -77,7 +80,8 @@ static char *dict_look (Dict dict, Dict_char *str) dict_bf_readp (dict->dbf, ptr, &p); mid = lo = 0; hi = DICT_nodir(p)-1; - indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + indxp = (short*) ((char*) p+DICT_pagesize(dict) + -sizeof(short)); continue; } } diff --git a/dict/lookupec.c b/dict/lookupec.c index 9147b17..85e2423 100644 --- a/dict/lookupec.c +++ b/dict/lookupec.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lookupec.c,v $ - * Revision 1.3 1994-09-26 16:31:06 adam + * Revision 1.4 1994-10-05 12:16:51 adam + * Pagesize is a resource now. + * + * Revision 1.3 1994/09/26 16:31:06 adam * Minor changes. * * Revision 1.2 1994/09/22 14:43:57 adam @@ -46,7 +49,7 @@ int dict_look_ec (Dict dict, Dict_ptr ptr, MatchInfo *mi, MatchWord *ri_base, dict_bf_readp (dict->dbf, ptr, &p); lo = 0; hi = DICT_nodir(p)-1; - indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short)); while (lo <= hi) { if (indxp[-lo] > 0) @@ -116,7 +119,7 @@ int dict_look_ec (Dict dict, Dict_ptr ptr, MatchInfo *mi, MatchWord *ri_base, dict_look_ec (dict, subptr, mi, ri, pos+1, userfunc, range, prefix); dict_bf_readp (dict->dbf, ptr, &p); - indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short)); } } } diff --git a/dict/open.c b/dict/open.c index e5319b3..e13b38c 100644 --- a/dict/open.c +++ b/dict/open.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: open.c,v $ - * Revision 1.5 1994-09-01 17:49:39 adam + * Revision 1.6 1994-10-05 12:16:52 adam + * Pagesize is a resource now. + * + * Revision 1.5 1994/09/01 17:49:39 adam * Removed stupid line. Work on insertion in dictionary. Not finished yet. * * Revision 1.4 1994/09/01 17:44:10 adam @@ -32,15 +35,26 @@ Dict dict_open (const char *name, int cache, int rw) Dict dict; void *head_buf; struct Dict_head *dh; + char resource_str[80]; + int page_size; dict = xmalloc (sizeof(*dict)); - dict->dbf = dict_bf_open (name, DICT_PAGESIZE, cache, rw); + sprintf (resource_str, "dict.%s.pagesize", name); + + page_size = atoi (res_get_def (common_resource, resource_str, + DICT_DEFAULT_PAGESIZE)); + if (page_size < 1024) + { + log (LOG_WARN, "Resource %s was too small. Set to 1024", resource_str); + page_size = 1024; + } + dict->dbf = dict_bf_open (name, page_size, cache, rw); dict->rw = rw; if(!dict->dbf) { - log (LOG_LOG, "cannot open `%s'", name); + log (LOG_WARN, "Cannot open `%s'", name); xfree (dict); return NULL; } @@ -52,13 +66,13 @@ Dict dict_open (const char *name, int cache, int rw) dh = (struct Dict_head *) head_buf; strcpy(dh->magic_str, DICT_MAGIC); dh->free_list = dh->last = 1; - dh->page_size = DICT_PAGESIZE; + dh->page_size = page_size; memcpy (&dict->head, dh, sizeof(*dh)); } else { /* no header present, i.e. no dictionary at all */ dict->head.free_list = dict->head.last = 0; - dict->head.page_size = DICT_PAGESIZE; + dict->head.page_size = page_size; } } else /* header was there, check magic and page size */ @@ -66,14 +80,15 @@ Dict dict_open (const char *name, int cache, int rw) dh = (struct Dict_head *) head_buf; if (strcmp (dh->magic_str, DICT_MAGIC)) { - log (LOG_LOG, "bad magic of `%s'", name); + log (LOG_WARN, "Bad magic of `%s'", name); dict_bf_close (dict->dbf); xfree (dict); return NULL; } - if (dh->page_size != DICT_PAGESIZE) + if (dh->page_size != page_size) { - log (LOG_LOG, "page size mismatch of `%s'", name); + log (LOG_WARN, "Resource %s is %d and pagesize of `%s' is %d", + resource_str, page_size, name, dh->page_size); dict_bf_close (dict->dbf); xfree (dict); return NULL; diff --git a/include/dict.h b/include/dict.h index a276e3c..a5f1eeb 100644 --- a/include/dict.h +++ b/include/dict.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dict.h,v $ - * Revision 1.9 1994-10-04 12:08:19 adam + * Revision 1.10 1994-10-05 12:16:58 adam + * Pagesize is a resource now. + * + * Revision 1.9 1994/10/04 12:08:19 adam * Minor changes. * * Revision 1.8 1994/10/03 17:23:11 adam @@ -23,7 +26,6 @@ * * Revision 1.4 1994/09/01 17:44:40 adam * Work on insertion in dictionary. Not finished yet. - * CVS ---------------------------------------------------------------------- * * Revision 1.3 1994/08/18 12:41:12 adam * Some development of dictionary. Not finished at all! @@ -86,7 +88,7 @@ typedef struct Dict_struct { #define DICT_MAGIC "dict00" -#define DICT_PAGESIZE 8192 +#define DICT_DEFAULT_PAGESIZE "8192" int dict_bf_readp (Dict_BFile bf, int no, void **bufp); int dict_bf_newp (Dict_BFile bf, int no, void **bufp); @@ -114,6 +116,7 @@ int dict_strlen (const Dict_char *s); #define DICT_nodir(x) 0[(short*)((char*)(x)+3*sizeof(Dict_ptr))] #define DICT_size(x) 1[(short*)((char*)(x)+3*sizeof(Dict_ptr))] #define DICT_infoffset (3*sizeof(Dict_ptr)+2*sizeof(short)) +#define DICT_pagesize(x) ((x)->head.page_size) #define DICT_to_str(x) sizeof(Dict_info)+sizeof(Dict_ptr)