- 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>
* valid.c: couple of bug fixes pointed by Gary Pennington

18
hash.c
View File

@ -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);
}

1
hash.h
View File

@ -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);

View File

@ -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);

View File

@ -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);
}