2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
16 #include "Eet_private.h"
19 eet_dictionary_add(void)
23 new = calloc(1, sizeof (Eet_Dictionary));
27 memset(new->hash, -1, sizeof (int) * 256);
33 eet_dictionary_free(Eet_Dictionary *ed)
39 for (i = 0; i < ed->count; ++i)
51 _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
56 current = ed->hash[hash];
60 if (ed->all[current].str)
61 if (strcmp(ed->all[current].str, string) >= 0)
64 if (ed->all[current].mmap)
65 if (strcmp(ed->all[current].mmap, string) >= 0)
69 current = ed->all[current].next;
79 eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
90 hash = _eet_hash_gen(string, 8);
92 idx = _eet_dictionary_lookup(ed, string, hash);
97 if (strcmp(ed->all[idx].str, string) == 0)
100 if (ed->all[idx].mmap)
101 if (strcmp(ed->all[idx].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->type = EET_D_NOT_CONVERTED;
130 current->hash = hash;
134 current->mmap = NULL;
138 current->next = ed->hash[hash];
140 ed->hash[hash] = ed->count;
145 current->prev = ed->all[idx].prev;
147 if (current->next != -1)
148 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 idx)
169 return ed->all[idx].len;
175 eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int idx)
184 return ed->all[idx].hash;
190 eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx)
201 /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
202 if (ed->all[idx].str == NULL)
204 ed->all[idx].str = strdup(ed->all[idx].mmap);
205 ed->all[idx].mmap = NULL;
209 if (ed->all[idx].mmap)
210 return ed->all[idx].mmap;
213 return ed->all[idx].str;
219 static inline Eina_Bool
220 _eet_dictionary_string_get_me_cache(const char *s,
225 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
227 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
228 *exponent = (s[5] - '0');
236 static inline Eina_Bool
237 _eet_dictionary_string_get_float_cache(const char *s, int len, float *result)
242 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
245 *result = (float)(mantisse << exponent);
247 *result = (float)mantisse / (float)(1 << exponent);
255 static inline Eina_Bool
256 _eet_dictionary_string_get_double_cache(const char *s, int len, double *result)
261 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
264 *result = (double)(mantisse << exponent);
266 *result = (double)mantisse / (float)(1 << exponent);
274 static inline Eina_Bool
275 _eet_dictionary_test(const Eet_Dictionary *ed, int idx, void *result)
286 if (!(idx < ed->count))
293 eet_dictionary_string_get_float(const Eet_Dictionary *ed,
297 if (!_eet_dictionary_test(ed, idx, result))
300 if (!(ed->all[idx].type & EET_D_FLOAT))
304 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
306 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
309 long long mantisse = 0;
312 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
313 &exponent) == EINA_FALSE)
316 ed->all[idx].f = ldexpf((float)mantisse, exponent);
319 ed->all[idx].type |= EET_D_FLOAT;
322 *result = ed->all[idx].f;
327 eet_dictionary_string_get_double(const Eet_Dictionary *ed,
331 if (!_eet_dictionary_test(ed, idx, result))
334 if (!(ed->all[idx].type & EET_D_DOUBLE))
338 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
340 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
343 long long mantisse = 0;
346 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
347 &exponent) == EINA_FALSE)
350 ed->all[idx].d = ldexp((double)mantisse, exponent);
353 ed->all[idx].type |= EET_D_DOUBLE;
356 *result = ed->all[idx].d;
361 eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
365 if (!_eet_dictionary_test(ed, idx, result))
368 if (!(ed->all[idx].type & EET_D_FIXED_POINT))
373 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
375 if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
378 ed->all[idx].fp = fp;
379 ed->all[idx].type |= EET_D_FIXED_POINT;
382 *result = ed->all[idx].fp;
387 eet_dictionary_string_check(Eet_Dictionary *ed, const char *string)
395 if (ed->start <= string
399 for (i = 0; i < ed->count; ++i)
400 if (ed->all[i].str == string)