1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0026157: NCollection, TCollection packages - IndexedMap, IndexedDataMap ::Substitute() do not allow passing equal key for the same index

cosmetic remarks from msv
This commit is contained in:
apl
2015-04-30 14:55:07 +03:00
committed by bugmaster
parent d66bd706ce
commit 985aed12ec
5 changed files with 75 additions and 20 deletions

View File

@@ -292,16 +292,27 @@ class NCollection_IndexedDataMap : public NCollection_BaseMap
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();
}

View File

@@ -263,16 +263,26 @@ class NCollection_IndexedMap : public NCollection_BaseMap
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();
}