1616// Purpose: Implementation of the BaseMap class
1717
1818#include < NCollection_BaseMap.hxx>
19- #include < TCollection .hxx>
19+ #include < NCollection_Primes .hxx>
2020
2121// =======================================================================
2222// function : BeginResize
@@ -30,7 +30,7 @@ Standard_Boolean NCollection_BaseMap::BeginResize
3030 NCollection_ListNode**& data2) const
3131{
3232 // get next size for the buckets array
33- N = NextPrimeForMap (NbBuckets);
33+ N = NCollection_Primes:: NextPrimeForMap (NbBuckets);
3434 if (N <= myNbBuckets)
3535 {
3636 if (!myData1)
@@ -46,7 +46,7 @@ Standard_Boolean NCollection_BaseMap::BeginResize
4646 Standard::Allocate ((N+1 )*sizeof (NCollection_ListNode *));
4747 }
4848 else
49- data2 = NULL ;
49+ data2 = nullptr ;
5050 return Standard_True;
5151}
5252
@@ -71,14 +71,46 @@ void NCollection_BaseMap::EndResize
7171 myData2 = data2;
7272}
7373
74-
7574// =======================================================================
76- // function : Destroy
77- // purpose :
75+ // function : Reallocate
76+ // purpose :
7877// =======================================================================
78+ Standard_Boolean NCollection_BaseMap::Reallocate (const Standard_Integer theNbBuckets)
79+ {
80+ // get next size for the buckets array
81+ Standard_Integer aNewBuckets = NCollection_Primes::NextPrimeForMap (theNbBuckets);
82+ if (aNewBuckets <= myNbBuckets)
83+ {
84+ if (!myData1)
85+ {
86+ aNewBuckets = myNbBuckets;
87+ }
88+ else
89+ {
90+ return Standard_False;
91+ }
92+ }
93+ myNbBuckets = aNewBuckets;
94+ myData1 = (NCollection_ListNode**)Standard::Reallocate (myData1, (theNbBuckets + 1 ) * sizeof (NCollection_ListNode*));
95+ memset (myData1, 0 , aNewBuckets * sizeof (NCollection_ListNode*));
96+ if (isDouble)
97+ {
98+ myData2 = (NCollection_ListNode**)Standard::Reallocate (myData2, (theNbBuckets + 1 ) * sizeof (NCollection_ListNode*));
99+ memset (myData2, 0 , aNewBuckets * sizeof (NCollection_ListNode*));
100+ }
101+ else
102+ {
103+ myData2 = nullptr ;
104+ }
105+ return Standard_True;
106+ }
107+
108+ // =======================================================================
109+ // function : Destroy
110+ // purpose :
111+ // =======================================================================
79112
80- void NCollection_BaseMap::Destroy (NCollection_DelMapNode fDel ,
81- Standard_Boolean doReleaseMemory)
113+ void NCollection_BaseMap::Destroy (NCollection_DelMapNode fDel , Standard_Boolean doReleaseMemory)
82114{
83115 if (!IsEmpty ())
84116 {
@@ -94,23 +126,22 @@ void NCollection_BaseMap::Destroy (NCollection_DelMapNode fDel,
94126 fDel (aCur, myAllocator);
95127 aCur = aNext;
96128 }
97- myData1[anInd] = nullptr ;
129+ myData1[anInd] = nullptr ;
98130 }
99131 }
100132 if (myData2)
101133 {
102134 memset (myData2, 0 , (aNbBuckets + 1 ) * sizeof (NCollection_ListNode*));
103135 }
136+ mySize = 0 ;
104137 }
105-
106- mySize = 0 ;
107138 if (doReleaseMemory)
108139 {
109140 if (myData1)
110141 Standard::Free (myData1);
111142 if (myData2)
112143 Standard::Free (myData2);
113- myData1 = myData2 = NULL ;
144+ myData1 = myData2 = nullptr ;
114145 }
115146}
116147
@@ -166,15 +197,3 @@ void NCollection_BaseMap::Statistics(Standard_OStream& S) const
166197
167198 delete [] sizes;
168199}
169-
170- // =======================================================================
171- // function : NextPrimeForMap
172- // purpose :
173- // =======================================================================
174-
175- Standard_Integer NCollection_BaseMap::NextPrimeForMap
176- (const Standard_Integer N) const
177- {
178- return TCollection::NextPrimeForMap ( N );
179- }
180-
0 commit comments