1 // File: GEOMAlgo_PassKey.cxx
3 // Author: Peter KURNEV
7 #include <GEOMAlgo_PassKey.ixx>
12 #include <TopTools_ListIteratorOfListOfShape.hxx>
15 #pragma warning( disable : 4101)
19 void SortShell(const int n, int* a);
21 //=======================================================================
24 //=======================================================================
25 GEOMAlgo_PassKey::GEOMAlgo_PassKey()
29 //=======================================================================
32 //=======================================================================
33 void GEOMAlgo_PassKey::Clear()
38 myIds[0]=0; myIds[1]=0; myIds[2]=0; myIds[3]=0;
39 myIds[4]=0; myIds[5]=0; myIds[6]=0; myIds[7]=0;
40 myUpper=432123;//2147483647;
42 //=======================================================================
45 //=======================================================================
46 GEOMAlgo_PassKey& GEOMAlgo_PassKey::Assign(const GEOMAlgo_PassKey& anOther)
48 myNbIds=anOther.myNbIds;
49 myNbMax=anOther.myNbMax;
51 memcpy(myIds, anOther.myIds, sizeof(myIds));
54 //=======================================================================
57 //=======================================================================
58 void GEOMAlgo_PassKey::SetIds(const TopoDS_Shape& aS1)
61 Standard_Integer anId1;
63 anId1=aS1.HashCode(myUpper);
69 //=======================================================================
72 //=======================================================================
73 void GEOMAlgo_PassKey::SetIds(const TopoDS_Shape& aS1,
74 const TopoDS_Shape& aS2)
76 Standard_Integer anId1, anId2;
78 anId1=aS1.HashCode(myUpper);
79 anId2=aS2.HashCode(myUpper);
91 //=======================================================================
94 //=======================================================================
95 void GEOMAlgo_PassKey::SetIds(const TopoDS_Shape& aS1,
96 const TopoDS_Shape& aS2,
97 const TopoDS_Shape& aS3)
99 Standard_Integer anId1, anId2, anId3;
101 anId1=aS1.HashCode(myUpper);
102 anId2=aS2.HashCode(myUpper);
103 anId3=aS3.HashCode(myUpper);
109 mySum=anId1+anId2+anId3;
112 //=======================================================================
115 //=======================================================================
116 void GEOMAlgo_PassKey::SetIds(const TopoDS_Shape& aS1,
117 const TopoDS_Shape& aS2,
118 const TopoDS_Shape& aS3,
119 const TopoDS_Shape& aS4)
121 Standard_Integer anId1, anId2, anId3, anId4;
123 anId1=aS1.HashCode(myUpper);
124 anId2=aS2.HashCode(myUpper);
125 anId3=aS3.HashCode(myUpper);
126 anId4=aS4.HashCode(myUpper);
133 mySum=anId1+anId2+anId3+anId4;
136 //=======================================================================
139 //=======================================================================
140 void GEOMAlgo_PassKey::SetIds(const TopTools_ListOfShape& aLS)
142 Standard_Integer aNb, i, anId;
143 TopTools_ListIteratorOfListOfShape aIt;
146 if (aNb<1 || aNb > myNbMax) {
154 for (; aIt.More(); aIt.Next(), ++i) {
155 const TopoDS_Shape& aS=aIt.Value();
156 anId=aS.HashCode(myUpper);
163 //=======================================================================
166 //=======================================================================
167 Standard_Integer GEOMAlgo_PassKey::NbMax()const
171 //=======================================================================
174 //=======================================================================
175 void GEOMAlgo_PassKey::Compute()
177 SortShell(myNbIds, myIds+myNbMax-myNbIds);
179 //=======================================================================
182 //=======================================================================
183 Standard_Boolean GEOMAlgo_PassKey::IsEqual(const GEOMAlgo_PassKey& anOther) const
185 Standard_Integer iIsEqual;
186 Standard_Boolean bIsEqual;
188 iIsEqual=memcmp(myIds, anOther.myIds, sizeof(myIds));
189 bIsEqual=Standard_False;
195 //=======================================================================
198 //=======================================================================
199 Standard_Address GEOMAlgo_PassKey::Key()const
201 return (Standard_Address)myIds;
203 //=======================================================================
204 //function : HashCode
206 //=======================================================================
207 Standard_Integer GEOMAlgo_PassKey::HashCode(const Standard_Integer Upper) const
209 return (mySum % Upper);
211 //=======================================================================
214 //=======================================================================
215 void GEOMAlgo_PassKey::Dump()const
219 printf(" PassKey: {");
220 for (i=0; i<myNbMax; ++i) {
221 printf(" %d", myIds[i]);
225 //=======================================================================
226 // function: SortShell
228 //=======================================================================
229 void SortShell(const int n, int* a)
231 int x, nd, i, j, l, d=1;
241 for (i=0; i<nd; ++i) {
250 if (j > -1) goto m30;
252 }//for (i=0; i<nd; ++i)