6 #ifndef SMESH_IndexedMap_HeaderFile 7 #define SMESH_IndexedMap_HeaderFile 9 #include <NCollection_BaseCollection.hxx> 10 #include <NCollection_BaseMap.hxx> 11 #include <NCollection_TListNode.hxx> 12 #include <Standard_NoSuchObject.hxx> 13 #include <Standard_ImmutableObject.hxx> 15 #if !defined No_Exception && !defined No_Standard_OutOfRange 16 #include <Standard_OutOfRange.hxx> 21 #pragma warning (push) 22 #pragma warning (disable:4291) 46 const Standard_Integer theKey2,
47 NCollection_ListNode* theNext1,
48 NCollection_ListNode* theNext2) :
56 {
return this->ChangeValue(); }
58 const Standard_Integer&
Key2 (
void)
65 static void delNode (NCollection_ListNode * theNode,
66 Handle(NCollection_BaseAllocator)& theAl)
92 virtual Standard_Boolean
More(
void)
const 93 {
return (myIndex <= myMap->Extent()); }
98 virtual const TheKeyType&
Value(
void)
const 100 #if !defined No_Exception && !defined No_Standard_NoSuchObject 102 Standard_NoSuchObject::Raise(
"SMESH_IndexedMap::Iterator::Value");
104 return myMap->FindKey(myIndex);
109 Standard_ImmutableObject::Raise (
"impossible to ChangeValue");
110 return * (TheKeyType *) NULL;
114 void*
operator new(
size_t theSize,
115 const Handle(NCollection_BaseAllocator)& theAllocator)
116 {
return theAllocator->Allocate(theSize); }
128 const Handle(NCollection_BaseAllocator)& theAllocator=0L) :
136 { *
this = theOther; }
141 if (
this == &theOther)
146 theOther.CreateIterator();
147 for (; anIter.More(); anIter.Next())
154 if (
this == &theOther)
158 ReSize (theOther.NbBuckets());
159 Standard_Integer i, iLength=theOther.Extent();
160 for (i=1; i<=iLength; i++)
162 TheKeyType aKey1 = theOther(i);
163 Standard_Integer iK1 =
HashCode (aKey1, NbBuckets());
164 Standard_Integer iK2 =
HashCode (i, NbBuckets());
168 myData1[iK1] = pNode;
169 myData2[iK2] = pNode;
180 Standard_Integer newBuck;
181 if (BeginResize (N, newBuck,
182 (NCollection_ListNode**&)ppNewData1,
183 (NCollection_ListNode**&)ppNewData2,
189 Standard_Integer i, iK1, iK2;
190 for (i = 0; i <= NbBuckets(); i++)
199 p->Next() = ppNewData1[iK1];
204 p->
Next2() = ppNewData2[iK2];
213 (NCollection_ListNode**&)ppNewData1,
214 (NCollection_ListNode**&)ppNewData2,
220 Standard_Integer
Add (
const TheKeyType& theKey1)
224 Standard_Integer iK1 =
HashCode (theKey1, NbBuckets());
230 return pNode->
Key2();
234 Standard_Integer iK2 =
HashCode(Extent(),NbBuckets());
235 pNode =
new (this->myAllocator)
IndexedMapNode (theKey1, Extent(),
236 myData1[iK1], myData2[iK2]);
237 myData1[iK1] = pNode;
238 myData2[iK2] = pNode;
243 Standard_Boolean
Contains (
const TheKeyType& theKey1)
const 246 return Standard_False;
247 Standard_Integer iK1 =
HashCode (theKey1, NbBuckets());
253 return Standard_True;
256 return Standard_False;
261 const TheKeyType& theKey1)
263 #if !defined No_Exception && !defined No_Standard_OutOfRange 264 if (theIndex < 1 || theIndex > Extent())
265 Standard_OutOfRange::Raise (
"SMESH_IndexedMap::Substitute");
269 Standard_Integer iK1 =
HashCode (theKey1, NbBuckets());
274 Standard_DomainError::Raise(
"SMESH_IndexedMap::Substitute");
279 Standard_Integer iK2 =
HashCode (theIndex, NbBuckets());
283 if (p->
Key2() == theIndex)
289 Standard_Integer iK =
HashCode (p->
Key1(), NbBuckets());
295 while (q->Next() != p)
297 q->Next() = p->Next();
302 p->Next() = myData1[iK1];
309 #if !defined No_Exception && !defined No_Standard_OutOfRange 311 Standard_OutOfRange::Raise (
"SMESH_IndexedMap::RemoveLast");
315 Standard_Integer iK2 =
HashCode (Extent(), NbBuckets());
320 if (p->
Key2() == Extent())
331 Standard_Integer iK1 =
HashCode (p->
Key1(), NbBuckets());
337 while (q->Next() != p)
339 q->Next() = p->Next();
341 p->~IndexedMapNode();
342 this->myAllocator->Free(p);
347 const TheKeyType&
FindKey (
const Standard_Integer theKey2)
const 349 #if !defined No_Exception && !defined No_Standard_OutOfRange 350 if (theKey2 < 1 || theKey2 > Extent())
351 Standard_OutOfRange::Raise (
"SMESH_IndexedMap::FindKey");
357 if (pNode2->
Key2() == theKey2)
358 return pNode2->
Key1();
361 Standard_NoSuchObject::Raise(
"SMESH_IndexedMap::FindKey");
362 return pNode2->
Key1();
366 const TheKeyType&
operator() (
const Standard_Integer theKey2)
const 370 Standard_Integer
FindIndex(
const TheKeyType& theKey1)
const 372 if (IsEmpty())
return 0;
378 return pNode1->
Key2();
386 void Clear(
const Standard_Boolean doReleaseMemory = Standard_True)
390 void Clear (
const Handle(NCollection_BaseAllocator)& theAllocator)
393 this->myAllocator = ( ! theAllocator.IsNull() ? theAllocator :
394 NCollection_BaseAllocator::CommonBaseAllocator() );
402 virtual Standard_Integer
Size(
void)
const 411 {
return *(
new (this->IterAllocator())
Iterator(*
this)); }
416 #pragma warning (pop) Standard_Integer FindIndex(const TheKeyType &theKey1) const
FindIndex.
Standard_Integer HashCode(SMDS_MeshElementPtr theElem, const Standard_Integer theUpper)
class Handle(MeshVS_DataSource3D)
virtual Standard_Boolean More(void) const
Query if the end of collection is reached by iterator.
virtual void Next(void)
Make a step along the collection.
Purpose: An indexed map is used to store keys and to bind an index to them.
Iterator(const SMESH_IndexedMap &theMap)
Constructor.
void ReSize(const Standard_Integer N)
ReSize.
TheKeyType & Key1(void)
Key1.
virtual void Assign(const NCollection_BaseCollection< TheKeyType > &theOther)
Assign another collection.
void Substitute(const Standard_Integer theIndex, const TheKeyType &theKey1)
Substitute.
const Standard_Integer & Key2(void)
Key2.
Iterator(void)
Empty constructor.
virtual TYPENAME NCollection_BaseCollection< TheKeyType >::Iterator & CreateIterator(void) const
Creates Iterator for use on BaseCollection.
void Clear(const Handle(NCollection_BaseAllocator)&theAllocator)
Clear data and reset allocator.
void RemoveLast(void)
RemoveLast.
IndexedMapNode(const TheKeyType &theKey1, const Standard_Integer theKey2, NCollection_ListNode *theNext1, NCollection_ListNode *theNext2)
Constructor with 'Next'.
void Clear(const Standard_Boolean doReleaseMemory=Standard_True)
Clear data. If doReleaseMemory is false then the table of buckets is not released and will be reused...
const TheKeyType & FindKey(const Standard_Integer theKey2) const
FindKey.
virtual Standard_Integer Size(void) const
Size.
Standard_Boolean IsEqual(SMDS_MeshElementPtr theOne, SMDS_MeshElementPtr theTwo)
SMESH_IndexedMap(const SMESH_IndexedMap &theOther)
Copy constructor.
SMESH_IndexedMap & operator=(const SMESH_IndexedMap &theOther)
= another map
IndexedMapNode *& Next2(void)
Next2.
Standard_Boolean Contains(const TheKeyType &theKey1) const
Contains.
static void delNode(NCollection_ListNode *theNode, Handle(NCollection_BaseAllocator)&theAl)
Static deleter to be passed to BaseList.
virtual TheKeyType & ChangeValue(void) const
Value change access denied - use Substitute.
SMESH_IndexedMap(const Standard_Integer NbBuckets=1, const Handle(NCollection_BaseAllocator)&theAllocator=0L)
Constructor.
const TheKeyType & operator()(const Standard_Integer theKey2) const
operator ()
virtual const TheKeyType & Value(void) const
Value access.
Standard_Integer Add(const TheKeyType &theKey1)
Add.
~SMESH_IndexedMap(void)
Destructor.