Lines Matching defs:dict

2  * dict.c: dictionary of reusable strings, just used to avoid allocation
24 #include <libxml/dict.h>
65 struct _xmlDictEntry *dict;
119 * @dict: the dictionnary
128 xmlDictAddString(xmlDictPtr dict, const xmlChar *name, int namelen) {
133 pool = dict->strings;
155 pool->next = dict->strings;
156 dict->strings = pool;
168 * @dict: the dictionnary
178 xmlDictAddQString(xmlDictPtr dict, const xmlChar *prefix,
186 if (prefix == NULL) return(xmlDictAddString(dict, name, namelen));
189 pool = dict->strings;
211 pool->next = dict->strings;
212 dict->strings = pool;
324 xmlDictPtr dict;
330 dict = xmlMalloc(sizeof(xmlDict));
331 if (dict) {
332 dict->ref_counter = 1;
334 dict->size = MIN_DICT_SIZE;
335 dict->nbElems = 0;
336 dict->dict = xmlMalloc(MIN_DICT_SIZE * sizeof(xmlDictEntry));
337 dict->strings = NULL;
338 dict->subdict = NULL;
339 if (dict->dict) {
340 if ((dict->mutex = xmlNewRMutex()) != NULL) {
341 memset(dict->dict, 0, MIN_DICT_SIZE * sizeof(xmlDictEntry));
342 return(dict);
344 xmlFree(dict->dict);
346 xmlFree(dict);
364 xmlDictPtr dict = xmlDictCreate();
366 if ((dict != NULL) && (sub != NULL)) {
367 dict->subdict = sub;
368 xmlDictReference(dict->subdict);
370 return(dict);
375 * @dict: the dictionnary
382 xmlDictReference(xmlDictPtr dict) {
387 if (dict == NULL) return -1;
389 dict->ref_counter++;
396 * @dict: the dictionnary
404 xmlDictGrow(xmlDictPtr dict, int size) {
413 if (dict == NULL)
420 oldsize = dict->size;
421 olddict = dict->dict;
425 dict->dict = xmlMalloc(size * sizeof(xmlDictEntry));
426 if (dict->dict == NULL) {
427 dict->dict = olddict;
430 memset(dict->dict, 0, size * sizeof(xmlDictEntry));
431 dict->size = size;
435 the main dict. So instead, we run through the array twice, first
442 key = xmlDictComputeKey(olddict[i].name, olddict[i].len) % dict->size;
443 memcpy(&(dict->dict[key]), &(olddict[i]), sizeof(xmlDictEntry));
444 dict->dict[key].next = NULL;
456 * put back the entry in the new dict
459 key = xmlDictComputeKey(iter->name, iter->len) % dict->size;
460 if (dict->dict[key].valid == 0) {
461 memcpy(&(dict->dict[key]), iter, sizeof(xmlDictEntry));
462 dict->dict[key].next = NULL;
463 dict->dict[key].valid = 1;
466 iter->next = dict->dict[key].next;
467 dict->dict[key].next = iter;
490 * @dict: the dictionnary
492 * Free the hash @dict and its contents. The userdata is
496 xmlDictFree(xmlDictPtr dict) {
503 if (dict == NULL)
512 dict->ref_counter--;
513 if (dict->ref_counter > 0) {
520 if (dict->subdict != NULL) {
521 xmlDictFree(dict->subdict);
524 if (dict->dict) {
525 for(i = 0; ((i < dict->size) && (dict->nbElems > 0)); i++) {
526 iter = &(dict->dict[i]);
534 dict->nbElems--;
540 xmlFree(dict->dict);
542 pool = dict->strings;
548 xmlFreeRMutex(dict->mutex);
549 xmlFree(dict);
554 * @dict: the dictionnary
558 * Add the @name to the dictionnary @dict if not present.
563 xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len) {
569 if ((dict == NULL) || (name == NULL))
579 key = okey % dict->size;
580 if (dict->dict[key].valid == 0) {
583 for (insert = &(dict->dict[key]); insert->next != NULL;
609 if (dict->subdict) {
610 key = okey % dict->subdict->size;
611 if (dict->subdict->dict[key].valid != 0) {
614 for (tmp = &(dict->subdict->dict[key]); tmp->next != NULL;
639 key = okey % dict->size;
642 ret = xmlDictAddString(dict, name, len);
646 entry = &(dict->dict[key]);
661 dict->nbElems++;
664 (dict->size <= ((MAX_DICT_HASH / 2) / MAX_HASH_LEN)))
665 xmlDictGrow(dict, MAX_HASH_LEN * 2 * dict->size);
673 * @dict: the dictionnary
677 * Check if the @name exists in the dictionnary @dict.
682 xmlDictExists(xmlDictPtr dict, const xmlChar *name, int len) {
686 if ((dict == NULL) || (name == NULL))
696 key = okey % dict->size;
697 if (dict->dict[key].valid == 0) {
700 for (insert = &(dict->dict[key]); insert->next != NULL;
726 if (dict->subdict) {
727 key = okey % dict->subdict->size;
728 if (dict->subdict->dict[key].valid != 0) {
731 for (tmp = &(dict->subdict->dict[key]); tmp->next != NULL;
756 key = okey % dict->size;
765 * @dict: the dictionnary
769 * Add the QName @prefix:@name to the hash @dict if not present.
774 xmlDictQLookup(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name) {
781 if ((dict == NULL) || (name == NULL))
792 key = okey % dict->size;
793 if (dict->dict[key].valid == 0) {
796 for (insert = &(dict->dict[key]); insert->next != NULL;
808 if (dict->subdict) {
809 key = okey % dict->subdict->size;
810 if (dict->subdict->dict[key].valid != 0) {
812 for (tmp = &(dict->subdict->dict[key]); tmp->next != NULL;
823 key = okey % dict->size;
826 ret = xmlDictAddQString(dict, prefix, name, len);
830 entry = &(dict->dict[key]);
844 dict->nbElems++;
847 (dict->size <= ((MAX_DICT_HASH / 2) / MAX_HASH_LEN)))
848 xmlDictGrow(dict, MAX_HASH_LEN * 2 * dict->size);
856 * @dict: the dictionnary
865 xmlDictOwns(xmlDictPtr dict, const xmlChar *str) {
868 if ((dict == NULL) || (str == NULL))
870 pool = dict->strings;
876 if (dict->subdict)
877 return(xmlDictOwns(dict->subdict, str));
883 * @dict: the dictionnary
885 * Query the number of elements installed in the hash @dict.
891 xmlDictSize(xmlDictPtr dict) {
892 if (dict == NULL)
894 if (dict->subdict)
895 return(dict->nbElems + dict->subdict->nbElems);
896 return(dict->nbElems);