3 #endif /* ifdef HAVE_CONFIG_H */
12 #include "Eet_private.h"
15 eet_dictionary_add(void)
19 new = calloc(1, sizeof (Eet_Dictionary));
23 memset(new->hash, -1, sizeof (int) * 256);
29 eet_dictionary_free(Eet_Dictionary *ed)
35 for (i = 0; i < ed->count; ++i)
36 if (ed->all[i].allocated)
37 eina_stringshare_del(ed->all[i].str);
40 eet_string_mp_free(ed->all);
42 if (ed->converts) eina_hash_free(ed->converts);
44 eet_dictionary_mp_free(ed);
48 _eet_dictionary_lookup(Eet_Dictionary *ed,
53 Eina_Bool found = EINA_FALSE;
57 current = ed->hash[hash];
61 if (ed->all[current].len == len)
63 if (ed->all[current].str &&
64 (ed->all[current].str == string || strcmp(ed->all[current].str, string) == 0))
72 current = ed->all[current].next;
75 if (current == -1 && found)
82 eet_dictionary_string_add(Eet_Dictionary *ed,
94 hash = _eet_hash_gen(string, 8);
95 len = strlen(string) + 1;
97 idx = _eet_dictionary_lookup(ed, string, len, hash);
101 if (ed->all[idx].str && (ed->all[idx].str == string || strcmp(ed->all[idx].str, string) == 0))
105 if (ed->total == ed->count)
110 total = ed->total + 8;
112 new = realloc(ed->all, sizeof (Eet_String) * total);
120 str = eina_stringshare_add(string);
124 current = ed->all + ed->count;
126 current->allocated = EINA_TRUE;
128 current->hash = hash;
135 current->next = ed->hash[hash];
137 ed->hash[hash] = ed->count;
142 current->prev = ed->all[idx].prev;
144 if (current->next != -1)
145 ed->all[current->next].prev = ed->count;
147 if (current->prev != -1)
148 ed->all[current->prev].next = ed->count;
150 ed->hash[hash] = ed->count;
157 eet_dictionary_string_get_size(const Eet_Dictionary *ed,
167 return ed->all[idx].len;
173 eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
183 return ed->all[idx].hash;
189 eet_dictionary_string_get_char(const Eet_Dictionary *ed,
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].allocated)
204 ed->all[idx].str = eina_stringshare_add(ed->all[idx].str);
205 ed->all[idx].allocated = EINA_TRUE;
207 #endif /* ifdef _WIN32 */
208 return ed->all[idx].str;
214 static inline Eina_Bool
215 _eet_dictionary_string_get_me_cache(const char *s,
220 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
222 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
223 *exponent = (s[5] - '0');
231 static inline Eina_Bool
232 _eet_dictionary_string_get_float_cache(const char *s,
239 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
242 *result = (float)(mantisse << exponent);
244 *result = (float)mantisse / (float)(1 << exponent);
252 static inline Eina_Bool
253 _eet_dictionary_string_get_double_cache(const char *s,
260 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
263 *result = (double)(mantisse << exponent);
265 *result = (double)mantisse / (float)(1 << exponent);
273 static inline Eina_Bool
274 _eet_dictionary_test(const Eet_Dictionary *ed,
287 if (!(idx < ed->count))
294 eet_dictionary_convert_get(const Eet_Dictionary *ed,
300 *str = ed->all[idx].str;
304 ((Eet_Dictionary *)ed)->converts = eina_hash_int32_new(free);
309 result = eina_hash_find(ed->converts, &idx);
310 if (result) return result;
313 result = calloc(1, sizeof (Eet_Convert));
315 eina_hash_add(ed->converts, &idx, result);
320 eet_dictionary_string_get_float(const Eet_Dictionary *ed,
324 Eet_Convert *convert;
327 if (!_eet_dictionary_test(ed, idx, result))
330 convert = eet_dictionary_convert_get(ed, idx, &str);
331 if (!convert) return EINA_FALSE;
333 if (!(convert->type & EET_D_FLOAT))
335 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
338 long long mantisse = 0;
341 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
342 &exponent) == EINA_FALSE)
345 convert->f = ldexpf((float)mantisse, exponent);
348 convert->type |= EET_D_FLOAT;
351 *result = convert->f;
356 eet_dictionary_string_get_double(const Eet_Dictionary *ed,
360 Eet_Convert *convert;
363 if (!_eet_dictionary_test(ed, idx, result))
366 convert = eet_dictionary_convert_get(ed, idx, &str);
367 if (!convert) return EINA_FALSE;
369 if (!(convert->type & EET_D_DOUBLE))
371 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
374 long long mantisse = 0;
377 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
378 &exponent) == EINA_FALSE)
381 convert->d = ldexp((double)mantisse, exponent);
384 convert->type |= EET_D_DOUBLE;
387 *result = convert->d;
392 eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
396 Eet_Convert *convert;
399 if (!_eet_dictionary_test(ed, idx, result))
402 convert = eet_dictionary_convert_get(ed, idx, &str);
403 if (!convert) return EINA_FALSE;
405 if (!(convert->type & EET_D_FIXED_POINT))
409 if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
413 convert->type |= EET_D_FIXED_POINT;
416 *result = convert->fp;
421 eet_dictionary_string_check(Eet_Dictionary *ed,
426 if ((!ed) || (!string))
429 if ((ed->start <= string) && (string < ed->end))
432 for (i = 0; i < ed->count; ++i)
433 if ((ed->all[i].allocated) && ed->all[i].str == string)