2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1994-08-18 12:40:56 adam
8 * Some development of dictionary. Not finished at all!
10 * Revision 1.2 1994/08/17 13:32:19 adam
11 * Use cache in dict - not in bfile.
13 * Revision 1.1 1994/08/16 16:26:48 adam
25 static Dict_ptr new_page (Dict dict, Dict_ptr back_ptr, void **pp)
28 Dict_ptr ptr = dict->head.free_list;
29 if (dict->head.free_list == dict->head.last)
31 dict->head.free_list++;
32 dict->head.last = dict->head.free_list;
33 dict_bf_newp (dict->dbf, ptr, &p);
37 dict_bf_readp (dict->dbf, dict->head.free_list, &p);
38 dict->head.free_list = DICT_nextptr(p);
39 if (dict->head.free_list == 0)
40 dict->head.free_list = dict->head.last;
44 DICT_backptr(p) = back_ptr;
47 DICT_size(p) = DICT_infoffset;
52 static int dict_ins (Dict dict, const Dict_char *str, Dict_ptr back_ptr,
53 void *p, void *userinfo)
56 Dict_ptr ptr = back_ptr, subptr;
57 short *indxp, *indxp1;
61 ptr = new_page (dict, back_ptr, &p);
65 indxp = (short*) ((char*) p+DICT_PAGESIZE);
66 for (i = DICT_nodir (p); --i >= 0; )
70 if (*--indxp > 0) /* tail string here! */
73 cmp = dict_strcmp ((Dict_char*)
74 (info+sizeof(Dict_info)+sizeof(Dict_ptr)),
78 if (memcmp (info+sizeof(Dict_ptr), userinfo, sizeof(userinfo)))
80 memcpy (info+sizeof(Dict_ptr), userinfo, sizeof(userinfo));
81 dict_bf_touch (dict->dbf, ptr);
88 else /* tail of string in sub page */
92 cmp = memcmp (info+sizeof(Dict_info)+sizeof(Dict_ptr), str,
98 memcpy (&subptr, info, sizeof(subptr));
101 subptr = new_page (dict, ptr, &pp);
102 memcpy (info, &subptr, sizeof(subptr));
103 dict_bf_touch (dict->dbf, ptr);
105 return dict_ins (dict, str+1, ptr, pp, userinfo);
111 newsize = DICT_size(p);
113 memcpy (p+newsize, &subptr, sizeof(subptr));
114 memcpy (p+newsize + sizeof(Dict_ptr), userinfo, sizeof(Dict_info));
115 memcpy (p+newsize + sizeof(Dict_ptr)+sizeof(Dict_info), str,
116 dict_strlen (str)+1);
118 indxp1 = (short*)((char*) p + DICT_PAGESIZE - DICT_nodir(p)*sizeof(short));
119 for (; indxp1 != indxp; indxp1++)
120 indxp1[0] = indxp1[1];
123 DICT_size(p) = newsize + sizeof(Dict_info)+sizeof(Dict_ptr)
124 +dict_strlen (str)+1;
128 int dict_insert (Dict dict, const Dict_char *str, void *userinfo)
131 if (dict->head.last == 1)
132 dict_ins (dict, str, 0, NULL, userinfo);
135 dict_bf_readp (dict->dbf, 1, &p);
136 dict_ins (dict, str, 1, p, userinfo);