X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=dict%2Fdelete.c;h=3a9912f8deb3e0c9e425fe6f2580f9a881329774;hb=c0a1c79e55f706009113b2de3c11a6f13d4a0e7d;hp=4ede1137ca6c89a8ca238ecca4f33eafca0374b0;hpb=bfa7f970e514dfdfa067191f1b3fc30a004972bf;p=idzebra-moved-to-github.git diff --git a/dict/delete.c b/dict/delete.c index 4ede113..3a9912f 100644 --- a/dict/delete.c +++ b/dict/delete.c @@ -1,10 +1,27 @@ /* - * Copyright (C) 1994, Index Data I/S + * Copyright (C) 1994-1999, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: delete.c,v $ - * Revision 1.1 1995-12-06 14:52:21 adam + * Revision 1.6 1999-05-15 14:36:37 adam + * Updated dictionary. Implemented "compression" of dictionary. + * + * Revision 1.5 1999/02/02 14:50:17 adam + * Updated WIN32 code specific sections. Changed header. + * + * Revision 1.4 1996/02/02 13:43:50 adam + * The public functions simply use char instead of Dict_char to represent + * search strings. Dict_char is used internally only. + * + * Revision 1.3 1995/12/07 11:48:55 adam + * Insert operation obeys DICT_type = 1 (slack in page). + * Function dict_open exists if page size or magic aren't right. + * + * Revision 1.2 1995/12/06 17:48:30 adam + * Bug fix: delete didn't work. + * + * Revision 1.1 1995/12/06 14:52:21 adam * New function: dict_delete. * */ @@ -16,9 +33,8 @@ #include -static int dict_del (Dict dict, const Dict_char *str) +static int dict_del (Dict dict, const Dict_char *str, Dict_ptr ptr) { - Dict_ptr ptr = 1; int mid, lo, hi; int cmp; void *p; @@ -28,7 +44,7 @@ static int dict_del (Dict dict, const Dict_char *str) dict_bf_readp (dict->dbf, ptr, &p); mid = lo = 0; hi = DICT_nodir(p)-1; - indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short)); + indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short)); while (lo <= hi) { mid = (lo+hi)/2; @@ -41,11 +57,13 @@ static int dict_del (Dict dict, const Dict_char *str) cmp = dict_strcmp((Dict_char*) info, str); if (!cmp) { + hi = DICT_nodir(p)-1; while (mid < hi) { indxp[-mid] = indxp[-mid-1]; mid++; } + DICT_type(p) = 1; (DICT_nodir(p))--; dict_bf_touch (dict->dbf, ptr); return 1; @@ -71,6 +89,7 @@ static int dict_del (Dict dict, const Dict_char *str) if (info[sizeof(Dict_ptr)+sizeof(Dict_char)]) { info[sizeof(Dict_ptr)+sizeof(Dict_char)] = 0; + DICT_type(p) = 1; dict_bf_touch (dict->dbf, ptr); return 1; } @@ -84,8 +103,7 @@ static int dict_del (Dict dict, const Dict_char *str) dict_bf_readp (dict->dbf, ptr, &p); mid = lo = 0; hi = DICT_nodir(p)-1; - indxp = (short*) ((char*) p+DICT_pagesize(dict) - -sizeof(short)); + indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short)); continue; } } @@ -98,9 +116,9 @@ static int dict_del (Dict dict, const Dict_char *str) return 0; } -int dict_delete (Dict dict, const Dict_char *p) +int dict_delete (Dict dict, const char *p) { - if (dict->head.last == 1) + if (!dict->head.root) return 0; - return dict_del (dict, p); + return dict_del (dict, (const Dict_char*) p, dict->head.root); }