const TheKeyType& theKey1,
const TheItemType& theItem)
{
- Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > Extent(), "NCollection_IndexedDataMap::Substitute");
+ Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > Extent(),
+ "NCollection_IndexedDataMap::Substitute : "
+ "Index is out of range");
IndexedDataMapNode * p;
// check if theKey1 is not already in the map
Standard_Integer iK1 = Hasher::HashCode (theKey1, NbBuckets());
p = (IndexedDataMapNode *) myData1[iK1];
- while (p)
+ while (p)
{
- if (Hasher::IsEqual (p->Key1(), theKey1))
- Standard_DomainError::Raise("NCollection_IndexedDataMap::Substitute");
+ if (Hasher::IsEqual (p->Key1(), theKey1))
+ {
+ if (p->Key2() != theIndex)
+ {
+ Standard_DomainError::Raise ("NCollection_IndexedDataMap::Substitute : "
+ "Attempt to substitute existing key");
+ }
+ p->Key1() = theKey1;
+ p->ChangeValue() = theItem;
+ return;
+ }
p = (IndexedDataMapNode *) p->Next();
}
void Substitute (const Standard_Integer theIndex,
const TheKeyType& theKey1)
{
- Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > Extent(), "NCollection_IndexedMap::Substitute");
+ Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > Extent(),
+ "NCollection_IndexedMap::Substitute : "
+ "Index is out of range");
IndexedMapNode * p;
// check if theKey1 is not already in the map
Standard_Integer iK1 = Hasher::HashCode (theKey1, NbBuckets());
p = (IndexedMapNode *) myData1[iK1];
- while (p)
+ while (p)
{
- if (Hasher::IsEqual (p->Key1(), theKey1))
- Standard_DomainError::Raise("NCollection_IndexedMap::Substitute");
+ if (Hasher::IsEqual (p->Key1(), theKey1))
+ {
+ if (p->Key2() != theIndex)
+ {
+ Standard_DomainError::Raise ("NCollection_IndexedMap::Substitute : "
+ "Attempt to substitute existing key");
+ }
+ p->Key1() = theKey1;
+ return;
+ }
p = (IndexedMapNode *) p->Next();
}
#include <gp_Pnt.hxx>
+#include <Precision.hxx>
+
#include <NCollection_Vector.hxx>
#define ItemType gp_Pnt
// Substitute
Random(aKey);
aM.Substitute(1,aKey);
+ if (!aM.Contains (aKey) || aM.FindIndex (aKey) != 1)
+ {
+ printf("Error : map does not contain valid key after substitute");
+ }
+ // Invoke substitute with the same key
+ aM.Substitute(1,aKey);
+ if (!aM.Contains (aKey) || aM.FindIndex (aKey) != 1)
+ {
+ printf("Error : map does not contain valid key after substitute");
+ }
// Copy constructor (including operator=)
////////////////////////////////QANCollection_IndexedMap aM2 = QANCollection_IndexedMap(aM);
QANCollection_IndexedMapFunc aM2 = QANCollection_IndexedMapFunc(aM);
aM.RemoveLast();
printf(" successfully removed item, l=%d\n", aM.Size());
}
- // Substitute
+ // Substitute with different keys
Random(aKey);
aM.Substitute (1, aKey, anItem);
+ if (!aM.Contains (aKey) || aM.FindIndex (aKey) != 1 || !aM.FindFromKey (aKey).IsEqual (anItem, Precision::Confusion()))
+ {
+ printf("Error : map does not contain valid key and item after substitute");
+ }
+ // Substitute with equal keys
+ Random(anItem);
+ aM.Substitute (1, aKey, anItem);
+ if (!aM.Contains (aKey) || aM.FindIndex (aKey) != 1 || !aM.FindFromKey (aKey).IsEqual (anItem, Precision::Confusion()))
+ {
+ printf("Error : map does not contain valid key and item after substitute");
+ }
// Copy constructor (including operator=)
////////////////////////////////theM = QANCollection_IDMap(aM);
theM = QANCollection_IDMapFunc(aM);
//=======================================================================
void TCollection_IndexedDataMap::Substitute(const Standard_Integer I,
- const TheKey& K1,
- const TheItem& T)
+ const TheKey& K1,
+ const TheItem& T)
{
- Standard_OutOfRange_Raise_if(I < 1 || I > Extent(),
- "IndexedMap::Substitute");
+ Standard_OutOfRange_Raise_if(I < 1 || I > Extent(), "IndexedDataMap::Substitute : "
+ "Index is out of range");
TCollection_IndexedDataMapNode** data1 = (TCollection_IndexedDataMapNode**)myData1;
TCollection_IndexedDataMapNode* p;
Standard_Integer k1 = Hasher::HashCode(K1,NbBuckets());
p = data1[k1];
while (p) {
- if (Hasher::IsEqual(p->Key1(),K1))
- Standard_DomainError::Raise("IndexedMap::Substitute");
+ if (Hasher::IsEqual(p->Key1(),K1)) {
+ if (p->Key2() != I)
+ Standard_DomainError::Raise("IndexedDataMap::Substitute : "
+ "Attempt to substitute existing key");
+ p->Key1() = K1;
+ p->Value() = T;
+ return;
+ }
p = (TCollection_IndexedDataMapNode*) p->Next();
}
//=======================================================================
void TCollection_IndexedMap::Substitute(const Standard_Integer I,
- const TheKey& K1)
+ const TheKey& K1)
{
- Standard_OutOfRange_Raise_if(I < 1 || I > Extent(),
- "IndexedMap::Substitute");
+ Standard_OutOfRange_Raise_if(I < 1 || I > Extent(), "IndexedMap::Substitute : "
+ "Index is out of range");
TCollection_IndexedMapNode** data1 = (TCollection_IndexedMapNode**)myData1;
TCollection_IndexedMapNode* p;
Standard_Integer k1 = Hasher::HashCode(K1,NbBuckets());
p = data1[k1];
while (p) {
- if (Hasher::IsEqual(p->Key1(),K1))
- Standard_DomainError::Raise("IndexedMap::Substitute");
+ if (Hasher::IsEqual(p->Key1(),K1)) {
+ if (p->Key2() != I)
+ Standard_DomainError::Raise("IndexedMap::Substitute : "
+ "Attempt to substitute existing key");
+ p->Key1() = K1;
+ return;
+ }
p = (TCollection_IndexedMapNode*) p->Next();
}