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)
42 if (ed->all) free(ed->all);
48 _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
53 current = ed->hash[hash];
57 if (ed->all[current].str)
59 if (strcmp(ed->all[current].str, string) >= 0)
62 if (ed->all[current].mmap)
64 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 index = _eet_dictionary_lookup(ed, string, hash);
96 if (ed->all[index].str)
98 if (strcmp(ed->all[index].str, string) == 0)
101 if (ed->all[index].mmap)
103 if (strcmp(ed->all[index].mmap, string) == 0)
108 if (ed->total == ed->count)
113 total = ed->total + 8;
115 new = realloc(ed->all, sizeof (Eet_String) * total);
123 len = strlen(string) + 1;
124 str = strdup(string);
128 current = ed->all + ed->count;
130 current->flags.converted = 0;
131 current->flags.is_float = 0;
133 current->hash = hash;
137 current->mmap = NULL;
141 current->next = ed->hash[hash];
143 ed->hash[hash] = ed->count;
147 current->next = index;
148 current->prev = ed->all[index].prev;
150 if (current->next != -1)
151 ed->all[current->next].prev = ed->count;
152 if (current->prev != -1)
153 ed->all[current->prev].next = ed->count;
155 ed->hash[hash] = ed->count;
162 eet_dictionary_string_get_size(const Eet_Dictionary *ed, int index)
165 if (index < 0) return 0;
166 if (index < ed->count)
167 return ed->all[index].len;
172 eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int index)
175 if (index < 0) return -1;
176 if (index < ed->count)
177 return ed->all[index].hash;
182 eet_dictionary_string_get_char(const Eet_Dictionary *ed, int index)
184 if (!ed) return NULL;
185 if (index < 0) return NULL;
186 if (index < ed->count)
189 /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
190 if (ed->all[index].str == NULL)
192 ed->all[index].str = strdup(ed->all[index].mmap);
193 ed->all[index].mmap = NULL;
196 if (ed->all[index].mmap)
197 return ed->all[index].mmap;
199 return ed->all[index].str;
205 _eet_dictionary_string_get_me_cache(const char *s, int len, int *mantisse, int *exponent)
207 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
209 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
210 *exponent = (s[5] - '0');
218 _eet_dictionary_string_get_float_cache(const char *s, int len, float *result)
223 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
225 if (s[4] == '+') *result = (float) (mantisse << exponent);
226 else *result = (float) mantisse / (float) (1 << exponent);
234 _eet_dictionary_string_get_double_cache(const char *s, int len, double *result)
239 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
241 if (s[4] == '+') *result = (double) (mantisse << exponent);
242 else *result = (double) mantisse / (float) (1 << exponent);
250 eet_dictionary_string_get_float(const Eet_Dictionary *ed, int index, float *result)
252 if (!result) return 0;
254 if (index < 0) return 0;
255 if (index < ed->count)
257 if (!(ed->all[index].flags.converted
258 && ed->all[index].flags.is_float))
262 str = ed->all[index].str ? ed->all[index].str : ed->all[index].mmap;
264 if (!_eet_dictionary_string_get_float_cache(str, ed->all[index].len, &ed->all[index].convert.f))
266 long long mantisse = 0;
269 if (eina_convert_atod(str, ed->all[index].len, &mantisse, &exponent) == EINA_FALSE)
272 ed->all[index].convert.f = ldexpf((float) mantisse, exponent);
275 ed->all[index].flags.is_float = 1;
278 *result = ed->all[index].convert.f;
285 eet_dictionary_string_get_double(const Eet_Dictionary *ed, int index, double *result)
287 if (!result) return 0;
289 if (index < 0) return 0;
290 if (index < ed->count)
292 if (!(ed->all[index].flags.converted
293 && !ed->all[index].flags.is_float))
297 str = ed->all[index].str ? ed->all[index].str : ed->all[index].mmap;
299 if (!_eet_dictionary_string_get_double_cache(str, ed->all[index].len, &ed->all[index].convert.d))
301 long long mantisse = 0;
304 if (eina_convert_atod(str, ed->all[index].len, &mantisse, &exponent) == EINA_FALSE)
307 ed->all[index].convert.d = ldexp((double) mantisse, exponent);
310 ed->all[index].flags.is_float = 0;
313 *result = ed->all[index].convert.d;
320 eet_dictionary_string_check(Eet_Dictionary *ed, const char *string)
328 if (ed->start <= string
332 for (i = 0; i < ed->count; ++i)
333 if (ed->all[i].str == string)