2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1994-08-17 13:32:19 adam
8 * Use cache in dict - not in bfile.
10 * Revision 1.1 1994/08/16 16:26:48 adam
22 static Dict_ptr new_page (Dict dict, Dict_ptr back_ptr, void **pp)
25 Dict_ptr ptr = dict->head.free_list;
26 if (dict->head.free_list == dict->head.last)
28 dict->head.free_list++;
29 dict->head.last = dict->head.free_list;
30 dict_bf_newp (dict->dbf, ptr, &p);
34 dict_bf_readp (dict->dbf, dict->head.free_list, &p);
35 dict->head.free_list = DICT_nextptr(p);
36 if (dict->head.free_list == 0)
37 dict->head.free_list = dict->head.last;
41 DICT_backptr(p) = back_ptr;
49 static int dict_ins (Dict dict, const Dict_char *str, Dict_ptr back_ptr,
50 void *p, void *userinfo)
52 Dict_ptr ptr = back_ptr, subptr;
53 short *indxp, *indxp1, *indxp2;
56 ptr = new_page (dict, back_ptr, &p);
60 indxp = (short*) ((char*) p+DICT_PAGESIZE);
61 while (*str != DICT_EOS)
64 if (*--indxp > 0) /* tail string here! */
67 info = DICT_info(p) + *indxp;
68 cmp = dict_strcmp ((Dict_char*)
69 (info+sizeof(Dict_info)+sizeof(Dict_ptr)),
73 if (memcmp (info+sizeof(Dict_ptr), userinfo, sizeof(userinfo)))
75 memcpy (info+sizeof(Dict_ptr), userinfo, sizeof(userinfo));
76 dict_bf_touch (dict->dbf, ptr);
84 else if(*indxp < 0) /* tail of string in sub page */
87 info = DICT_info(p) - *indxp;
88 cmp = memcmp (info+sizeof(Dict_info)+sizeof(Dict_ptr), str,
94 memcpy (&subptr, info, sizeof(subptr));
97 subptr = new_page (dict, ptr, &pp);
98 memcpy (info, &subptr, sizeof(subptr));
99 dict_bf_touch (dict->dbf, ptr);
101 return dict_ins (dict, str+1, ptr, pp, userinfo);
109 newsize = DICT_size(p);
111 memcpy (DICT_info(p) + newsize, &subptr, sizeof(subptr));
112 memcpy (DICT_info(p) + newsize + sizeof(Dict_ptr), userinfo,
114 memcpy (DICT_info(p) + newsize + sizeof(Dict_ptr)+sizeof(Dict_info),
115 str, dict_strlen (str));
116 newsize = DICT_size(p) +
117 sizeof(Dict_info) + sizeof(Dict_ptr) + dict_strlen (str);
118 DICT_size (p) = newsize;
120 DICT_nodir(p) = DICT_nodir(p)+1;
121 indxp2 = (short*)((char*) p + DICT_PAGESIZE - DICT_nodir(p)*sizeof(short));
122 for (indxp1 = indxp2; indxp1 != indxp; indxp1++)
128 int dict_insert (Dict dict, const Dict_char *str, void *userinfo)
130 dict_ins (dict, str, 0, NULL, userinfo);