3 #endif /* ifdef HAVE_CONFIG_H */
12 #include "Eet_private.h"
15 eet_dictionary_add(void)
19 new = eet_dictionary_calloc(1);
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);
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, total * sizeof(Eet_String));
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_count(const Eet_Dictionary *ed)
179 eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
189 return ed->all[idx].hash;
195 eet_dictionary_string_get_char(const Eet_Dictionary *ed,
207 /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
208 if (!ed->all[idx].allocated)
210 ed->all[idx].str = eina_stringshare_add(ed->all[idx].str);
211 ed->all[idx].allocated = EINA_TRUE;
213 #endif /* ifdef _WIN32 */
214 return ed->all[idx].str;
220 static inline Eina_Bool
221 _eet_dictionary_string_get_me_cache(const char *s,
226 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
228 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
229 *exponent = (s[5] - '0');
237 static inline Eina_Bool
238 _eet_dictionary_string_get_float_cache(const char *s,
245 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
248 *result = (float)(mantisse << exponent);
250 *result = (float)mantisse / (float)(1 << exponent);
258 static inline Eina_Bool
259 _eet_dictionary_string_get_double_cache(const char *s,
266 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
269 *result = (double)(mantisse << exponent);
271 *result = (double)mantisse / (float)(1 << exponent);
279 static inline Eina_Bool
280 _eet_dictionary_test(const Eet_Dictionary *ed,
293 if (!(idx < ed->count))
300 eet_dictionary_convert_get(const Eet_Dictionary *ed,
306 *str = ed->all[idx].str;
310 ((Eet_Dictionary *)ed)->converts = eina_hash_int32_new(free);
315 result = eina_hash_find(ed->converts, &idx);
316 if (result) return result;
319 result = calloc(1, sizeof (Eet_Convert));
321 eina_hash_add(ed->converts, &idx, result);
326 eet_dictionary_string_get_float(const Eet_Dictionary *ed,
330 Eet_Convert *convert;
333 if (!_eet_dictionary_test(ed, idx, result))
336 convert = eet_dictionary_convert_get(ed, idx, &str);
337 if (!convert) return EINA_FALSE;
339 if (!(convert->type & EET_D_FLOAT))
341 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
344 long long mantisse = 0;
347 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
348 &exponent) == EINA_FALSE)
351 convert->f = ldexpf((float)mantisse, exponent);
354 convert->type |= EET_D_FLOAT;
357 *result = convert->f;
362 eet_dictionary_string_get_double(const Eet_Dictionary *ed,
366 Eet_Convert *convert;
369 if (!_eet_dictionary_test(ed, idx, result))
372 convert = eet_dictionary_convert_get(ed, idx, &str);
373 if (!convert) return EINA_FALSE;
375 if (!(convert->type & EET_D_DOUBLE))
377 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
380 long long mantisse = 0;
383 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
384 &exponent) == EINA_FALSE)
387 convert->d = ldexp((double)mantisse, exponent);
390 convert->type |= EET_D_DOUBLE;
393 *result = convert->d;
398 eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
402 Eet_Convert *convert;
405 if (!_eet_dictionary_test(ed, idx, result))
408 convert = eet_dictionary_convert_get(ed, idx, &str);
409 if (!convert) return EINA_FALSE;
411 if (!(convert->type & EET_D_FIXED_POINT))
415 if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
419 convert->type |= EET_D_FIXED_POINT;
422 *result = convert->fp;
427 eet_dictionary_string_check(Eet_Dictionary *ed,
432 if ((!ed) || (!string))
435 if ((ed->start <= string) && (string < ed->end))
438 for (i = 0; i < ed->count; ++i)
439 if ((ed->all[i].allocated) && ed->all[i].str == string)