1 // Created on: 2002-04-18
2 // Created by: Alexander KARTOMIN (akm)
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // Purpose: Implementation of the BaseMap class
18 #include <NCollection_BaseMap.hxx>
19 #include <TCollection.hxx>
21 //=======================================================================
22 //function : BeginResize
24 //=======================================================================
26 Standard_Boolean NCollection_BaseMap::BeginResize
27 (const Standard_Integer NbBuckets,
29 NCollection_ListNode**& data1,
30 NCollection_ListNode**& data2) const
32 N = NextPrimeForMap(NbBuckets);
33 if (N <= myNbBuckets) {
37 return Standard_False;
39 data1 = (NCollection_ListNode **)
40 myAllocator->Allocate((N+1)*sizeof(NCollection_ListNode *));
41 memset(data1, 0, (N+1)*sizeof(NCollection_ListNode *));
44 data2 = (NCollection_ListNode **)
45 myAllocator->Allocate((N+1)*sizeof(NCollection_ListNode *));
46 memset(data2, 0, (N+1)*sizeof(NCollection_ListNode *));
53 //=======================================================================
54 //function : EndResize
56 //=======================================================================
58 void NCollection_BaseMap::EndResize
59 (const Standard_Integer theNbBuckets,
60 const Standard_Integer N,
61 NCollection_ListNode** data1,
62 NCollection_ListNode** data2)
64 (void )theNbBuckets; // obsolete parameter
66 myAllocator->Free(myData1);
68 myAllocator->Free(myData2);
75 //=======================================================================
78 //=======================================================================
80 void NCollection_BaseMap::Destroy (NCollection_DelMapNode fDel,
81 Standard_Boolean doReleaseMemory)
86 NCollection_ListNode** data = (NCollection_ListNode**) myData1;
87 NCollection_ListNode *p,*q;
88 for (i = 0; i <= NbBuckets(); i++)
95 q = (NCollection_ListNode*)p->Next();
96 fDel (p, myAllocator);
108 myAllocator->Free(myData1);
109 if (isDouble && myData2)
110 myAllocator->Free(myData2);
111 myData1 = myData2 = NULL;
116 //=======================================================================
117 //function : Statistics
119 //=======================================================================
121 void NCollection_BaseMap::Statistics(Standard_OStream& S) const
123 S <<"\nMap Statistics\n---------------\n\n";
124 S <<"This Map has "<<myNbBuckets<<" Buckets and "<<mySize<<" Keys\n\n";
126 if (mySize == 0) return;
128 // compute statistics on 1
129 Standard_Integer * sizes = new Standard_Integer [mySize+1];
130 Standard_Integer i,l,nb;
131 NCollection_ListNode* p;
132 NCollection_ListNode** data;
134 S << "\nStatistics for the first Key\n";
135 for (i = 0; i <= mySize; i++) sizes[i] = 0;
136 data = (NCollection_ListNode **) myData1;
138 for (i = 0; i <= myNbBuckets; i++)
153 for (i = 0; i<= mySize; i++)
158 S << setw(5) << sizes[i] <<" buckets of size "<<i<<"\n";
162 Standard_Real mean = ((Standard_Real) l) / ((Standard_Real) nb);
163 S<<"\n\nMean of length : "<<mean<<"\n";
168 //=======================================================================
169 //function : NextPrimeForMap
171 //=======================================================================
173 Standard_Integer NCollection_BaseMap::NextPrimeForMap
174 (const Standard_Integer N) const
176 return TCollection::NextPrimeForMap ( N );