diff --git a/src/NCollection/FILES b/src/NCollection/FILES index 71f73fe29f..0fb54fe7f3 100755 --- a/src/NCollection/FILES +++ b/src/NCollection/FILES @@ -79,3 +79,6 @@ NCollection_Comparator.hxx NCollection_QuickSort.hxx NCollection_Haft.h + + +NCollection_DefaultHasher.hxx \ No newline at end of file diff --git a/src/NCollection/NCollection_BaseList.hxx b/src/NCollection/NCollection_BaseList.hxx index 3567b5fb0a..0349cf1ddf 100755 --- a/src/NCollection/NCollection_BaseList.hxx +++ b/src/NCollection/NCollection_BaseList.hxx @@ -49,6 +49,11 @@ class NCollection_BaseList myCurrent = theList.myFirst; myPrevious = NULL; } + // ******** Initialisation + void Initialize (const NCollection_BaseList& theList) + { + Init(theList); + } // ******** More Standard_Boolean More (void) const { return (myCurrent!=NULL); } diff --git a/src/NCollection/NCollection_DataMap.hxx b/src/NCollection/NCollection_DataMap.hxx index 74514c8810..97a051b387 100755 --- a/src/NCollection/NCollection_DataMap.hxx +++ b/src/NCollection/NCollection_DataMap.hxx @@ -10,6 +10,8 @@ #include #include +#include + #include #include @@ -36,7 +38,11 @@ * can be done only if aKey was previously bound to * an item in the map. */ -template class NCollection_DataMap + +template < class TheKeyType, + class TheItemType, + class Hasher = NCollection_DefaultHasher > class NCollection_DataMap + : public NCollection_BaseCollection, public NCollection_BaseMap { @@ -179,7 +185,7 @@ template class NCollection_DataMap p = olddata[i]; while (p) { - k = HashCode(p->Key(),newBuck); + k = Hasher::HashCode(p->Key(),newBuck); q = (DataMapNode*) p->Next(); p->Next() = newdata[k]; newdata[k] = p; @@ -201,11 +207,11 @@ template class NCollection_DataMap if (Resizable()) ReSize(Extent()); DataMapNode** data = (DataMapNode**)myData1; - Standard_Integer k = HashCode (theKey, NbBuckets()); + Standard_Integer k = Hasher::HashCode (theKey, NbBuckets()); DataMapNode* p = data[k]; while (p) { - if (IsEqual(p->Key(), theKey)) + if (Hasher::IsEqual(p->Key(), theKey)) { p->ChangeValue() = theItem; return Standard_False; @@ -223,10 +229,10 @@ template class NCollection_DataMap if (IsEmpty()) return Standard_False; DataMapNode** data = (DataMapNode**) myData1; - DataMapNode* p = data[HashCode(K,NbBuckets())]; + DataMapNode* p = data[Hasher::HashCode(K,NbBuckets())]; while (p) { - if (IsEqual(p->Key(),K)) + if (Hasher::IsEqual(p->Key(),K)) return Standard_True; p = (DataMapNode *) p->Next(); } @@ -239,12 +245,12 @@ template class NCollection_DataMap if (IsEmpty()) return Standard_False; DataMapNode** data = (DataMapNode**) myData1; - Standard_Integer k = HashCode(K,NbBuckets()); + Standard_Integer k = Hasher::HashCode(K,NbBuckets()); DataMapNode* p = data[k]; DataMapNode* q = NULL; while (p) { - if (IsEqual(p->Key(),K)) + if (Hasher::IsEqual(p->Key(),K)) { Decrement(); if (q) @@ -268,10 +274,10 @@ template class NCollection_DataMap if (IsEmpty()) Standard_NoSuchObject::Raise ("NCollection_DataMap::Find"); #endif - DataMapNode* p = (DataMapNode*) myData1[HashCode(theKey,NbBuckets())]; + DataMapNode* p = (DataMapNode*) myData1[Hasher::HashCode(theKey,NbBuckets())]; while (p) { - if (IsEqual(p->Key(),theKey)) + if (Hasher::IsEqual(p->Key(),theKey)) return p->Value(); p = (DataMapNode*) p->Next(); } @@ -290,10 +296,10 @@ template class NCollection_DataMap if (IsEmpty()) Standard_NoSuchObject::Raise ("NCollection_DataMap::Find"); #endif - DataMapNode* p = (DataMapNode*) myData1[HashCode(theKey,NbBuckets())]; + DataMapNode* p = (DataMapNode*) myData1[Hasher::HashCode(theKey,NbBuckets())]; while (p) { - if (IsEqual(p->Key(),theKey)) + if (Hasher::IsEqual(p->Key(),theKey)) return p->ChangeValue(); p = (DataMapNode*) p->Next(); } @@ -341,3 +347,4 @@ template class NCollection_DataMap #endif #endif + diff --git a/src/NCollection/NCollection_DefaultHasher.hxx b/src/NCollection/NCollection_DefaultHasher.hxx new file mode 100644 index 0000000000..e8cc7b7354 --- /dev/null +++ b/src/NCollection/NCollection_DefaultHasher.hxx @@ -0,0 +1,56 @@ +// File: NCollection_DefaultHasher.hxx +// Created: +// Author: Eugene Maltchikov +// + + +#ifndef NCollection_DefaultHasher_HeaderFile +#define NCollection_DefaultHasher_HeaderFile + +#include +#include + +//======================================================================= +//function : HashCode_Proxy +//purpose : Function is required to call the global function HashCode. +//======================================================================= +template + static Standard_Integer HashCode_Proxy(const TheKeyType& theKey, + const Standard_Integer Upper) { + return HashCode(theKey, Upper); +} + +//======================================================================= +//function : IsEqual_Proxy +//purpose : Function is required to call the global function IsEqual. +//======================================================================= +template + static Standard_Boolean IsEqual_Proxy(const TheKeyType& theKey1, + const TheKeyType& theKey2) { + return IsEqual(theKey1, theKey2); +} + + +/** + * Purpose: The DefaultHasher is a Hasher that is used by + * default in NCollection maps. + * To compute the hash code of the key is used the + * global function HashCode. + * To compare two keys is used the global function + * IsEqual. +*/ +template class NCollection_DefaultHasher { +public: + // + static Standard_Integer HashCode(const TheKeyType& theKey, + const Standard_Integer Upper) { + return HashCode_Proxy(theKey, Upper); + } + // + static Standard_Boolean IsEqual(const TheKeyType& theKey1, + const TheKeyType& theKey2) { + return IsEqual_Proxy(theKey1, theKey2); + } +}; + +#endif diff --git a/src/NCollection/NCollection_DoubleMap.hxx b/src/NCollection/NCollection_DoubleMap.hxx index f59b70838b..4b85c6f45a 100755 --- a/src/NCollection/NCollection_DoubleMap.hxx +++ b/src/NCollection/NCollection_DoubleMap.hxx @@ -15,6 +15,8 @@ #include #include +#include + #ifdef WNT // Disable the warning "operator new unmatched by delete" #pragma warning (push) @@ -28,7 +30,11 @@ * See Map from NCollection for a discussion about the number * of buckets */ -template class NCollection_DoubleMap + +template < class TheKey1Type, + class TheKey2Type, + class Hasher1 = NCollection_DefaultHasher, + class Hasher2 = NCollection_DefaultHasher > class NCollection_DoubleMap : public NCollection_BaseCollection, public NCollection_BaseMap { @@ -164,8 +170,8 @@ template class NCollection_DoubleMap { TheKey1Type aKey1 = anIter.Key1(); TheKey2Type aKey2 = anIter.Key2(); - Standard_Integer iK1 = HashCode (aKey1, NbBuckets()); - Standard_Integer iK2 = HashCode (aKey2, NbBuckets()); + Standard_Integer iK1 = Hasher1::HashCode (aKey1, NbBuckets()); + Standard_Integer iK2 = Hasher2::HashCode (aKey2, NbBuckets()); DoubleMapNode * pNode = new (this->myAllocator) DoubleMapNode (aKey1, aKey2, myData1[iK1], myData2[iK2]); @@ -198,8 +204,8 @@ template class NCollection_DoubleMap p = (DoubleMapNode *) myData1[i]; while (p) { - iK1 = HashCode (p->Key1(), newBuck); - iK2 = HashCode (p->Key2(), newBuck); + iK1 = Hasher1::HashCode (p->Key1(), newBuck); + iK2 = Hasher2::HashCode (p->Key2(), newBuck); q = (DoubleMapNode*) p->Next(); p->Next() = ppNewData1[iK1]; p->Next2() = ppNewData2[iK2]; @@ -222,20 +228,20 @@ template class NCollection_DoubleMap { if (Resizable()) ReSize(Extent()); - Standard_Integer iK1 = HashCode (theKey1, NbBuckets()); - Standard_Integer iK2 = HashCode (theKey2, NbBuckets()); + Standard_Integer iK1 = Hasher1::HashCode (theKey1, NbBuckets()); + Standard_Integer iK2 = Hasher2::HashCode (theKey2, NbBuckets()); DoubleMapNode * pNode; pNode = (DoubleMapNode *) myData1[iK1]; while (pNode) { - if (IsEqual (pNode->Key1(), theKey1)) + if (Hasher1::IsEqual (pNode->Key1(), theKey1)) Standard_MultiplyDefined::Raise("NCollection_DoubleMap:Bind"); pNode = (DoubleMapNode *) pNode->Next(); } pNode = (DoubleMapNode *) myData2[iK2]; while (pNode) { - if (IsEqual (pNode->Key2(), theKey2)) + if (Hasher2::IsEqual (pNode->Key2(), theKey2)) Standard_MultiplyDefined::Raise("NCollection_DoubleMap:Bind"); pNode = (DoubleMapNode *) pNode->Next(); } @@ -252,13 +258,13 @@ template class NCollection_DoubleMap { if (IsEmpty()) return Standard_False; - Standard_Integer iK1 = HashCode (theKey1, NbBuckets()); - Standard_Integer iK2 = HashCode (theKey2, NbBuckets()); + Standard_Integer iK1 = Hasher1::HashCode (theKey1, NbBuckets()); + Standard_Integer iK2 = Hasher2::HashCode (theKey2, NbBuckets()); DoubleMapNode * pNode1, * pNode2; pNode1 = (DoubleMapNode *) myData1[iK1]; while (pNode1) { - if (IsEqual(pNode1->Key1(), theKey1)) + if (Hasher1::IsEqual(pNode1->Key1(), theKey1)) break; pNode1 = (DoubleMapNode *) pNode1->Next(); } @@ -267,7 +273,7 @@ template class NCollection_DoubleMap pNode2 = (DoubleMapNode *) myData2[iK2]; while (pNode2) { - if (IsEqual(pNode2->Key2(), theKey2)) + if (Hasher2::IsEqual(pNode2->Key2(), theKey2)) break; pNode2 = (DoubleMapNode *) pNode2->Next(); } @@ -282,12 +288,12 @@ template class NCollection_DoubleMap { if (IsEmpty()) return Standard_False; - Standard_Integer iK1 = HashCode (theKey1, NbBuckets()); + Standard_Integer iK1 = Hasher1::HashCode (theKey1, NbBuckets()); DoubleMapNode * pNode1; pNode1 = (DoubleMapNode *) myData1[iK1]; while (pNode1) { - if (IsEqual(pNode1->Key1(), theKey1)) + if (Hasher1::IsEqual(pNode1->Key1(), theKey1)) return Standard_True; pNode1 = (DoubleMapNode *) pNode1->Next(); } @@ -299,12 +305,12 @@ template class NCollection_DoubleMap { if (IsEmpty()) return Standard_False; - Standard_Integer iK2 = HashCode (theKey2, NbBuckets()); + Standard_Integer iK2 = Hasher2::HashCode (theKey2, NbBuckets()); DoubleMapNode * pNode2; pNode2 = (DoubleMapNode *) myData2[iK2]; while (pNode2) { - if (IsEqual(pNode2->Key2(), theKey2)) + if (Hasher2::IsEqual(pNode2->Key2(), theKey2)) return Standard_True; pNode2 = (DoubleMapNode *) pNode2->Next2(); } @@ -316,20 +322,20 @@ template class NCollection_DoubleMap { if (IsEmpty()) return Standard_False; - Standard_Integer iK1 = HashCode (theKey1, NbBuckets()); + Standard_Integer iK1 = Hasher1::HashCode (theKey1, NbBuckets()); DoubleMapNode * p1, * p2, * q1, *q2; q1 = q2 = NULL; p1 = (DoubleMapNode *) myData1[iK1]; while (p1) { - if (IsEqual (p1->Key1(), theKey1)) + if (Hasher1::IsEqual (p1->Key1(), theKey1)) { // remove from the data1 if (q1) q1->Next() = p1->Next(); else myData1[iK1] = (DoubleMapNode*) p1->Next(); - Standard_Integer iK2 = HashCode (p1->Key2(), NbBuckets()); + Standard_Integer iK2 = Hasher2::HashCode (p1->Key2(), NbBuckets()); p2 = (DoubleMapNode *) myData2[iK2]; while (p2) { @@ -361,20 +367,20 @@ template class NCollection_DoubleMap { if (IsEmpty()) return Standard_False; - Standard_Integer iK2 = HashCode (theKey2, NbBuckets()); + Standard_Integer iK2 = Hasher2::HashCode (theKey2, NbBuckets()); DoubleMapNode * p1, * p2, * q1, *q2; q1 = q2 = NULL; p2 = (DoubleMapNode *) myData2[iK2]; while (p2) { - if (IsEqual (p2->Key2(), theKey2)) + if (Hasher2::IsEqual (p2->Key2(), theKey2)) { // remove from the data2 if (q2) q2->Next() = p2->Next(); else myData2[iK2] = (DoubleMapNode*) p2->Next2(); - Standard_Integer iK1 = HashCode (p2->Key1(), NbBuckets()); + Standard_Integer iK1 = Hasher1::HashCode (p2->Key1(), NbBuckets()); p1 = (DoubleMapNode *) myData1[iK1]; while (p1) { @@ -409,10 +415,10 @@ template class NCollection_DoubleMap Standard_NoSuchObject::Raise ("NCollection_DoubleMap::Find1"); #endif DoubleMapNode * pNode1 = - (DoubleMapNode *) myData1[HashCode(theKey1,NbBuckets())]; + (DoubleMapNode *) myData1[Hasher1::HashCode(theKey1,NbBuckets())]; while (pNode1) { - if (IsEqual (pNode1->Key1(), theKey1)) + if (Hasher1::IsEqual (pNode1->Key1(), theKey1)) return pNode1->Key2(); pNode1 = (DoubleMapNode*) pNode1->Next(); } @@ -428,10 +434,10 @@ template class NCollection_DoubleMap Standard_NoSuchObject::Raise ("NCollection_DoubleMap::Find2"); #endif DoubleMapNode * pNode2 = - (DoubleMapNode *) myData2[HashCode(theKey2,NbBuckets())]; + (DoubleMapNode *) myData2[Hasher2::HashCode(theKey2,NbBuckets())]; while (pNode2) { - if (IsEqual (pNode2->Key2(), theKey2)) + if (Hasher2::IsEqual (pNode2->Key2(), theKey2)) return pNode2->Key1(); pNode2 = (DoubleMapNode*) pNode2->Next2(); } diff --git a/src/NCollection/NCollection_IndexedDataMap.hxx b/src/NCollection/NCollection_IndexedDataMap.hxx index ba2c818d24..0eb09ed769 100755 --- a/src/NCollection/NCollection_IndexedDataMap.hxx +++ b/src/NCollection/NCollection_IndexedDataMap.hxx @@ -11,6 +11,9 @@ #include #include #include + +#include + #if !defined No_Exception && !defined No_Standard_OutOfRange #include #endif @@ -39,7 +42,11 @@ * See the class Map from NCollection for a * discussion about the number of buckets. */ -template class NCollection_IndexedDataMap + +template < class TheKeyType, + class TheItemType, + class Hasher = NCollection_DefaultHasher > + class NCollection_IndexedDataMap : public NCollection_BaseCollection, public NCollection_BaseMap { @@ -167,8 +174,8 @@ template class NCollection_IndexedDataMap { TheKeyType aKey1 = theOther.FindKey(i); TheItemType anItem = theOther.FindFromIndex(i); - Standard_Integer iK1 = HashCode (aKey1, NbBuckets()); - Standard_Integer iK2 = HashCode (i, NbBuckets()); + Standard_Integer iK1 = Hasher::HashCode (aKey1, NbBuckets()); + Standard_Integer iK2 = ::HashCode (i, NbBuckets()); IndexedDataMapNode * pNode = new (this->myAllocator) IndexedDataMapNode (aKey1, i, anItem, myData1[iK1], myData2[iK2]); @@ -201,8 +208,8 @@ template class NCollection_IndexedDataMap p = (IndexedDataMapNode *) myData1[i]; while (p) { - iK1 = HashCode (p->Key1(), newBuck); - iK2 = HashCode (p->Key2(), newBuck); + iK1 = Hasher::HashCode (p->Key1(), newBuck); + iK2 = ::HashCode (p->Key2(), newBuck); q = (IndexedDataMapNode*) p->Next(); p->Next() = ppNewData1[iK1]; p->Next2() = ppNewData2[iK2]; @@ -225,17 +232,17 @@ template class NCollection_IndexedDataMap { if (Resizable()) ReSize(Extent()); - Standard_Integer iK1 = HashCode (theKey1, NbBuckets()); + Standard_Integer iK1 = Hasher::HashCode (theKey1, NbBuckets()); IndexedDataMapNode * pNode; pNode = (IndexedDataMapNode *) myData1[iK1]; while (pNode) { - if (IsEqual (pNode->Key1(), theKey1)) + if (Hasher::IsEqual (pNode->Key1(), theKey1)) return pNode->Key2(); pNode = (IndexedDataMapNode *) pNode->Next(); } Increment(); - Standard_Integer iK2 = HashCode(Extent(),NbBuckets()); + Standard_Integer iK2 = ::HashCode(Extent(),NbBuckets()); pNode = new (this->myAllocator) IndexedDataMapNode (theKey1, Extent(), theItem, myData1[iK1], myData2[iK2]); myData1[iK1] = pNode; @@ -248,12 +255,12 @@ template class NCollection_IndexedDataMap { if (IsEmpty()) return Standard_False; - Standard_Integer iK1 = HashCode (theKey1, NbBuckets()); + Standard_Integer iK1 = Hasher::HashCode (theKey1, NbBuckets()); IndexedDataMapNode * pNode1; pNode1 = (IndexedDataMapNode *) myData1[iK1]; while (pNode1) { - if (IsEqual(pNode1->Key1(), theKey1)) + if (Hasher::IsEqual(pNode1->Key1(), theKey1)) return Standard_True; pNode1 = (IndexedDataMapNode *) pNode1->Next(); } @@ -271,17 +278,17 @@ template class NCollection_IndexedDataMap #endif IndexedDataMapNode * p; // check if theKey1 is not already in the map - Standard_Integer iK1 = HashCode (theKey1, NbBuckets()); + Standard_Integer iK1 = Hasher::HashCode (theKey1, NbBuckets()); p = (IndexedDataMapNode *) myData1[iK1]; while (p) { - if (IsEqual (p->Key1(), theKey1)) + if (Hasher::IsEqual (p->Key1(), theKey1)) Standard_DomainError::Raise("NCollection_IndexedDataMap::Substitute"); p = (IndexedDataMapNode *) p->Next(); } // Find the node for the index I - Standard_Integer iK2 = HashCode (theIndex, NbBuckets()); + Standard_Integer iK2 = ::HashCode (theIndex, NbBuckets()); p = (IndexedDataMapNode *) myData2[iK2]; while (p) { @@ -291,7 +298,7 @@ template class NCollection_IndexedDataMap } // remove the old key - Standard_Integer iK = HashCode (p->Key1(), NbBuckets()); + Standard_Integer iK = Hasher::HashCode (p->Key1(), NbBuckets()); IndexedDataMapNode * q = (IndexedDataMapNode *) myData1[iK]; if (q == p) myData1[iK] = (IndexedDataMapNode *) p->Next(); @@ -318,7 +325,7 @@ template class NCollection_IndexedDataMap #endif IndexedDataMapNode * p, * q; // Find the node for the last index and remove it - Standard_Integer iK2 = HashCode (Extent(), NbBuckets()); + Standard_Integer iK2 = ::HashCode (Extent(), NbBuckets()); p = (IndexedDataMapNode *) myData2[iK2]; q = NULL; while (p) @@ -334,7 +341,7 @@ template class NCollection_IndexedDataMap q->Next2() = p->Next2(); // remove the key - Standard_Integer iK1 = HashCode (p->Key1(), NbBuckets()); + Standard_Integer iK1 = Hasher::HashCode (p->Key1(), NbBuckets()); q = (IndexedDataMapNode *) myData1[iK1]; if (q == p) myData1[iK1] = (IndexedDataMapNode *) p->Next(); @@ -357,7 +364,7 @@ template class NCollection_IndexedDataMap Standard_OutOfRange::Raise ("NCollection_IndexedDataMap::FindKey"); #endif IndexedDataMapNode * pNode2 = - (IndexedDataMapNode *) myData2[HashCode(theKey2,NbBuckets())]; + (IndexedDataMapNode *) myData2[::HashCode(theKey2,NbBuckets())]; while (pNode2) { if (pNode2->Key2() == theKey2) @@ -376,7 +383,7 @@ template class NCollection_IndexedDataMap Standard_OutOfRange::Raise ("NCollection_IndexedDataMap::FindFromIndex"); #endif IndexedDataMapNode * pNode2 = - (IndexedDataMapNode *) myData2[HashCode(theKey2,NbBuckets())]; + (IndexedDataMapNode *) myData2[::HashCode(theKey2,NbBuckets())]; while (pNode2) { if (pNode2->Key2() == theKey2) @@ -399,7 +406,7 @@ template class NCollection_IndexedDataMap Standard_OutOfRange::Raise("NCollection_IndexedDataMap::ChangeFromIndex"); #endif IndexedDataMapNode * pNode2 = - (IndexedDataMapNode *) myData2[HashCode(theKey2,NbBuckets())]; + (IndexedDataMapNode *) myData2[::HashCode(theKey2,NbBuckets())]; while (pNode2) { if (pNode2->Key2() == theKey2) @@ -419,10 +426,10 @@ template class NCollection_IndexedDataMap { if (IsEmpty()) return 0; IndexedDataMapNode * pNode1 = - (IndexedDataMapNode *) myData1[HashCode(theKey1,NbBuckets())]; + (IndexedDataMapNode *) myData1[Hasher::HashCode(theKey1,NbBuckets())]; while (pNode1) { - if (IsEqual (pNode1->Key1(), theKey1)) + if (Hasher::IsEqual (pNode1->Key1(), theKey1)) return pNode1->Key2(); pNode1 = (IndexedDataMapNode*) pNode1->Next(); } @@ -437,10 +444,10 @@ template class NCollection_IndexedDataMap Standard_NoSuchObject::Raise ("NCollection_IndexedDataMap::FindFromKey"); #endif IndexedDataMapNode * pNode1 = - (IndexedDataMapNode *) myData1[HashCode(theKey1,NbBuckets())]; + (IndexedDataMapNode *) myData1[Hasher::HashCode(theKey1,NbBuckets())]; while (pNode1) { - if (IsEqual (pNode1->Key1(), theKey1)) + if (Hasher::IsEqual (pNode1->Key1(), theKey1)) return pNode1->Value(); pNode1 = (IndexedDataMapNode*) pNode1->Next(); } @@ -456,10 +463,10 @@ template class NCollection_IndexedDataMap Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::ChangeFromKey"); #endif IndexedDataMapNode * pNode1 = - (IndexedDataMapNode *) myData1[HashCode(theKey1,NbBuckets())]; + (IndexedDataMapNode *) myData1[Hasher::HashCode(theKey1,NbBuckets())]; while (pNode1) { - if (IsEqual (pNode1->Key1(), theKey1)) + if (Hasher::IsEqual (pNode1->Key1(), theKey1)) return pNode1->ChangeValue(); pNode1 = (IndexedDataMapNode*) pNode1->Next(); } diff --git a/src/NCollection/NCollection_IndexedMap.hxx b/src/NCollection/NCollection_IndexedMap.hxx index 8b4e6ea63e..1a53813b6a 100755 --- a/src/NCollection/NCollection_IndexedMap.hxx +++ b/src/NCollection/NCollection_IndexedMap.hxx @@ -12,6 +12,8 @@ #include #include +#include + #if !defined No_Exception && !defined No_Standard_OutOfRange #include #endif @@ -32,7 +34,10 @@ * See the class Map from NCollection for a * discussion about the number of buckets. */ -template class NCollection_IndexedMap + +template < class TheKeyType, + class Hasher = NCollection_DefaultHasher > + class NCollection_IndexedMap : public NCollection_BaseCollection, public NCollection_BaseMap { @@ -160,8 +165,8 @@ template class NCollection_IndexedMap for (i=1; i<=iLength; i++) { TheKeyType aKey1 = theOther(i); - Standard_Integer iK1 = HashCode (aKey1, NbBuckets()); - Standard_Integer iK2 = HashCode (i, NbBuckets()); + Standard_Integer iK1 = Hasher::HashCode (aKey1, NbBuckets()); + Standard_Integer iK2 = ::HashCode (i, NbBuckets()); IndexedMapNode * pNode = new (this->myAllocator) IndexedMapNode (aKey1, i, myData1[iK1], myData2[iK2]); @@ -194,13 +199,13 @@ template class NCollection_IndexedMap p = (IndexedMapNode *) myData1[i]; while (p) { - iK1 = HashCode (p->Key1(), newBuck); + iK1 =Hasher::HashCode(p->Key1(), newBuck); q = (IndexedMapNode*) p->Next(); p->Next() = ppNewData1[iK1]; ppNewData1[iK1] = p; if (p->Key2() > 0) { - iK2 = HashCode (p->Key2(), newBuck); + iK2 = ::HashCode (p->Key2(), newBuck); p->Next2() = ppNewData2[iK2]; ppNewData2[iK2] = p; } @@ -221,17 +226,17 @@ template class NCollection_IndexedMap { if (Resizable()) ReSize(Extent()); - Standard_Integer iK1 = HashCode (theKey1, NbBuckets()); + Standard_Integer iK1 = Hasher::HashCode (theKey1, NbBuckets()); IndexedMapNode * pNode; pNode = (IndexedMapNode *) myData1[iK1]; while (pNode) { - if (IsEqual (pNode->Key1(), theKey1)) + if (Hasher::IsEqual (pNode->Key1(), theKey1)) return pNode->Key2(); pNode = (IndexedMapNode *) pNode->Next(); } Increment(); - Standard_Integer iK2 = HashCode(Extent(),NbBuckets()); + Standard_Integer iK2 = ::HashCode(Extent(),NbBuckets()); pNode = new (this->myAllocator) IndexedMapNode (theKey1, Extent(), myData1[iK1], myData2[iK2]); myData1[iK1] = pNode; @@ -244,12 +249,12 @@ template class NCollection_IndexedMap { if (IsEmpty()) return Standard_False; - Standard_Integer iK1 = HashCode (theKey1, NbBuckets()); + Standard_Integer iK1 = Hasher::HashCode (theKey1, NbBuckets()); IndexedMapNode * pNode1; pNode1 = (IndexedMapNode *) myData1[iK1]; while (pNode1) { - if (IsEqual(pNode1->Key1(), theKey1)) + if (Hasher::IsEqual(pNode1->Key1(), theKey1)) return Standard_True; pNode1 = (IndexedMapNode *) pNode1->Next(); } @@ -266,17 +271,17 @@ template class NCollection_IndexedMap #endif IndexedMapNode * p; // check if theKey1 is not already in the map - Standard_Integer iK1 = HashCode (theKey1, NbBuckets()); + Standard_Integer iK1 = Hasher::HashCode (theKey1, NbBuckets()); p = (IndexedMapNode *) myData1[iK1]; while (p) { - if (IsEqual (p->Key1(), theKey1)) + if (Hasher::IsEqual (p->Key1(), theKey1)) Standard_DomainError::Raise("NCollection_IndexedMap::Substitute"); p = (IndexedMapNode *) p->Next(); } // Find the node for the index I - Standard_Integer iK2 = HashCode (theIndex, NbBuckets()); + Standard_Integer iK2 = ::HashCode (theIndex, NbBuckets()); p = (IndexedMapNode *) myData2[iK2]; while (p) { @@ -286,7 +291,7 @@ template class NCollection_IndexedMap } // remove the old key - Standard_Integer iK = HashCode (p->Key1(), NbBuckets()); + Standard_Integer iK = Hasher::HashCode (p->Key1(), NbBuckets()); IndexedMapNode * q = (IndexedMapNode *) myData1[iK]; if (q == p) myData1[iK] = (IndexedMapNode *) p->Next(); @@ -312,7 +317,7 @@ template class NCollection_IndexedMap #endif IndexedMapNode * p, * q; // Find the node for the last index and remove it - Standard_Integer iK2 = HashCode (Extent(), NbBuckets()); + Standard_Integer iK2 = ::HashCode (Extent(), NbBuckets()); p = (IndexedMapNode *) myData2[iK2]; q = NULL; while (p) @@ -328,7 +333,7 @@ template class NCollection_IndexedMap q->Next2() = p->Next2(); // remove the key - Standard_Integer iK1 = HashCode (p->Key1(), NbBuckets()); + Standard_Integer iK1 = Hasher::HashCode (p->Key1(), NbBuckets()); q = (IndexedMapNode *) myData1[iK1]; if (q == p) myData1[iK1] = (IndexedMapNode *) p->Next(); @@ -351,7 +356,7 @@ template class NCollection_IndexedMap Standard_OutOfRange::Raise ("NCollection_IndexedMap::FindKey"); #endif IndexedMapNode * pNode2 = - (IndexedMapNode *) myData2[HashCode(theKey2,NbBuckets())]; + (IndexedMapNode *) myData2[::HashCode(theKey2,NbBuckets())]; while (pNode2) { if (pNode2->Key2() == theKey2) @@ -371,10 +376,10 @@ template class NCollection_IndexedMap { if (IsEmpty()) return 0; IndexedMapNode * pNode1 = - (IndexedMapNode *) myData1[HashCode(theKey1,NbBuckets())]; + (IndexedMapNode *) myData1[Hasher::HashCode(theKey1,NbBuckets())]; while (pNode1) { - if (IsEqual (pNode1->Key1(), theKey1)) + if (Hasher::IsEqual (pNode1->Key1(), theKey1)) return pNode1->Key2(); pNode1 = (IndexedMapNode*) pNode1->Next(); } diff --git a/src/NCollection/NCollection_Map.hxx b/src/NCollection/NCollection_Map.hxx index 4369517a95..a7a3a076a7 100755 --- a/src/NCollection/NCollection_Map.hxx +++ b/src/NCollection/NCollection_Map.hxx @@ -9,6 +9,9 @@ #include #include #include + +#include + #include #if !defined No_Exception && !defined No_Standard_NoSuchObject @@ -48,12 +51,15 @@ * method. This should be consider only for crucial * optimisation issues. */ -template class NCollection_Map + +template < class TheKeyType, + class Hasher = NCollection_DefaultHasher > class NCollection_Map : public NCollection_BaseCollection, public NCollection_BaseMap { //! Adaptation of the TListNode to the map notations public: + class MapNode : public NCollection_TListNode { public: @@ -182,7 +188,7 @@ template class NCollection_Map p = olddata[i]; while (p) { - k = HashCode(p->Key(),newBuck); + k = Hasher::HashCode(p->Key(),newBuck); q = (MapNode*) p->Next(); p->Next() = newdata[k]; newdata[k] = p; @@ -204,11 +210,11 @@ template class NCollection_Map if (Resizable()) ReSize(Extent()); MapNode** data = (MapNode**)myData1; - Standard_Integer k = HashCode(K,NbBuckets()); + Standard_Integer k = Hasher::HashCode(K,NbBuckets()); MapNode* p = data[k]; while (p) { - if (IsEqual(p->Key(),K)) + if (Hasher::IsEqual(p->Key(),K)) return Standard_False; p = (MapNode *) p->Next(); } @@ -224,11 +230,11 @@ template class NCollection_Map if (Resizable()) ReSize(Extent()); MapNode** data = (MapNode**)myData1; - Standard_Integer k = HashCode(K,NbBuckets()); + Standard_Integer k = Hasher::HashCode(K,NbBuckets()); MapNode* p = data[k]; while (p) { - if (IsEqual(p->Key(),K)) + if (Hasher::IsEqual(p->Key(),K)) return p->Key(); p = (MapNode *) p->Next(); } @@ -243,10 +249,10 @@ template class NCollection_Map if (IsEmpty()) return Standard_False; MapNode** data = (MapNode**) myData1; - MapNode* p = data[HashCode(K,NbBuckets())]; + MapNode* p = data[Hasher::HashCode(K,NbBuckets())]; while (p) { - if (IsEqual(p->Key(),K)) + if (Hasher::IsEqual(p->Key(),K)) return Standard_True; p = (MapNode *) p->Next(); } @@ -259,12 +265,12 @@ template class NCollection_Map if (IsEmpty()) return Standard_False; MapNode** data = (MapNode**) myData1; - Standard_Integer k = HashCode(K,NbBuckets()); + Standard_Integer k = Hasher::HashCode(K,NbBuckets()); MapNode* p = data[k]; MapNode* q = NULL; while (p) { - if (IsEqual(p->Key(),K)) + if (Hasher::IsEqual(p->Key(),K)) { Decrement(); if (q)