1 // File: GEOMAlgo_PassKey.cxx
3 // Author: Peter KURNEV
7 #include <GEOMAlgo_PassKey.ixx>
11 #include <TColStd_ListIteratorOfListOfInteger.hxx>
14 #pragma warning( disable : 4101)
18 void SortShell(const int n, int* a);
20 Standard_Integer NormalizedId(const Standard_Integer aId,
21 const Standard_Integer aDiv);
23 //=======================================================================
26 //=======================================================================
27 GEOMAlgo_PassKey::GEOMAlgo_PassKey()
31 //=======================================================================
34 //=======================================================================
35 GEOMAlgo_PassKey& GEOMAlgo_PassKey::Assign(const GEOMAlgo_PassKey& anOther)
37 myNbIds=anOther.myNbIds;
38 myNbMax=anOther.myNbMax;
40 memcpy(myIds, anOther.myIds, sizeof(myIds));
43 //=======================================================================
46 //=======================================================================
47 void GEOMAlgo_PassKey::Clear()
54 for (i=0; i<myNbMax; ++i) {
58 //=======================================================================
61 //=======================================================================
62 void GEOMAlgo_PassKey::SetIds(const Standard_Integer anId1)
66 myIds[myNbMax-1]=anId1;
69 //=======================================================================
72 //=======================================================================
73 void GEOMAlgo_PassKey::SetIds(const Standard_Integer anId1,
74 const Standard_Integer anId2)
76 Standard_Integer aIdN1, aIdN2;
79 aIdN1=NormalizedId(anId1, myNbIds);
80 aIdN2=NormalizedId(anId2, myNbIds);
84 myIds[myNbMax-2]=anId1;
85 myIds[myNbMax-1]=anId2;
88 myIds[myNbMax-2]=anId2;
89 myIds[myNbMax-1]=anId1;
92 //=======================================================================
95 //=======================================================================
96 void GEOMAlgo_PassKey::SetIds(const Standard_Integer anId1,
97 const Standard_Integer anId2,
98 const Standard_Integer anId3)
100 Standard_Integer aIdN1, aIdN2, aIdN3;
103 aIdN1=NormalizedId(anId1, myNbIds);
104 aIdN2=NormalizedId(anId2, myNbIds);
105 aIdN3=NormalizedId(anId3, myNbIds);
106 mySum=aIdN1+aIdN2+aIdN3;
108 myIds[myNbMax-3]=anId1;
109 myIds[myNbMax-2]=anId2;
110 myIds[myNbMax-1]=anId3;
114 //=======================================================================
117 //=======================================================================
118 void GEOMAlgo_PassKey::SetIds(const Standard_Integer anId1,
119 const Standard_Integer anId2,
120 const Standard_Integer anId3,
121 const Standard_Integer anId4)
123 Standard_Integer aIdN1, aIdN2, aIdN3, aIdN4;
126 aIdN1=NormalizedId(anId1, myNbIds);
127 aIdN2=NormalizedId(anId2, myNbIds);
128 aIdN3=NormalizedId(anId3, myNbIds);
129 aIdN4=NormalizedId(anId4, myNbIds);
130 mySum=aIdN1+aIdN2+aIdN3+aIdN4;
132 myIds[myNbMax-4]=anId1;
133 myIds[myNbMax-3]=anId2;
134 myIds[myNbMax-2]=anId3;
135 myIds[myNbMax-1]=anId4;
139 //=======================================================================
142 //=======================================================================
143 void GEOMAlgo_PassKey::SetIds(const TColStd_ListOfInteger& aLI)
145 Standard_Integer aNb, i, anId, aIdN;
146 TColStd_ListIteratorOfListOfInteger aIt;
149 if (!aNb || aNb > myNbMax) {
157 for (; aIt.More(); aIt.Next(), ++i) {
160 aIdN=NormalizedId(anId, myNbIds);
166 //=======================================================================
169 //=======================================================================
170 Standard_Integer GEOMAlgo_PassKey::Id(const Standard_Integer aIndex)const
172 if (aIndex < 0 || aIndex >= myNbMax) {
175 return myIds[aIndex];
177 //=======================================================================
180 //=======================================================================
181 Standard_Integer GEOMAlgo_PassKey::NbMax()const
185 //=======================================================================
188 //=======================================================================
189 void GEOMAlgo_PassKey::Compute()
191 SortShell(myNbIds, myIds+myNbMax-myNbIds);
193 //=======================================================================
196 //=======================================================================
197 Standard_Boolean GEOMAlgo_PassKey::IsEqual(const GEOMAlgo_PassKey& anOther) const
199 Standard_Integer iIsEqual;
200 Standard_Boolean bIsEqual;
202 iIsEqual=memcmp(myIds, anOther.myIds, sizeof(myIds));
203 bIsEqual=Standard_False;
209 //=======================================================================
212 //=======================================================================
213 Standard_Address GEOMAlgo_PassKey::Key()const
215 return (Standard_Address)myIds;
217 //=======================================================================
218 //function : HashCode
220 //=======================================================================
221 Standard_Integer GEOMAlgo_PassKey::HashCode(const Standard_Integer Upper) const
223 //return (mySum % Upper);
224 return ::HashCode(mySum, Upper);
226 //=======================================================================
229 //=======================================================================
230 void GEOMAlgo_PassKey::Dump()const
234 printf(" PassKey: {");
235 for (i=0; i<myNbMax; ++i) {
236 printf(" %d", myIds[i]);
240 //=======================================================================
241 // function: NormalizedId
243 //=======================================================================
244 Standard_Integer NormalizedId(const Standard_Integer aId,
245 const Standard_Integer aDiv)
247 Standard_Integer aMax, aTresh, aIdRet;
250 aMax=::IntegerLast();
257 //=======================================================================
258 // function: SortShell
260 //=======================================================================
261 void SortShell(const int n, int* a)
263 int x, nd, i, j, l, d=1;
273 for (i=0; i<nd; ++i) {
282 if (j > -1) goto m30;
284 }//for (i=0; i<nd; ++i)