Refactor TCollection to use NCollection_Primes and remove obsolete TCollection.cxx
New prime declaration now will be more clear to use.
NCollection_Mat3.hxx
NCollection_Mat4.hxx
NCollection_OccAllocator.hxx
+NCollection_Primes.cxx
+NCollection_Primes.hxx
NCollection_Sequence.hxx
NCollection_Shared.hxx
NCollection_SparseArray.hxx
// Purpose: Implementation of the BaseMap class
#include <NCollection_BaseMap.hxx>
-#include <TCollection.hxx>
+#include <NCollection_Primes.hxx>
//=======================================================================
//function : BeginResize
Standard::Allocate((N+1)*sizeof(NCollection_ListNode *));
}
else
- data2 = NULL;
+ data2 = nullptr;
return Standard_True;
}
myData2 = data2;
}
-
//=======================================================================
//function : Destroy
//purpose :
{
memset(myData2, 0, (aNbBuckets + 1) * sizeof(NCollection_ListNode*));
}
+ mySize = 0;
}
-
- mySize = 0;
if (doReleaseMemory)
{
if (myData1)
Standard::Free(myData1);
if (myData2)
Standard::Free(myData2);
- myData1 = myData2 = NULL;
+ myData1 = myData2 = nullptr;
}
}
Standard_Integer NCollection_BaseMap::NextPrimeForMap
(const Standard_Integer N) const
{
- return TCollection::NextPrimeForMap ( N );
+ return NCollection_Primes::NextPrimeForMap ( N );
}
-
//! Empty constructor
Iterator (void) :
myNbBuckets (0),
- myBuckets (NULL),
+ myBuckets (nullptr),
myBucket (0),
- myNode (NULL) {}
+ myNode (nullptr) {}
//! Constructor
Iterator (const NCollection_BaseMap& theMap) :
myNbBuckets (theMap.myNbBuckets),
myBuckets (theMap.myData1),
myBucket (-1),
- myNode (NULL)
+ myNode (nullptr)
{
if (!myBuckets)
myNbBuckets = -1;
myNbBuckets = theMap.myNbBuckets;
myBuckets = theMap.myData1;
myBucket = -1;
- myNode = NULL;
+ myNode = nullptr;
if (!myBuckets)
myNbBuckets = -1;
PNext();
void Reset (void)
{
myBucket = -1;
- myNode = NULL;
+ myNode = nullptr;
PNext();
}
protected:
//! PMore
Standard_Boolean PMore (void) const
- { return (myNode != NULL); }
+ { return (myNode != nullptr); }
//! PNext
void PNext (void)
const Standard_Boolean single,
const Handle(NCollection_BaseAllocator)& theAllocator) :
myAllocator(theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator),
- myData1(NULL),
- myData2(NULL),
+ myData1(nullptr),
+ myData2(nullptr),
myNbBuckets(NbBuckets),
mySize(0),
isDouble(!single)
#include <NCollection_BasePointerVector.hxx>
-#include <TCollection.hxx>
#include <cstring>
//=======================================================================
--- /dev/null
+// Copyright (c) 2024 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <NCollection_Primes.hxx>
+
+#include <Standard_OutOfRange.hxx>
+
+#include <algorithm>
+#include <array>
+
+namespace
+{
+ // The array of prime numbers used as consecutive steps for
+ // size of array of buckets in the map.
+ // The prime numbers are used for array size with the hope that this will
+ // lead to less probability of having the same hash codes for
+ // different map items (note that all hash codes are modulo that size).
+ // The value of each next step is chosen to be ~2 times greater than previous.
+ // Though this could be thought as too much, actually the amount of
+ // memory overhead in that case is only ~15% as compared with total size of
+ // all auxiliary data structures (each map node takes ~24 bytes),
+ // and this proves to pay off in performance (see OCC13189).
+ constexpr std::array<int, 24> THE_PRIME_VECTOR = {101, 1009, 2003, 5003, 10007, 20011,
+ 37003, 57037, 65003, 100019, 209953, 472393,
+ 995329, 2359297, 4478977, 9437185, 17915905, 35831809,
+ 71663617, 150994945, 301989889, 573308929, 1019215873, 2038431745};
+}
+
+int NCollection_Primes::NextPrimeForMap(const int theN)
+{
+ auto aResult = std::lower_bound(THE_PRIME_VECTOR.begin(), THE_PRIME_VECTOR.end(), theN + 1);
+ if (aResult == THE_PRIME_VECTOR.end())
+ {
+ throw Standard_OutOfRange("NCollection_Primes::NextPrimeForMap() - requested too big size");
+ }
+ return *aResult;
+}
--- /dev/null
+// Copyright (c) 2024 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _NCollection_Primes_HeaderFile
+#define _NCollection_Primes_HeaderFile
+
+#include <Standard_Macro.hxx>
+
+//! Namespace provides a collection of prime numbers.
+//!
+//! This namespace is used to store a collection of prime numbers that are used as
+//! consecutive steps for the size of an array of buckets in a map. The prime
+//! numbers are chosen to minimize the probability of having the same hash codes
+//! for different map items. The namespace also provides a method to find the next
+//! prime number greater than or equal to a given number.
+//!
+//! The following are Pierpont primes, prime numbers of the form 2^u * 3^v + 1:
+//! 101, 1009, 2003, 5003, 10007, 20011, 37003, 57037, 65003, 100019, 209953, 472393,
+//! 995329, 2359297, 4478977, 9437185, 17915905, 35831809, 71663617, 150994945,
+//! 301989889, 573308929, 1019215873, 2038431745
+namespace NCollection_Primes
+{
+ //! Returns the next prime number greater than or equal to theN.
+ Standard_EXPORT int NextPrimeForMap(const int theN);
+};
+
+#endif // _NCollection_Primes_HeaderFile
\ No newline at end of file
#include <TColStd_PackedMapOfInteger.hxx>
#include <NCollection_Array1.hxx>
-#include <TCollection.hxx>
+#include <NCollection_Primes.hxx>
namespace
{
void TColStd_PackedMapOfInteger::ReSize (const Standard_Integer theNbBuckets)
{
- Standard_Integer aNewBuck = TCollection::NextPrimeForMap (theNbBuckets);
+ Standard_Integer aNewBuck = NCollection_Primes::NextPrimeForMap (theNbBuckets);
if (aNewBuck <= myNbBuckets)
{
if (!IsEmpty())
-TCollection.cxx
TCollection.hxx
TCollection_AsciiString.cxx
TCollection_AsciiString.hxx
+++ /dev/null
-// Created on: 1993-01-14
-// Created by: Remi LEQUETTE
-// Copyright (c) 1993-1999 Matra Datavision
-// Copyright (c) 1999-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <TCollection.hxx>
-
-#include <Standard_OutOfRange.hxx>
-
-// The array of prime numbers used as consecutive steps for
-// size of array of buckets in the map.
-// The prime numbers are used for array size with the hope that this will
-// lead to less probability of having the same hash codes for
-// different map items (note that all hash codes are modulo that size).
-// The value of each next step is chosen to be ~2 times greater than previous.
-// Though this could be thought as too much, actually the amount of
-// memory overhead in that case is only ~15% as compared with total size of
-// all auxiliary data structures (each map node takes ~24 bytes),
-// and this proves to pay off in performance (see OCC13189).
-#define THE_NB_PRIMES 24
-static const Standard_Integer THE_TCollection_Primes[THE_NB_PRIMES] =
-{
- 101,
- 1009,
- 2003,
- 5003,
- 10007,
- 20011,
- 37003,
- 57037,
- 65003,
- 100019,
- 209953, // The following are Pierpont primes [List of prime numbers]
- 472393,
- 995329,
- 2359297,
- 4478977,
- 9437185,
- 17915905,
- 35831809,
- 71663617,
- 150994945,
- 301989889,
- 573308929,
- 1019215873,
- 2038431745
-};
-
-// =======================================================================
-// function : NextPrimeForMap
-// purpose :
-// =======================================================================
-Standard_Integer TCollection::NextPrimeForMap(const Standard_Integer N)
-{
- for (Standard_Integer aPrimeIter = 0; aPrimeIter < THE_NB_PRIMES; ++aPrimeIter)
- {
- if (THE_TCollection_Primes[aPrimeIter] > N)
- {
- return THE_TCollection_Primes[aPrimeIter];
- }
- }
- throw Standard_OutOfRange ("TCollection::NextPrimeForMap() - requested too big size");
-}
#ifndef _TCollection_HeaderFile
#define _TCollection_HeaderFile
+#include <NCollection_Primes.hxx>
+
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
//! The package <TCollection> provides the services for the
//! transient basic data structures.
-class TCollection
+class Standard_DEPRECATED("Deprecated since OCCT 7.9, NCollection_Primes should be used instead of TCollection") TCollection
{
public:
//! around 1 000 000). This is not a limit of the number of
//! items but a limit in the number of buckets. i.e.
//! there will be more collisions in the map.
- Standard_EXPORT static Standard_Integer NextPrimeForMap (const Standard_Integer I);
+ static Standard_Integer NextPrimeForMap (const Standard_Integer I)
+ {
+ return NCollection_Primes::NextPrimeForMap(I);
+ }
};