1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: GEOMAlgo_PassKey.cxx
22 // Author: Peter KURNEV
26 #include <GEOMAlgo_PassKey.ixx>
30 #include <TColStd_ListIteratorOfListOfInteger.hxx>
33 #pragma warning( disable : 4101)
37 void SortShell(const int n, int* a);
39 Standard_Integer NormalizedId(const Standard_Integer aId,
40 const Standard_Integer aDiv);
42 //=======================================================================
45 //=======================================================================
46 GEOMAlgo_PassKey::GEOMAlgo_PassKey()
50 //=======================================================================
53 //=======================================================================
54 GEOMAlgo_PassKey& GEOMAlgo_PassKey::Assign(const GEOMAlgo_PassKey& anOther)
56 myNbIds=anOther.myNbIds;
57 myNbMax=anOther.myNbMax;
59 memcpy(myIds, anOther.myIds, sizeof(myIds));
62 //=======================================================================
65 //=======================================================================
66 void GEOMAlgo_PassKey::Clear()
73 for (i=0; i<myNbMax; ++i) {
77 //=======================================================================
80 //=======================================================================
81 void GEOMAlgo_PassKey::SetIds(const Standard_Integer anId1)
85 myIds[myNbMax-1]=anId1;
88 //=======================================================================
91 //=======================================================================
92 void GEOMAlgo_PassKey::SetIds(const Standard_Integer anId1,
93 const Standard_Integer anId2)
95 Standard_Integer aIdN1, aIdN2;
98 aIdN1=NormalizedId(anId1, myNbIds);
99 aIdN2=NormalizedId(anId2, myNbIds);
103 myIds[myNbMax-2]=anId1;
104 myIds[myNbMax-1]=anId2;
107 myIds[myNbMax-2]=anId2;
108 myIds[myNbMax-1]=anId1;
111 //=======================================================================
114 //=======================================================================
115 void GEOMAlgo_PassKey::SetIds(const Standard_Integer anId1,
116 const Standard_Integer anId2,
117 const Standard_Integer anId3)
119 Standard_Integer aIdN1, aIdN2, aIdN3;
122 aIdN1=NormalizedId(anId1, myNbIds);
123 aIdN2=NormalizedId(anId2, myNbIds);
124 aIdN3=NormalizedId(anId3, myNbIds);
125 mySum=aIdN1+aIdN2+aIdN3;
127 myIds[myNbMax-3]=anId1;
128 myIds[myNbMax-2]=anId2;
129 myIds[myNbMax-1]=anId3;
133 //=======================================================================
136 //=======================================================================
137 void GEOMAlgo_PassKey::SetIds(const Standard_Integer anId1,
138 const Standard_Integer anId2,
139 const Standard_Integer anId3,
140 const Standard_Integer anId4)
142 Standard_Integer aIdN1, aIdN2, aIdN3, aIdN4;
145 aIdN1=NormalizedId(anId1, myNbIds);
146 aIdN2=NormalizedId(anId2, myNbIds);
147 aIdN3=NormalizedId(anId3, myNbIds);
148 aIdN4=NormalizedId(anId4, myNbIds);
149 mySum=aIdN1+aIdN2+aIdN3+aIdN4;
151 myIds[myNbMax-4]=anId1;
152 myIds[myNbMax-3]=anId2;
153 myIds[myNbMax-2]=anId3;
154 myIds[myNbMax-1]=anId4;
158 //=======================================================================
161 //=======================================================================
162 void GEOMAlgo_PassKey::SetIds(const TColStd_ListOfInteger& aLI)
164 Standard_Integer aNb, i, anId, aIdN;
165 TColStd_ListIteratorOfListOfInteger aIt;
168 if (!aNb || aNb > myNbMax) {
176 for (; aIt.More(); aIt.Next(), ++i) {
179 aIdN=NormalizedId(anId, myNbIds);
185 //=======================================================================
188 //=======================================================================
189 Standard_Integer GEOMAlgo_PassKey::Id(const Standard_Integer aIndex)const
191 if (aIndex < 0 || aIndex >= myNbMax) {
194 return myIds[aIndex];
196 //=======================================================================
199 //=======================================================================
200 Standard_Integer GEOMAlgo_PassKey::NbMax()const
204 //=======================================================================
207 //=======================================================================
208 void GEOMAlgo_PassKey::Compute()
210 SortShell(myNbIds, myIds+myNbMax-myNbIds);
212 //=======================================================================
215 //=======================================================================
216 Standard_Boolean GEOMAlgo_PassKey::IsEqual(const GEOMAlgo_PassKey& anOther) const
218 Standard_Integer iIsEqual;
219 Standard_Boolean bIsEqual;
221 iIsEqual=memcmp(myIds, anOther.myIds, sizeof(myIds));
222 bIsEqual=Standard_False;
228 //=======================================================================
231 //=======================================================================
232 Standard_Address GEOMAlgo_PassKey::Key()const
234 return (Standard_Address)myIds;
236 //=======================================================================
237 //function : HashCode
239 //=======================================================================
240 Standard_Integer GEOMAlgo_PassKey::HashCode(const Standard_Integer Upper) const
242 //return (mySum % Upper);
243 return ::HashCode(mySum, Upper);
245 //=======================================================================
248 //=======================================================================
249 void GEOMAlgo_PassKey::Dump()const
253 printf(" PassKey: {");
254 for (i=0; i<myNbMax; ++i) {
255 printf(" %d", myIds[i]);
259 //=======================================================================
260 // function: NormalizedId
262 //=======================================================================
263 Standard_Integer NormalizedId(const Standard_Integer aId,
264 const Standard_Integer aDiv)
266 Standard_Integer aMax, aTresh, aIdRet;
269 aMax=::IntegerLast();
276 //=======================================================================
277 // function: SortShell
279 //=======================================================================
280 void SortShell(const int n, int* a)
282 int x, nd, i, j, l, d=1;
292 for (i=0; i<nd; ++i) {
301 if (j > -1) goto m30;
303 }//for (i=0; i<nd; ++i)