amassari 2004/12/30 06:52:34 Modified: c/src/xercesc/util RefHash2KeysTableOf.c RefHash2KeysTableOf.hpp Log: Added API to remove all entries having the same primary key Revision Changes Path 1.14 +55 -1 xml-xerces/c/src/xercesc/util/RefHash2KeysTableOf.c Index: RefHash2KeysTableOf.c =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/RefHash2KeysTableOf.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- RefHash2KeysTableOf.c 19 Nov 2004 00:50:22 -0000 1.13 +++ RefHash2KeysTableOf.c 30 Dec 2004 14:52:34 -0000 1.14 @@ -16,6 +16,9 @@ /** * $Log$ + * Revision 1.14 2004/12/30 14:52:34 amassari + * Added API to remove all entries having the same primary key + * * Revision 1.13 2004/11/19 00:50:22 cargilld * Memory improvement to utility classes from Christian Will. Remove dependency on XMemory. * @@ -188,6 +191,57 @@ removeBucketElem(key1, key2, hashVal); } +template <class TVal> void RefHash2KeysTableOf<TVal>:: +removeKey(const void* const key1) +{ + // Hash the key + unsigned int hashVal = fHash->getHashVal(key1, fHashModulus); + assert(hashVal < fHashModulus); + + // + // Search the given bucket for this key. Keep up with the previous + // element so we can patch around it. + // + RefHash2KeysTableBucketElem<TVal>* curElem = fBucketList[hashVal]; + RefHash2KeysTableBucketElem<TVal>* lastElem = 0; + + while (curElem) + { + if (fHash->equals(key1, curElem->fKey1)) + { + if (!lastElem) + { + // It was the first in the bucket + fBucketList[hashVal] = curElem->fNext; + } + else + { + // Patch around the current element + lastElem->fNext = curElem->fNext; + } + + // If we adopted the elements, then delete the data + if (fAdoptedElems) + delete curElem->fData; + + RefHash2KeysTableBucketElem<TVal>* toBeDeleted=curElem; + curElem = curElem->fNext; + + // Delete the current element + // delete curElem; + // destructor is empty... + // curElem->~RefHash2KeysTableBucketElem(); + fMemoryManager->deallocate(toBeDeleted); + } + else + { + // Move both pointers upwards + lastElem = curElem; + curElem = curElem->fNext; + } + } +} + template <class TVal> void RefHash2KeysTableOf<TVal>::removeAll() { // Clean up the buckets first @@ -405,7 +459,7 @@ // It was the first in the bucket fBucketList[hashVal] = curElem->fNext; } - else + else { // Patch around the current element lastElem->fNext = curElem->fNext; 1.14 +4 -0 xml-xerces/c/src/xercesc/util/RefHash2KeysTableOf.hpp Index: RefHash2KeysTableOf.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/RefHash2KeysTableOf.hpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- RefHash2KeysTableOf.hpp 19 Nov 2004 00:50:22 -0000 1.13 +++ RefHash2KeysTableOf.hpp 30 Dec 2004 14:52:34 -0000 1.14 @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.14 2004/12/30 14:52:34 amassari + * Added API to remove all entries having the same primary key + * * Revision 1.13 2004/11/19 00:50:22 cargilld * Memory improvement to utility classes from Christian Will. Remove dependency on XMemory. * @@ -164,6 +167,7 @@ bool isEmpty() const; bool containsKey(const void* const key1, const int key2) const; void removeKey(const void* const key1, const int key2); + void removeKey(const void* const key1); void removeAll(); void transferElement(const void* const key1, void* key2);
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]