2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
14 #include "Eet_private.h"
17 eet_dictionary_add(void)
21 new = calloc(1, sizeof (Eet_Dictionary));
25 memset(new->hash, -1, sizeof (int) * 256);
31 eet_dictionary_free(Eet_Dictionary *ed)
37 for (i = 0; i < ed->count; ++i)
40 if (ed->all) free(ed->all);
46 _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
51 current = ed->hash[hash];
55 if (ed->all[current].str)
57 if (strcmp(ed->all[current].str, string) >= 0)
60 if (ed->all[current].mmap)
62 if (strcmp(ed->all[current].mmap, string) >= 0)
67 current = ed->all[current].next;
77 eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
88 hash = _eet_hash_gen(string, 8);
90 index = _eet_dictionary_lookup(ed, string, hash);
94 if (ed->all[index].str)
96 if (strcmp(ed->all[index].str, string) == 0)
99 if (ed->all[index].mmap)
101 if (strcmp(ed->all[index].mmap, string) == 0)
106 if (ed->total == ed->count)
111 total = ed->total + 8;
113 new = realloc(ed->all, sizeof (Eet_String) * total);
121 len = strlen(string) + 1;
122 str = strdup(string);
126 current = ed->all + ed->count;
128 current->flags.converted = 0;
129 current->flags.is_float = 0;
131 current->hash = hash;
135 current->mmap = NULL;
139 current->next = ed->hash[hash];
141 ed->hash[hash] = ed->count;
145 current->next = index;
146 current->prev = ed->all[index].prev;
148 if (current->next != -1)
149 ed->all[current->next].prev = ed->count;
150 if (current->prev != -1)
151 ed->all[current->prev].next = ed->count;
153 ed->hash[hash] = ed->count;
160 eet_dictionary_string_get_size(const Eet_Dictionary *ed, int index)
163 if (index < 0) return 0;
164 if (index < ed->count)
165 return ed->all[index].len;
170 eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int index)
173 if (index < 0) return -1;
174 if (index < ed->count)
175 return ed->all[index].hash;
180 eet_dictionary_string_get_char(const Eet_Dictionary *ed, int index)
182 if (!ed) return NULL;
183 if (index < 0) return NULL;
184 if (index < ed->count)
187 /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
188 if (ed->all[index].str == NULL)
190 ed->all[index].str = strdup(ed->all[index].mmap);
191 ed->all[index].mmap = NULL;
194 if (ed->all[index].mmap)
195 return ed->all[index].mmap;
197 return ed->all[index].str;
203 _eet_dictionary_string_get_me_cache(const char *s, int len, int *mantisse, int *exponent)
205 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
207 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
208 *exponent = (s[5] - '0');
216 _eet_dictionary_string_get_float_cache(const char *s, int len, float *result)
221 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
223 if (s[4] == '+') *result = (float) (mantisse << exponent);
224 else *result = (float) mantisse / (float) (1 << exponent);
232 _eet_dictionary_string_get_double_cache(const char *s, int len, double *result)
237 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
239 if (s[4] == '+') *result = (double) (mantisse << exponent);
240 else *result = (double) mantisse / (float) (1 << exponent);
248 eet_dictionary_string_get_float(const Eet_Dictionary *ed, int index, float *result)
250 if (!result) return 0;
252 if (index < 0) return 0;
253 if (index < ed->count)
255 if (!(ed->all[index].flags.converted
256 && ed->all[index].flags.is_float))
260 str = ed->all[index].str ? ed->all[index].str : ed->all[index].mmap;
262 if (!_eet_dictionary_string_get_float_cache(str, ed->all[index].len, &ed->all[index].convert.f))
264 long long mantisse = 0;
267 if (!_eet_string_to_double_convert(str, &mantisse, &exponent))
270 ed->all[index].convert.f = ldexpf((float) mantisse, exponent);
273 ed->all[index].flags.is_float = 1;
276 *result = ed->all[index].convert.f;
283 eet_dictionary_string_get_double(const Eet_Dictionary *ed, int index, double *result)
285 if (!result) return 0;
287 if (index < 0) return 0;
288 if (index < ed->count)
290 if (!(ed->all[index].flags.converted
291 && !ed->all[index].flags.is_float))
295 str = ed->all[index].str ? ed->all[index].str : ed->all[index].mmap;
297 if (!_eet_dictionary_string_get_double_cache(str, ed->all[index].len, &ed->all[index].convert.d))
299 long long mantisse = 0;
302 if (!_eet_string_to_double_convert(str, &mantisse, &exponent))
305 ed->all[index].convert.d = ldexp((double) mantisse, exponent);
308 ed->all[index].flags.is_float = 0;
311 *result = ed->all[index].convert.d;
318 eet_dictionary_string_check(Eet_Dictionary *ed, const char *string)
326 if (ed->start <= string
330 for (i = 0; i < ed->count; ++i)
331 if (ed->all[i].str == string)