- hash.[ch]: added a first version of xmlHashSize()

- valid.c: another bug fix from Gary Pennington
Daniel
This commit is contained in:
Daniel Veillard 2001-02-08 09:37:42 +00:00
parent 5eef6225f7
commit 1f83d39fd3
5 changed files with 31 additions and 2 deletions

View File

@ -1,3 +1,8 @@
Thu Feb 8 10:37:00 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* 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 <Daniel.Veillard@imag.fr> Wed Feb 7 19:22:37 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* valid.c: couple of bug fixes pointed by Gary Pennington * valid.c: couple of bug fixes pointed by Gary Pennington

18
hash.c
View File

@ -47,6 +47,7 @@ struct _xmlHashEntry {
struct _xmlHashTable { struct _xmlHashTable {
struct _xmlHashEntry **table; struct _xmlHashEntry **table;
int size; int size;
int nbElems;
}; };
/* /*
@ -83,6 +84,7 @@ xmlHashCreate(int size) {
table = xmlMalloc(sizeof(xmlHashTable)); table = xmlMalloc(sizeof(xmlHashTable));
if (table) { if (table) {
table->size = size; table->size = size;
table->nbElems = 0;
table->table = xmlMalloc(size * sizeof(xmlHashEntry)); table->table = xmlMalloc(size * sizeof(xmlHashEntry));
if (table->table) { if (table->table) {
memset(table->table, 0, size * sizeof(xmlHashEntry)); memset(table->table, 0, size * sizeof(xmlHashEntry));
@ -297,6 +299,7 @@ xmlHashAddEntry3(xmlHashTablePtr table, const xmlChar *name,
} else { } else {
insert->next = entry; insert->next = entry;
} }
table->nbElems++;
return(0); return(0);
} }
@ -362,6 +365,7 @@ xmlHashUpdateEntry3(xmlHashTablePtr table, const xmlChar *name,
entry->name3 = xmlStrdup(name3); entry->name3 = xmlStrdup(name3);
entry->payload = userdata; entry->payload = userdata;
entry->next = NULL; entry->next = NULL;
table->nbElems++;
if (insert == NULL) { if (insert == NULL) {
@ -510,6 +514,20 @@ xmlHashCopy(xmlHashTablePtr table, xmlHashCopier f) {
} }
} }
} }
ret->nbElems = table->nbElems;
return(ret); 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);
}

1
hash.h
View File

@ -92,6 +92,7 @@ void * xmlHashLookup3 (xmlHashTablePtr table,
*/ */
xmlHashTablePtr xmlHashCopy (xmlHashTablePtr table, xmlHashTablePtr xmlHashCopy (xmlHashTablePtr table,
xmlHashCopier f); xmlHashCopier f);
int xmlHashSize (xmlHashTablePtr);
void xmlHashScan (xmlHashTablePtr table, void xmlHashScan (xmlHashTablePtr table,
xmlHashScanner f, xmlHashScanner f,
void *data); void *data);

View File

@ -92,6 +92,7 @@ void * xmlHashLookup3 (xmlHashTablePtr table,
*/ */
xmlHashTablePtr xmlHashCopy (xmlHashTablePtr table, xmlHashTablePtr xmlHashCopy (xmlHashTablePtr table,
xmlHashCopier f); xmlHashCopier f);
int xmlHashSize (xmlHashTablePtr);
void xmlHashScan (xmlHashTablePtr table, void xmlHashScan (xmlHashTablePtr table,
xmlHashScanner f, xmlHashScanner f,
void *data); void *data);

View File

@ -1775,8 +1775,12 @@ xmlAddRef(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value,
* !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ? * !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ?
*/ */
if (xmlHashAddEntry(table, value, ret) < 0) { 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); return(ret);
} }