From 1f83d39fd3f0bb38c7b044dd8aedd9c5d90156ea Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 8 Feb 2001 09:37:42 +0000 Subject: [PATCH] - hash.[ch]: added a first version of xmlHashSize() - valid.c: another bug fix from Gary Pennington Daniel --- ChangeLog | 5 +++++ hash.c | 18 ++++++++++++++++++ hash.h | 1 + include/libxml/hash.h | 1 + valid.c | 8 ++++++-- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1380162a..f2c30c97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Feb 8 10:37:00 CET 2001 Daniel Veillard + + * hash.[ch]: added a first version of xmlHashSize() + * valid.c: another bug fix from Gary Pennington + Wed Feb 7 19:22:37 CET 2001 Daniel Veillard * valid.c: couple of bug fixes pointed by Gary Pennington diff --git a/hash.c b/hash.c index 0f4f1048..6458b6d8 100644 --- a/hash.c +++ b/hash.c @@ -47,6 +47,7 @@ struct _xmlHashEntry { struct _xmlHashTable { struct _xmlHashEntry **table; int size; + int nbElems; }; /* @@ -83,6 +84,7 @@ xmlHashCreate(int size) { table = xmlMalloc(sizeof(xmlHashTable)); if (table) { table->size = size; + table->nbElems = 0; table->table = xmlMalloc(size * sizeof(xmlHashEntry)); if (table->table) { memset(table->table, 0, size * sizeof(xmlHashEntry)); @@ -297,6 +299,7 @@ xmlHashAddEntry3(xmlHashTablePtr table, const xmlChar *name, } else { insert->next = entry; } + table->nbElems++; return(0); } @@ -362,6 +365,7 @@ xmlHashUpdateEntry3(xmlHashTablePtr table, const xmlChar *name, entry->name3 = xmlStrdup(name3); entry->payload = userdata; entry->next = NULL; + table->nbElems++; if (insert == NULL) { @@ -510,6 +514,20 @@ xmlHashCopy(xmlHashTablePtr table, xmlHashCopier f) { } } } + ret->nbElems = table->nbElems; return(ret); } +/** + * xmlHashSize: + * @table: the hash table + * + * Returns the number of elements in the hash table or + * -1 in case of error + */ +int +xmlHashSize(xmlHashTablePtr table) { + if (table == NULL) + return(-1); + return(table->nbElems); +} diff --git a/hash.h b/hash.h index e0453136..0b48d9b9 100644 --- a/hash.h +++ b/hash.h @@ -92,6 +92,7 @@ void * xmlHashLookup3 (xmlHashTablePtr table, */ xmlHashTablePtr xmlHashCopy (xmlHashTablePtr table, xmlHashCopier f); +int xmlHashSize (xmlHashTablePtr); void xmlHashScan (xmlHashTablePtr table, xmlHashScanner f, void *data); diff --git a/include/libxml/hash.h b/include/libxml/hash.h index e0453136..0b48d9b9 100644 --- a/include/libxml/hash.h +++ b/include/libxml/hash.h @@ -92,6 +92,7 @@ void * xmlHashLookup3 (xmlHashTablePtr table, */ xmlHashTablePtr xmlHashCopy (xmlHashTablePtr table, xmlHashCopier f); +int xmlHashSize (xmlHashTablePtr); void xmlHashScan (xmlHashTablePtr table, xmlHashScanner f, void *data); diff --git a/valid.c b/valid.c index 8fc789e9..bdb70741 100644 --- a/valid.c +++ b/valid.c @@ -1775,8 +1775,12 @@ xmlAddRef(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value, * !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ? */ if (xmlHashAddEntry(table, value, ret) < 0) { - xmlFreeRef(ret); - return(NULL); + /* + * Since there is no discrimination on error returns + * from xmlHashAddEntry, I'm presuming <0 means the + * key already exists. + */ + xmlHashUpdateEntry(table, value, ret, (xmlHashDeallocator) xmlFreeRef); } return(ret); }