2 * Copyright (C) 1994-2000, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 2000-12-05 09:59:10 adam
8 * Work on dict_delete_subtree.
10 * Revision 1.6 1999/05/15 14:36:37 adam
11 * Updated dictionary. Implemented "compression" of dictionary.
13 * Revision 1.5 1999/02/02 14:50:17 adam
14 * Updated WIN32 code specific sections. Changed header.
16 * Revision 1.4 1996/02/02 13:43:50 adam
17 * The public functions simply use char instead of Dict_char to represent
18 * search strings. Dict_char is used internally only.
20 * Revision 1.3 1995/12/07 11:48:55 adam
21 * Insert operation obeys DICT_type = 1 (slack in page).
22 * Function dict_open exists if page size or magic aren't right.
24 * Revision 1.2 1995/12/06 17:48:30 adam
25 * Bug fix: delete didn't work.
27 * Revision 1.1 1995/12/06 14:52:21 adam
28 * New function: dict_delete.
39 static void dict_del_subtree (Dict dict, Dict_ptr ptr,
41 int (*f)(const char *, void *))
54 dict_bf_readp (dict->dbf, ptr, &p);
56 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
58 for (i = 0; i <= hi; i++)
62 /* string (Dict_char *) DICT_EOS terminated */
63 /* unsigned char length of information */
64 /* char * information */
65 char *info = (char*)p + indxp[-i];
67 (*f)(info + (dict_strlen((Dict_char*) info)+1)
68 *sizeof(Dict_char), client);
76 /* Dict_char sub char */
77 /* unsigned char length of information */
78 /* char * information */
79 char *info = (char*)p - indxp[-i];
80 memcpy (&subptr, info, sizeof(Dict_ptr));
82 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
85 (*f)(info+sizeof(Dict_ptr)+sizeof(Dict_char), client);
89 dict_del_subtree (dict, subptr, client, f);
96 DICT_backptr(p) = dict->head.freelist;
97 dict->head.freelist = ptr;
98 dict_bf_touch (dict->dbf, ptr);
101 static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr,
102 int sub_flag, void *client,
103 int (*f)(const char *, void *))
113 dict_bf_readp (dict->dbf, ptr, &p);
115 hi = DICT_nodir(p)-1;
116 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
122 /* string (Dict_char *) DICT_EOS terminated */
123 /* unsigned char length of information */
124 /* char * information */
125 info = (char*)p + indxp[-mid];
127 cmp = dict_strcmp((Dict_char*) info, str);
130 /* determine if prefix match */
131 if (!dict_strncmp (str, (Dict_char*) info, dict_strlen(str)))
134 (*f)(info + (dict_strlen((Dict_char*) info)+1)
135 *sizeof(Dict_char), client);
137 hi = DICT_nodir(p)-1;
140 indxp[-mid] = indxp[-mid-1];
145 dict_bf_touch (dict->dbf, ptr);
148 /* start again (may not be the most efficient way to go)*/
154 /* normal delete: delete if equal */
157 hi = DICT_nodir(p)-1;
160 indxp[-mid] = indxp[-mid-1];
165 dict_bf_touch (dict->dbf, ptr);
175 /* Dict_ptr subptr */
176 /* Dict_char sub char */
177 /* unsigned char length of information */
178 /* char * information */
179 info = (char*)p - indxp[-mid];
180 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
184 memcpy (&subptr, info, sizeof(Dict_ptr));
185 if (*++str == DICT_EOS)
187 if (sub_flag && subptr)
190 memcpy (info, &null_ptr, sizeof(Dict_ptr));
192 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
194 info[sizeof(Dict_ptr)+sizeof(Dict_char)] = 0;
196 dict_bf_touch (dict->dbf, ptr);
199 (*f)(info+sizeof(Dict_ptr)+sizeof(Dict_char),
201 if (sub_flag && subptr)
202 dict_del_subtree (dict, subptr, client, f);
205 if (sub_flag && subptr)
208 dict_bf_touch (dict->dbf, ptr);
209 dict_del_subtree (dict, subptr, client, f);
218 dict_bf_readp (dict->dbf, ptr, &p);
220 hi = DICT_nodir(p)-1;
221 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
234 int dict_delete (Dict dict, const char *p)
236 return dict_del_string (dict, (const Dict_char*) p, dict->head.root, 0,
240 int dict_delete_subtree (Dict dict, const char *p, void *client,
241 int (*f)(const char *info, void *client))
243 return dict_del_string (dict, (const Dict_char*) p, dict->head.root, 1,