NCollection_QuickSort.hxx
NCollection_Haft.h
+
+
+NCollection_DefaultHasher.hxx
\ No newline at end of file
myCurrent = theList.myFirst;
myPrevious = NULL;
}
+ // ******** Initialisation
+ void Initialize (const NCollection_BaseList& theList)
+ {
+ Init(theList);
+ }
// ******** More
Standard_Boolean More (void) const
{ return (myCurrent!=NULL); }
#include <NCollection_BaseMap.hxx>
#include <NCollection_TListNode.hxx>
+#include <NCollection_DefaultHasher.hxx>
+
#include <Standard_TypeMismatch.hxx>
#include <Standard_NoSuchObject.hxx>
* can be done only if aKey was previously bound to
* an item in the map.
*/
-template <class TheKeyType, class TheItemType> class NCollection_DataMap
+
+template < class TheKeyType,
+ class TheItemType,
+ class Hasher = NCollection_DefaultHasher<TheKeyType> > class NCollection_DataMap
+
: public NCollection_BaseCollection<TheItemType>,
public NCollection_BaseMap
{
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;
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;
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();
}
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)
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();
}
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();
}
#endif
#endif
+
--- /dev/null
+// File: NCollection_DefaultHasher.hxx
+// Created:
+// Author: Eugene Maltchikov
+//
+
+
+#ifndef NCollection_DefaultHasher_HeaderFile
+#define NCollection_DefaultHasher_HeaderFile
+
+#include <Standard_Integer.hxx>
+#include <Standard_Boolean.hxx>
+
+//=======================================================================
+//function : HashCode_Proxy
+//purpose : Function is required to call the global function HashCode.
+//=======================================================================
+template <class TheKeyType>
+ 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 <class TheKeyType>
+ 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 TheKeyType> 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
#include <Standard_ImmutableObject.hxx>
#include <Standard_NoSuchObject.hxx>
+#include <NCollection_DefaultHasher.hxx>
+
#ifdef WNT
// Disable the warning "operator new unmatched by delete"
#pragma warning (push)
* See Map from NCollection for a discussion about the number
* of buckets
*/
-template <class TheKey1Type, class TheKey2Type> class NCollection_DoubleMap
+
+template < class TheKey1Type,
+ class TheKey2Type,
+ class Hasher1 = NCollection_DefaultHasher<TheKey1Type>,
+ class Hasher2 = NCollection_DefaultHasher<TheKey2Type> > class NCollection_DoubleMap
: public NCollection_BaseCollection<TheKey2Type>,
public NCollection_BaseMap
{
{
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]);
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];
{
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();
}
{
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();
}
pNode2 = (DoubleMapNode *) myData2[iK2];
while (pNode2)
{
- if (IsEqual(pNode2->Key2(), theKey2))
+ if (Hasher2::IsEqual(pNode2->Key2(), theKey2))
break;
pNode2 = (DoubleMapNode *) pNode2->Next();
}
{
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();
}
{
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();
}
{
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)
{
{
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)
{
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();
}
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();
}
#include <NCollection_TListNode.hxx>
#include <Standard_TypeMismatch.hxx>
#include <Standard_NoSuchObject.hxx>
+
+#include <NCollection_DefaultHasher.hxx>
+
#if !defined No_Exception && !defined No_Standard_OutOfRange
#include <Standard_OutOfRange.hxx>
#endif
* See the class Map from NCollection for a
* discussion about the number of buckets.
*/
-template <class TheKeyType, class TheItemType> class NCollection_IndexedDataMap
+
+template < class TheKeyType,
+ class TheItemType,
+ class Hasher = NCollection_DefaultHasher<TheKeyType> >
+ class NCollection_IndexedDataMap
: public NCollection_BaseCollection<TheItemType>,
public NCollection_BaseMap
{
{
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]);
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];
{
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;
{
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();
}
#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)
{
}
// 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();
#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)
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();
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)
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)
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)
{
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();
}
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();
}
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();
}
#include <Standard_NoSuchObject.hxx>
#include <Standard_ImmutableObject.hxx>
+#include <NCollection_DefaultHasher.hxx>
+
#if !defined No_Exception && !defined No_Standard_OutOfRange
#include <Standard_OutOfRange.hxx>
#endif
* See the class Map from NCollection for a
* discussion about the number of buckets.
*/
-template <class TheKeyType> class NCollection_IndexedMap
+
+template < class TheKeyType,
+ class Hasher = NCollection_DefaultHasher<TheKeyType> >
+ class NCollection_IndexedMap
: public NCollection_BaseCollection<TheKeyType>,
public NCollection_BaseMap
{
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]);
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;
}
{
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;
{
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();
}
#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)
{
}
// 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();
#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)
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();
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)
{
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();
}
#include <NCollection_BaseCollection.hxx>
#include <NCollection_BaseMap.hxx>
#include <NCollection_TListNode.hxx>
+
+#include <NCollection_DefaultHasher.hxx>
+
#include <Standard_ImmutableObject.hxx>
#if !defined No_Exception && !defined No_Standard_NoSuchObject
* method. This should be consider only for crucial
* optimisation issues.
*/
-template <class TheKeyType> class NCollection_Map
+
+template < class TheKeyType,
+ class Hasher = NCollection_DefaultHasher<TheKeyType> > class NCollection_Map
: public NCollection_BaseCollection<TheKeyType>,
public NCollection_BaseMap
{
//! Adaptation of the TListNode to the map notations
public:
+
class MapNode : public NCollection_TListNode<TheKeyType>
{
public:
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;
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();
}
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();
}
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();
}
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)