-// Copyright (C) 2006 SAMTECH
+// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// File: NMTDS_PassKey.cxx
-// Created:
+//
+// File: NMTDS_Algo.cxx
+// Created: Sat Dec 04 12:39:47 2004
// Author: Peter KURNEV
-// <pkv@irinox>
+// <peter@PREFEX>
#include <NMTDS_PassKey.ixx>
#include <stdio.h>
#include <string.h>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
+#include <TColStd_ListOfInteger.hxx>
#ifdef WNT
#pragma warning( disable : 4101)
#endif
-static
- void SortShell(const int n, int* a);
static
Standard_Integer NormalizedId(const Standard_Integer aId,
const Standard_Integer aDiv);
//=======================================================================
NMTDS_PassKey::NMTDS_PassKey()
{
- Clear();
+ Clear();
+}
+//=======================================================================
+//function :
+//purpose :
+//=======================================================================
+ NMTDS_PassKey::NMTDS_PassKey(const NMTDS_PassKey& aOther)
+{
+ myNbIds=aOther.myNbIds;
+ mySum=aOther.mySum;
+ myMap=aOther.myMap;
}
//=======================================================================
-//function :Assign
+//function :operator =
//purpose :
//=======================================================================
- NMTDS_PassKey& NMTDS_PassKey::Assign(const NMTDS_PassKey& anOther)
+ NMTDS_PassKey& NMTDS_PassKey::operator =(const NMTDS_PassKey& aOther)
{
- myNbIds=anOther.myNbIds;
- myNbMax=anOther.myNbMax;
- mySum=anOther.mySum;
- memcpy(myIds, anOther.myIds, sizeof(myIds));
+ myNbIds=aOther.myNbIds;
+ mySum=aOther.mySum;
+ myMap=aOther.myMap;
return *this;
}
//=======================================================================
+//function :~
+//purpose :
+//=======================================================================
+ NMTDS_PassKey::~NMTDS_PassKey()
+{
+}
+//=======================================================================
//function :Clear
//purpose :
//=======================================================================
void NMTDS_PassKey::Clear()
{
- Standard_Integer i;
- //
myNbIds=0;
- myNbMax=2;
mySum=0;
- for (i=0; i<myNbMax; ++i) {
- myIds[i]=0;
- }
+ myMap.Clear();
+}
+//=======================================================================
+//function :SetIds
+//purpose :
+//=======================================================================
+ void NMTDS_PassKey::SetIds(const Standard_Integer aId1)
+
+{
+ Clear();
+ myNbIds=1;
+ myMap.Add(aId1);
+ mySum=NormalizedId(aId1, myNbIds);
+}
+//=======================================================================
+//function :SetIds
+//purpose :
+//=======================================================================
+ void NMTDS_PassKey::SetIds(const Standard_Integer aId1,
+ const Standard_Integer aId2)
+{
+ TColStd_ListOfInteger aLI;
+ //
+ aLI.Append(aId1);
+ aLI.Append(aId2);
+ SetIds(aLI);
}
//=======================================================================
//function :SetIds
//purpose :
//=======================================================================
- void NMTDS_PassKey::SetIds(const Standard_Integer anId1,
- const Standard_Integer anId2)
+ void NMTDS_PassKey::SetIds(const Standard_Integer aId1,
+ const Standard_Integer aId2,
+ const Standard_Integer aId3)
{
- Standard_Integer aIdN1, aIdN2;
+ TColStd_ListOfInteger aLI;
//
- myNbIds=2;
- aIdN1=NormalizedId(anId1, myNbIds);
- aIdN2=NormalizedId(anId2, myNbIds);
- mySum=aIdN1+aIdN2;
+ aLI.Append(aId1);
+ aLI.Append(aId2);
+ aLI.Append(aId3);
+ SetIds(aLI);
+}
+//=======================================================================
+//function :SetIds
+//purpose :
+//=======================================================================
+ void NMTDS_PassKey::SetIds(const Standard_Integer aId1,
+ const Standard_Integer aId2,
+ const Standard_Integer aId3,
+ const Standard_Integer aId4)
+{
+ TColStd_ListOfInteger aLI;
//
- if (anId1<anId2) {
- myIds[myNbMax-2]=anId1;
- myIds[myNbMax-1]=anId2;
- return;
- }
- myIds[myNbMax-2]=anId2;
- myIds[myNbMax-1]=anId1;
+ aLI.Append(aId1);
+ aLI.Append(aId2);
+ aLI.Append(aId3);
+ aLI.Append(aId4);
+ SetIds(aLI);
}
//=======================================================================
-//function :Ids
+//function :SetIds
//purpose :
//=======================================================================
- void NMTDS_PassKey::Ids(Standard_Integer& aId1,
- Standard_Integer& aId2)const
+ void NMTDS_PassKey::SetIds(const TColStd_ListOfInteger& aLI)
{
- aId1=myIds[0];
- aId2=myIds[1];
+ Standard_Integer i, aId, aIdN;
+ TColStd_ListIteratorOfListOfInteger aIt;
+ //
+ Clear();
+ aIt.Initialize(aLI);
+ for (; aIt.More(); aIt.Next()) {
+ aId=aIt.Value();
+ myMap.Add(aId);
+ }
+ myNbIds=myMap.Extent();
+ for(i=1; i<=myNbIds; ++i) {
+ aId=myMap(i);
+ aIdN=NormalizedId(aId, myNbIds);
+ mySum+=aIdN;
+ }
}
+
//=======================================================================
-//function :NbMax
+//function :NbIds
//purpose :
//=======================================================================
- Standard_Integer NMTDS_PassKey::NbMax()const
+ Standard_Integer NMTDS_PassKey::NbIds()const
{
- return myNbMax;
+ return myNbIds;
}
//=======================================================================
-//function :Compute
+//function :Id
//purpose :
//=======================================================================
- void NMTDS_PassKey::Compute()
+ Standard_Integer NMTDS_PassKey::Id(const Standard_Integer aIndex) const
{
- SortShell(myNbIds, myIds+myNbMax-myNbIds);
+ if (aIndex<1 || aIndex>myNbIds) {
+ return -1;
+ }
+ return myMap(aIndex);
}
//=======================================================================
-//function :IsEqual
+//function :Ids
//purpose :
//=======================================================================
- Standard_Boolean NMTDS_PassKey::IsEqual(const NMTDS_PassKey& anOther) const
+ void NMTDS_PassKey::Ids(Standard_Integer& aId1,
+ Standard_Integer& aId2) const
{
- Standard_Integer iIsEqual;
- Standard_Boolean bIsEqual;
- //
- iIsEqual=memcmp(myIds, anOther.myIds, sizeof(myIds));
- bIsEqual=Standard_False;
- if (!iIsEqual) {
- bIsEqual=!bIsEqual;
+ aId1=0;
+ aId2=0;
+ if (myNbIds>1) {
+ aId1=myMap(1);
+ aId2=myMap(2);
}
- return bIsEqual;
}
//=======================================================================
-//function :Key
+//function :IsEqual
//purpose :
//=======================================================================
- Standard_Address NMTDS_PassKey::Key()const
+ Standard_Boolean NMTDS_PassKey::IsEqual(const NMTDS_PassKey& aOther) const
{
- return (Standard_Address)myIds;
+ Standard_Boolean bRet;
+ Standard_Integer i, aId;
+ //
+ bRet=Standard_False;
+ //
+ if (myNbIds!=aOther.myNbIds) {
+ return bRet;
+ }
+ for (i=1; i<=myNbIds; ++i) {
+ aId=myMap(i);
+ if (!aOther.myMap.Contains(aId)) {
+ return bRet;
+ }
+ }
+ return !bRet;
}
//=======================================================================
//function : HashCode
//purpose :
//=======================================================================
- Standard_Integer NMTDS_PassKey::HashCode(const Standard_Integer Upper) const
+ Standard_Integer NMTDS_PassKey::HashCode(const Standard_Integer aUpper) const
{
- return ::HashCode(mySum, Upper);
+ return ::HashCode(mySum, aUpper);
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
- void NMTDS_PassKey::Dump()const
+ void NMTDS_PassKey::Dump(const Standard_Integer )const
{
- Standard_Integer i;
- //
- printf(" PassKey: {");
- for (i=0; i<myNbMax; ++i) {
- printf(" %d", myIds[i]);
- }
- printf(" }");
}
+
//=======================================================================
// function: NormalizedId
// purpose :
}
return aIdRet;
}
+/*
+//=========
//=======================================================================
-// function: SortShell
-// purpose :
+//function : Contains
+//purpose :
+//=======================================================================
+ Standard_Boolean NMTDS_PassKey::Contains(const Standard_Integer aId) const
+{
+ return myMap.Contains(aId);
+}
+//=======================================================================
+//function :Contains
+//purpose :
+//=======================================================================
+ Standard_Boolean NMTDS_PassKey::Contains(const NMTDS_PassKey& aOther) const
+{
+ Standard_Boolean bRet;
+ Standard_Integer i, aId;
+ //
+ bRet=Standard_False;
+ //
+ if (myNbIds<aOther.myNbIds) {
+ return bRet;
+ }
+ for (i=1; i<=aOther.myNbIds; ++i) {
+ aId=aOther.myMap(i);
+ if (!myMap.Contains(aId)) {
+ return bRet;
+ }
+ }
+ return !bRet;
+}
+//=======================================================================
+//function :Intersected
+//purpose :
//=======================================================================
-void SortShell(const int n, int* a)
+ Standard_Boolean NMTDS_PassKey::Intersected(const NMTDS_PassKey& aOther) const
{
- int x, nd, i, j, l, d=1;
+ Standard_Boolean bRet;
+ Standard_Integer i, aId;
//
- while(d<=n) {
- d*=2;
+ bRet=Standard_False;
+ //
+ for (i=1; i<=myNbIds; ++i) {
+ aId=myMap(i);
+ if (aOther.Contains(aId)) {
+ return !bRet;
+ }
+ }
+ return bRet;
+}
+//=======================================================================
+//function : Add
+//purpose :
+//=======================================================================
+ void NMTDS_PassKey::Add(const Standard_Integer aId)
+{
+ TColStd_ListOfInteger aLI;
+ aLI.Append(aId);
+ //
+ Add(aLI);
+}
+//=======================================================================
+//function : Add
+//purpose :
+//=======================================================================
+ void NMTDS_PassKey::Add(const NMTDS_PassKey& aOther)
+{
+ Standard_Integer i, aId;
+ TColStd_ListOfInteger aLS;
+ //
+ for(i=1; i<=myNbIds; ++i) {
+ aId=myMap(i);
+ aLS.Append(aId);
+ }
+ for(i=1; i<=aOther.myNbIds; ++i) {
+ aId=aOther.myMap(i);
+ aLS.Append(aId);
+ }
+ //
+ Add(aLS);
+}
+//=======================================================================
+//function : Add
+//purpose :
+//=======================================================================
+ void NMTDS_PassKey::Add(const TColStd_ListOfInteger& aLI)
+{
+ Standard_Integer i, aId;
+ TColStd_ListOfInteger aLS;
+ TColStd_ListIteratorOfListOfInteger aIt;
+ //
+ for(i=1; i<=myNbIds; ++i) {
+ aId=myMap(i);
+ aLS.Append(aId);
+ }
+ aIt.Initialize(aLI);
+ for (; aIt.More(); aIt.Next()) {
+ aId=aIt.Value();
+ aLS.Append(aId);
}
//
- while (d) {
- d=(d-1)/2;
- //
- nd=n-d;
- for (i=0; i<nd; ++i) {
- j=i;
- m30:;
- l=j+d;
- if (a[l] < a[j]){
- x=a[j];
- a[j]=a[l];
- a[l]=x;
- j-=d;
- if (j > -1) goto m30;
- }//if (a[l] < a[j]){
- }//for (i=0; i<nd; ++i)
- }//while (1)
+ SetIds(aLS);
}
+//=========
+*/