Lines Matching refs:dict

2  * dict.c: dictionary of reusable strings, just used to avoid allocation
36 * Note2: the fast function used for a small dict won't protect very
56 #include <libxml/dict.h>
70 #define xmlDictComputeKey(dict, name, len) \
71 (((dict)->size == MIN_DICT_SIZE) ? \
72 xmlDictComputeFastKey(name, len, (dict)->seed) : \
73 xmlDictComputeBigKey(name, len, (dict)->seed))
75 #define xmlDictComputeQKey(dict, prefix, plen, name, len) \
77 (xmlDictComputeKey(dict, name, len)) : \
78 (((dict)->size == MIN_DICT_SIZE) ? \
79 xmlDictComputeFastQKey(prefix, plen, name, len, (dict)->seed) : \
80 xmlDictComputeBigQKey(prefix, plen, name, len, (dict)->seed)))
83 #define xmlDictComputeKey(dict, name, len) \
84 xmlDictComputeFastKey(name, len, (dict)->seed)
85 #define xmlDictComputeQKey(dict, prefix, plen, name, len) \
86 xmlDictComputeFastQKey(prefix, plen, name, len, (dict)->seed)
118 struct _xmlDictEntry *dict;
232 * @dict: the dictionnary
241 xmlDictAddString(xmlDictPtr dict, const xmlChar *name, unsigned int namelen) {
250 pool = dict->strings;
262 if ((dict->limit > 0) && (limit > dict->limit)) {
277 pool->next = dict->strings;
278 dict->strings = pool;
294 * @dict: the dictionnary
305 xmlDictAddQString(xmlDictPtr dict, const xmlChar *prefix, unsigned int plen,
313 if (prefix == NULL) return(xmlDictAddString(dict, name, namelen));
318 pool = dict->strings;
330 if ((dict->limit > 0) && (limit > dict->limit)) {
345 pool->next = dict->strings;
346 dict->strings = pool;
537 xmlDictPtr dict;
547 dict = xmlMalloc(sizeof(xmlDict));
548 if (dict) {
549 dict->ref_counter = 1;
550 dict->limit = 0;
552 dict->size = MIN_DICT_SIZE;
553 dict->nbElems = 0;
554 dict->dict = xmlMalloc(MIN_DICT_SIZE * sizeof(xmlDictEntry));
555 dict->strings = NULL;
556 dict->subdict = NULL;
557 if (dict->dict) {
558 memset(dict->dict, 0, MIN_DICT_SIZE * sizeof(xmlDictEntry));
560 dict->seed = __xmlRandom();
562 dict->seed = 0;
564 return(dict);
566 xmlFree(dict);
584 xmlDictPtr dict = xmlDictCreate();
586 if ((dict != NULL) && (sub != NULL)) {
590 dict->seed = sub->seed;
591 dict->subdict = sub;
592 xmlDictReference(dict->subdict);
594 return(dict);
599 * @dict: the dictionnary
606 xmlDictReference(xmlDictPtr dict) {
611 if (dict == NULL) return -1;
613 dict->ref_counter++;
620 * @dict: the dictionnary
628 xmlDictGrow(xmlDictPtr dict, size_t size) {
639 if (dict == NULL)
650 oldsize = dict->size;
651 olddict = dict->dict;
657 dict->dict = xmlMalloc(size * sizeof(xmlDictEntry));
658 if (dict->dict == NULL) {
659 dict->dict = olddict;
662 memset(dict->dict, 0, size * sizeof(xmlDictEntry));
663 dict->size = size;
667 the main dict. It is nicer to run through the array twice, first
678 okey = xmlDictComputeKey(dict, olddict[i].name, olddict[i].len);
679 key = okey % dict->size;
681 if (dict->dict[key].valid == 0) {
682 memcpy(&(dict->dict[key]), &(olddict[i]), sizeof(xmlDictEntry));
683 dict->dict[key].next = NULL;
684 dict->dict[key].okey = okey;
693 entry->next = dict->dict[key].next;
695 dict->dict[key].next = entry;
715 * put back the entry in the new dict
721 okey = xmlDictComputeKey(dict, iter->name, iter->len);
722 key = okey % dict->size;
723 if (dict->dict[key].valid == 0) {
724 memcpy(&(dict->dict[key]), iter, sizeof(xmlDictEntry));
725 dict->dict[key].next = NULL;
726 dict->dict[key].valid = 1;
727 dict->dict[key].okey = okey;
730 iter->next = dict->dict[key].next;
732 dict->dict[key].next = iter;
755 * @dict: the dictionnary
757 * Free the hash @dict and its contents. The userdata is
761 xmlDictFree(xmlDictPtr dict) {
768 if (dict == NULL)
777 dict->ref_counter--;
778 if (dict->ref_counter > 0) {
785 if (dict->subdict != NULL) {
786 xmlDictFree(dict->subdict);
789 if (dict->dict) {
790 for(i = 0; ((i < dict->size) && (dict->nbElems > 0)); i++) {
791 iter = &(dict->dict[i]);
799 dict->nbElems--;
804 xmlFree(dict->dict);
806 pool = dict->strings;
812 xmlFree(dict);
817 * @dict: the dictionnary
821 * Add the @name to the dictionnary @dict if not present.
826 xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len) {
833 if ((dict == NULL) || (name == NULL))
841 if (((dict->limit > 0) && (l >= dict->limit)) ||
848 okey = xmlDictComputeKey(dict, name, l);
849 key = okey % dict->size;
850 if (dict->dict[key].valid == 0) {
853 for (insert = &(dict->dict[key]); insert->next != NULL;
879 if (dict->subdict) {
883 if (((dict->size == MIN_DICT_SIZE) &&
884 (dict->subdict->size != MIN_DICT_SIZE)) ||
885 ((dict->size != MIN_DICT_SIZE) &&
886 (dict->subdict->size == MIN_DICT_SIZE)))
887 skey = xmlDictComputeKey(dict->subdict, name, l);
891 key = skey % dict->subdict->size;
892 if (dict->subdict->dict[key].valid != 0) {
895 for (tmp = &(dict->subdict->dict[key]); tmp->next != NULL;
920 key = okey % dict->size;
923 ret = xmlDictAddString(dict, name, l);
927 entry = &(dict->dict[key]);
943 dict->nbElems++;
946 (dict->size <= ((MAX_DICT_HASH / 2) / MAX_HASH_LEN))) {
947 if (xmlDictGrow(dict, MAX_HASH_LEN * 2 * dict->size) != 0)
957 * @dict: the dictionnary
961 * Check if the @name exists in the dictionnary @dict.
966 xmlDictExists(xmlDictPtr dict, const xmlChar *name, int len) {
971 if ((dict == NULL) || (name == NULL))
978 if (((dict->limit > 0) && (l >= dict->limit)) ||
985 okey = xmlDictComputeKey(dict, name, l);
986 key = okey % dict->size;
987 if (dict->dict[key].valid == 0) {
990 for (insert = &(dict->dict[key]); insert->next != NULL;
1016 if (dict->subdict) {
1020 if (((dict->size == MIN_DICT_SIZE) &&
1021 (dict->subdict->size != MIN_DICT_SIZE)) ||
1022 ((dict->size != MIN_DICT_SIZE) &&
1023 (dict->subdict->size == MIN_DICT_SIZE)))
1024 skey = xmlDictComputeKey(dict->subdict, name, l);
1028 key = skey % dict->subdict->size;
1029 if (dict->subdict->dict[key].valid != 0) {
1032 for (tmp = &(dict->subdict->dict[key]); tmp->next != NULL;
1065 * @dict: the dictionnary
1069 * Add the QName @prefix:@name to the hash @dict if not present.
1074 xmlDictQLookup(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name) {
1081 if ((dict == NULL) || (name == NULL))
1084 return(xmlDictLookup(dict, name, -1));
1093 okey = xmlDictComputeQKey(dict, prefix, plen, name, l);
1094 key = okey % dict->size;
1095 if (dict->dict[key].valid == 0) {
1098 for (insert = &(dict->dict[key]); insert->next != NULL;
1110 if (dict->subdict) {
1114 if (((dict->size == MIN_DICT_SIZE) &&
1115 (dict->subdict->size != MIN_DICT_SIZE)) ||
1116 ((dict->size != MIN_DICT_SIZE) &&
1117 (dict->subdict->size == MIN_DICT_SIZE)))
1118 skey = xmlDictComputeQKey(dict->subdict, prefix, plen, name, l);
1122 key = skey % dict->subdict->size;
1123 if (dict->subdict->dict[key].valid != 0) {
1125 for (tmp = &(dict->subdict->dict[key]); tmp->next != NULL;
1136 key = okey % dict->size;
1139 ret = xmlDictAddQString(dict, prefix, plen, name, l);
1143 entry = &(dict->dict[key]);
1158 dict->nbElems++;
1161 (dict->size <= ((MAX_DICT_HASH / 2) / MAX_HASH_LEN)))
1162 xmlDictGrow(dict, MAX_HASH_LEN * 2 * dict->size);
1170 * @dict: the dictionnary
1179 xmlDictOwns(xmlDictPtr dict, const xmlChar *str) {
1182 if ((dict == NULL) || (str == NULL))
1184 pool = dict->strings;
1190 if (dict->subdict)
1191 return(xmlDictOwns(dict->subdict, str));
1197 * @dict: the dictionnary
1199 * Query the number of elements installed in the hash @dict.
1205 xmlDictSize(xmlDictPtr dict) {
1206 if (dict == NULL)
1208 if (dict->subdict)
1209 return(dict->nbElems + dict->subdict->nbElems);
1210 return(dict->nbElems);
1215 * @dict: the dictionnary
1224 xmlDictSetLimit(xmlDictPtr dict, size_t limit) {
1227 if (dict == NULL)
1229 ret = dict->limit;
1230 dict->limit = limit;
1236 * @dict: the dictionnary
1244 xmlDictGetUsage(xmlDictPtr dict) {
1248 if (dict == NULL)
1250 pool = dict->strings;