2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1994-08-16 16:26:48 adam
19 static Dict_ptr new_page (Dict dict, Dict_ptr back_ptr, void **pp)
22 Dict_ptr ptr = dict->head.free_list;
23 if (dict->head.free_list == dict->head.last)
25 dict->head.free_list++;
26 dict->head.last = dict->head.free_list;
27 bf_newp (dict->bf, ptr, &p);
31 bf_readp (dict->bf, dict->head.free_list, &p);
32 dict->head.free_list = DICT_nextptr(p);
33 if (dict->head.free_list == 0)
34 dict->head.free_list = dict->head.last;
38 DICT_backptr(p) = back_ptr;
46 static int dict_ins (Dict dict, const Dict_char *str, Dict_ptr back_ptr,
47 void *p, void *userinfo)
49 Dict_ptr ptr = back_ptr, subptr;
50 short *indxp, *indxp1, *indxp2;
53 ptr = new_page (dict, back_ptr, &p);
57 indxp = (short*) ((char*) p+DICT_PAGESIZE);
58 while (*str != DICT_EOS)
61 if (*--indxp > 0) /* tail string here! */
64 info = DICT_info(p) + *indxp;
65 cmp = dict_strcmp ((Dict_char*)
66 (info+sizeof(Dict_info)+sizeof(Dict_ptr)),
70 if (memcmp (info+sizeof(Dict_ptr), userinfo, sizeof(userinfo)))
72 memcpy (info+sizeof(Dict_ptr), userinfo, sizeof(userinfo));
73 bf_touch (dict->bf, ptr);
81 else if(*indxp < 0) /* tail of string in sub page */
84 info = DICT_info(p) - *indxp;
85 cmp = memcmp (info+sizeof(Dict_info)+sizeof(Dict_ptr), str,
91 memcpy (&subptr, info, sizeof(subptr));
94 subptr = new_page (dict, ptr, &pp);
95 memcpy (info, &subptr, sizeof(subptr));
96 bf_touch (dict->bf, ptr);
98 return dict_ins (dict, str+1, ptr, pp, userinfo);
106 newsize = DICT_size(p);
108 memcpy (DICT_info(p) + newsize, &subptr, sizeof(subptr));
109 memcpy (DICT_info(p) + newsize + sizeof(Dict_ptr), userinfo,
111 memcpy (DICT_info(p) + newsize + sizeof(Dict_ptr)+sizeof(Dict_info),
112 str, dict_strlen (str));
113 newsize = DICT_size(p) +
114 sizeof(Dict_info) + sizeof(Dict_ptr) + dict_strlen (str);
115 DICT_size (p) = newsize;
117 DICT_nodir(p) = DICT_nodir(p)+1;
118 indxp2 = (short*)((char*) p + DICT_PAGESIZE - DICT_nodir(p)*sizeof(short));
119 for (indxp1 = indxp2; indxp1 != indxp; indxp1++)
125 int dict_insert (Dict dict, const Dict_char *str, void *userinfo)
127 dict_ins (dict, str, 0, NULL, userinfo);