1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0030550: Coding - Integer overflow in Standard_CString HashCodes

0030551: Foundation Classes - Integer overflow in NCollection_CellFilter HashCode

Signed integers are not used in hash code functions now to prevent undefined behavior on left shift operations with signed integers.
A possibility of negative values of hash codes is eliminated.
INT_MAX → IntegerLast() in hash code functions.
All found hash code functions behaves uniformly now: they return a value in the range [1, theUpperBound]. Relevant comments are added to such functions.
This commit is contained in:
tiv 2019-03-28 12:42:41 +03:00 committed by bugmaster
parent 833034f301
commit 2b2be3fb82
89 changed files with 878 additions and 580 deletions

View File

@ -62,11 +62,13 @@ class BOPDS_Pair {
return (myIndex1 == theOther.myIndex1 && myIndex2 == theOther.myIndex2) || return (myIndex1 == theOther.myIndex1 && myIndex2 == theOther.myIndex2) ||
(myIndex1 == theOther.myIndex2 && myIndex2 == theOther.myIndex1); (myIndex1 == theOther.myIndex2 && myIndex2 == theOther.myIndex1);
} }
//
//! Returns hash code //! Computes a hash code for this pair, in the range [1, theUpperBound]
Standard_Integer HashCode (const Standard_Integer theUpper) const //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_Integer HashCode (const Standard_Integer theUpperBound) const
{ {
return ::HashCode(myIndex1 + myIndex2, theUpper); return ::HashCode(myIndex1 + myIndex2, theUpperBound);
} }
protected: protected:

View File

@ -30,13 +30,16 @@ class BOPDS_PairMapHasher
public: public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
static Standard_Integer HashCode(const BOPDS_Pair& thePair, //! Computes a hash code for the given pair, in the range [1, theUpperBound]
const Standard_Integer Upper) //! @param thePair the pair which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const BOPDS_Pair& thePair, const Standard_Integer theUpperBound)
{ {
return thePair.HashCode(Upper); return thePair.HashCode (theUpperBound);
} }
static Standard_Boolean IsEqual(const BOPDS_Pair& thePair1, static Standard_Boolean IsEqual(const BOPDS_Pair& thePair1,
const BOPDS_Pair& thePair2) const BOPDS_Pair& thePair2)
{ {

View File

@ -31,10 +31,13 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the given pave, in the range [1, theUpperBound]
static Standard_Integer HashCode (const BOPDS_Pave& aPave, const Standard_Integer Upper); //! @param thePave the pave which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
static Standard_Boolean IsEqual (const BOPDS_Pave& aPave1, const BOPDS_Pave& aPave2); //! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const BOPDS_Pave& thePave, Standard_Integer theUpperBound);
static Standard_Boolean IsEqual (const BOPDS_Pave& aPave1, const BOPDS_Pave& aPave2);

View File

@ -15,15 +15,14 @@
#include <BOPDS_Pave.hxx> #include <BOPDS_Pave.hxx>
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
inline inline Standard_Integer BOPDS_PaveMapHasher::HashCode (const BOPDS_Pave& thePave, const Standard_Integer theUpperBound)
Standard_Integer BOPDS_PaveMapHasher::HashCode(const BOPDS_Pave& aPave,
const Standard_Integer Upper)
{ {
return ::HashCode(aPave.Index(), Upper); return ::HashCode (thePave.Index(), theUpperBound);
} }
//======================================================================= //=======================================================================
//function :IsEqual //function :IsEqual
//purpose : //purpose :

View File

@ -55,10 +55,13 @@ class BOPTools_Parallel
//! Auxiliary thread ID hasher. //! Auxiliary thread ID hasher.
struct Hasher struct Hasher
{ {
static Standard_Integer HashCode(const Standard_ThreadId theKey, //! Computes a hash code for the given thread identifier, in the range [1, theUpperBound]
const Standard_Integer Upper) //! @param theThreadId the thread identifier which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const Standard_ThreadId theThreadId, const Standard_Integer theUpperBound)
{ {
return ::HashCode((Standard_Size)theKey, Upper); return ::HashCode (theThreadId, theUpperBound);
} }
static Standard_Boolean IsEqual(const Standard_ThreadId theKey1, static Standard_Boolean IsEqual(const Standard_ThreadId theKey1,

View File

@ -107,15 +107,16 @@ const TopoDS_Shape& BOPTools_Set::Shape()const
{ {
return myShape; return myShape;
} }
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
Standard_Integer BOPTools_Set::HashCode Standard_Integer BOPTools_Set::HashCode (const Standard_Integer theUpperBound) const
(const Standard_Integer theUpper)const
{ {
return ::HashCode(mySum, theUpper); return ::HashCode (mySum, theUpperBound);
} }
//======================================================================= //=======================================================================
//function : IsEqual //function : IsEqual
//purpose : //purpose :

View File

@ -54,10 +54,11 @@ BOPTools_Set& operator = (const BOPTools_Set& Other)
Standard_EXPORT Standard_Integer NbShapes() const; Standard_EXPORT Standard_Integer NbShapes() const;
Standard_EXPORT Standard_Boolean IsEqual (const BOPTools_Set& aOther) const; Standard_EXPORT Standard_Boolean IsEqual (const BOPTools_Set& aOther) const;
Standard_EXPORT Standard_Integer HashCode (const Standard_Integer Upper) const;
//! Computes a hash code for this set, in the range [1, theUpperBound]
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT Standard_Integer HashCode (Standard_Integer theUpperBound) const;
protected: protected:

View File

@ -30,11 +30,14 @@ class BOPTools_SetMapHasher
public: public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the given set, in the range [1, theUpperBound]
//! @param theSet the set which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const BOPTools_Set& theSet, Standard_Integer theUpperBound);
static Standard_Boolean IsEqual (const BOPTools_Set& aSet1, const BOPTools_Set& aSet2);
static Standard_Integer HashCode (const BOPTools_Set& aSet, const Standard_Integer Upper);
static Standard_Boolean IsEqual (const BOPTools_Set& aSet1, const BOPTools_Set& aSet2);

View File

@ -13,15 +13,17 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
//#include <BOPTools_SetMapHasher.ixx> //#include <BOPTools_SetMapHasher.ixx>
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
inline Standard_Integer BOPTools_SetMapHasher::HashCode(const BOPTools_Set& theSS, inline Standard_Integer BOPTools_SetMapHasher::HashCode (const BOPTools_Set& theSet,
const Standard_Integer Upper) const Standard_Integer theUpperBound)
{ {
return theSS.HashCode(Upper); return theSet.HashCode (theUpperBound);
} }
//======================================================================= //=======================================================================
//function :IsEqual //function :IsEqual
//purpose : //purpose :

View File

@ -86,10 +86,13 @@ private:
BRepMesh_DegreeOfFreedom myMovability; BRepMesh_DegreeOfFreedom myMovability;
}; };
inline Standard_Integer HashCode(const BRepMesh_Edge& theEdge, //! Computes a hash code for the given edge, in the range [1, theUpperBound]
const Standard_Integer theUpper) //! @param theEdge the edge which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const BRepMesh_Edge& theEdge, const Standard_Integer theUpperBound)
{ {
return theEdge.HashCode(theUpper); return theEdge.HashCode (theUpperBound);
} }
#endif #endif

View File

@ -54,12 +54,12 @@ public:
return myLastNode; return myLastNode;
} }
//! Returns hash code for this edge. //! Computes a hash code for this oriented edge, in the range [1, theUpperBound]
//! @param theUpper upper index in the container. //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return hash code. //! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode(const Standard_Integer theUpper) const inline Standard_Integer HashCode (const Standard_Integer theUpperBound) const
{ {
return ::HashCode(myFirstNode + myLastNode, theUpper); return ::HashCode (myFirstNode + myLastNode, theUpperBound);
} }
//! Checks this and other edge for equality. //! Checks this and other edge for equality.
@ -82,10 +82,13 @@ private:
Standard_Integer myLastNode; Standard_Integer myLastNode;
}; };
inline Standard_Integer HashCode(const BRepMesh_OrientedEdge& theEdge, //! Computes a hash code for the given oriented edge, in the range [1, theUpperBound]
const Standard_Integer theUpper) //! @param theOrientedEdge the oriented edge which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const BRepMesh_OrientedEdge& theOrientedEdge, const Standard_Integer theUpperBound)
{ {
return theEdge.HashCode(theUpper); return theOrientedEdge.HashCode (theUpperBound);
} }
#endif #endif

View File

@ -91,15 +91,15 @@ public:
{ {
myMovability = theMovability; myMovability = theMovability;
} }
//! Returns hash code for this triangle. //! Computes a hash code for this triangle, in the range [1, theUpperBound]
//! @param theUpper upper index in the container. //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return hash code. //! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode(const Standard_Integer theUpper) const inline Standard_Integer HashCode (const Standard_Integer theUpperBound) const
{ {
return ::HashCode(myEdges[0] + myEdges[1] + myEdges[2], theUpper); return ::HashCode (myEdges[0] + myEdges[1] + myEdges[2], theUpperBound);
} }
//! Checks for equality with another triangle. //! Checks for equality with another triangle.
//! @param theOther triangle to be checked against this one. //! @param theOther triangle to be checked against this one.
//! @return TRUE if equal, FALSE if not. //! @return TRUE if equal, FALSE if not.
@ -143,10 +143,13 @@ public:
BRepMesh_DegreeOfFreedom myMovability; BRepMesh_DegreeOfFreedom myMovability;
}; };
inline Standard_Integer HashCode(const BRepMesh_Triangle& theTriangle, //! Computes a hash code for the given triangle, in the range [1, theUpperBound]
const Standard_Integer theUpper) //! @param theTriangle the triangle which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const BRepMesh_Triangle& theTriangle, const Standard_Integer theUpperBound)
{ {
return theTriangle.HashCode(theUpper); return theTriangle.HashCode (theUpperBound);
} }
#endif #endif

View File

@ -103,13 +103,13 @@ public:
{ {
myMovability = theMovability; myMovability = theMovability;
} }
//! Returns hash code for this vertex. //! Computes a hash code for this vertex, in the range [1, theUpperBound]
//! @param theUpper upper index in the container. //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return hash code. //! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode(const Standard_Integer Upper) const inline Standard_Integer HashCode(const Standard_Integer theUpperBound) const
{ {
return ::HashCode(Floor(1e5 * myUV.X()) * Floor(1e5 * myUV.Y()), Upper); return ::HashCode(Floor(1e5 * myUV.X()) * Floor(1e5 * myUV.Y()), theUpperBound);
} }
//! Checks for equality with another vertex. //! Checks for equality with another vertex.
@ -139,9 +139,13 @@ private:
BRepMesh_DegreeOfFreedom myMovability; BRepMesh_DegreeOfFreedom myMovability;
}; };
inline Standard_Integer HashCode(const BRepMesh_Vertex& me, const Standard_Integer Upper) //! Computes a hash code for the given vertex, in the range [1, theUpperBound]
//! @param theVertex the vertex which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const BRepMesh_Vertex& theVertex, const Standard_Integer theUpperBound)
{ {
return me.HashCode(Upper); return theVertex.HashCode (theUpperBound);
} }
#endif #endif

View File

@ -136,13 +136,15 @@ private:
Handle(Font_SystemFont) Find (const TCollection_AsciiString& theFontName) const; Handle(Font_SystemFont) Find (const TCollection_AsciiString& theFontName) const;
public: public:
//! Computes a hash code for the system font, in the range [1, theUpperBound]. Based on Font Family, so that the
//! Hash value, for Map interface. //! whole family with different aspects can be found within the same bucket of some map
//! Based on Font Family, so that the whole family with different aspects can be found within the same bucket. //! @param theHExtendedString the handle referred to extended string which hash code is to be computed
static Standard_Integer HashCode (const Handle(Font_SystemFont)& theFont, //! @param theUpperBound the upper bound of the range a computing hash code must be within
const Standard_Integer theUpper) //! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const Handle (Font_SystemFont) & theSystemFont,
const Standard_Integer theUpperBound)
{ {
return ::HashCode (theFont->FontKey(), theUpper); return ::HashCode (theSystemFont->FontKey(), theUpperBound);
} }
//! Matching two instances, for Map interface. //! Matching two instances, for Map interface.

View File

@ -89,13 +89,14 @@ public:
Standard_EXPORT TCollection_AsciiString ToString() const; Standard_EXPORT TCollection_AsciiString ToString() const;
public: public:
//! Computes a hash code for the system font, in the range [1, theUpperBound]. Based on Font Family, so that the whole
//! Hash value, for Map interface. //! family with different aspects can be found within the same bucket of some map
//! Based on Font Family, so that the whole family with different aspects can be found within the same bucket. //! @param theSystemFont the system font which hash code is to be computed
static Standard_Integer HashCode (const Handle(Font_SystemFont)& theFont, //! @param theUpperBound the upper bound of the range a computing hash code must be within
const Standard_Integer theUpper) //! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const Handle (Font_SystemFont) & theSystemFont, const Standard_Integer theUpperBound)
{ {
return ::HashCode (theFont->FontKey(), theUpper); return ::HashCode (theSystemFont->FontKey(), theUpperBound);
} }
//! Matching two instances, for Map interface. //! Matching two instances, for Map interface.

View File

@ -141,9 +141,13 @@ namespace IMeshData
return (theFirst == theSecond); return (theFirst == theSecond);
} }
static Standard_Integer HashCode(const Type* thePtr, Standard_Integer theUpper) //! Computes a hash code for the given pointer, in the range [1, theUpperBound]
//! @param thePointer the pointer which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const Type* const thePointer, Standard_Integer theUpperBound)
{ {
return ::HashCode(thePtr, theUpper); return ::HashCode (thePointer, theUpperBound);
} }
}; };

View File

@ -92,12 +92,15 @@ public:
return (myIndex1 == theOther.myIndex1 && myIndex2 == theOther.myIndex2) || return (myIndex1 == theOther.myIndex1 && myIndex2 == theOther.myIndex2) ||
(myIndex1 == theOther.myIndex2 && myIndex2 == theOther.myIndex1); (myIndex1 == theOther.myIndex2 && myIndex2 == theOther.myIndex1);
} }
//
//! Returns hash code //! Computes a hash code for this couple, in the range [1, theUpperBound]
Standard_Integer HashCode (const Standard_Integer theUpper) const //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_Integer HashCode (const Standard_Integer theUpperBound) const
{ {
return ::HashCode(myIndex1 + myIndex2, theUpper); return ::HashCode (myIndex1 + myIndex2, theUpperBound);
} }
// Dump // Dump
Standard_EXPORT void Dump (const Standard_Integer v) const; Standard_EXPORT void Dump (const Standard_Integer v) const;

View File

@ -24,13 +24,16 @@ class IntPolyh_Couple;
class IntPolyh_CoupleMapHasher class IntPolyh_CoupleMapHasher
{ {
public: public:
static Standard_Integer HashCode(const IntPolyh_Couple& theCouple, //! Computes a hash code for the given couple, in the range [1, theUpperBound]
const Standard_Integer Upper) //! @param theCouple the couple which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const IntPolyh_Couple& theCouple, const Standard_Integer theUpperBound)
{ {
return theCouple.HashCode(Upper); return theCouple.HashCode (theUpperBound);
} }
static Standard_Boolean IsEqual(const IntPolyh_Couple& theCouple1, static Standard_Boolean IsEqual(const IntPolyh_Couple& theCouple1,
const IntPolyh_Couple& theCouple2) const IntPolyh_Couple& theCouple2)
{ {

View File

@ -32,11 +32,12 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the given key, in the range [1, theUpperBound]
//! Returns a HasCode value for the Key <K> in the //! @param theKey the key which hash code is to be computed
//! range 0..Upper. //! @param theUpperBound the upper bound of the range a computing hash code must be within
static Standard_Integer HashCode (const IntTools_CurveRangeSample& K, const Standard_Integer Upper); //! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const IntTools_CurveRangeSample& theKey, const Standard_Integer theUpperBound);
//! Returns True when the two keys are the same. Two //! Returns True when the two keys are the same. Two
//! same keys must have the same hashcode, the //! same keys must have the same hashcode, the
//! contrary is not necessary. //! contrary is not necessary.

View File

@ -13,11 +13,16 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
inline Standard_Integer IntTools_CurveRangeSampleMapHasher::HashCode(const IntTools_CurveRangeSample& K, //=======================================================================
const Standard_Integer Upper) { // function : HashCode
return (K.GetDepth() % Upper); // purpose :
//=======================================================================
inline Standard_Integer IntTools_CurveRangeSampleMapHasher::HashCode (const IntTools_CurveRangeSample& theKey,
const Standard_Integer theUpperBound)
{
return ::HashCode(theKey.GetDepth(), theUpperBound);
} }
inline Standard_Boolean IntTools_CurveRangeSampleMapHasher::IsEqual(const IntTools_CurveRangeSample& S1, inline Standard_Boolean IntTools_CurveRangeSampleMapHasher::IsEqual(const IntTools_CurveRangeSample& S1,
const IntTools_CurveRangeSample& S2) { const IntTools_CurveRangeSample& S2) {
return S1.IsEqual(S2); return S1.IsEqual(S2);

View File

@ -32,11 +32,12 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the given key, in the range [1, theUpperBound]
//! Returns a HasCode value for the Key <K> in the //! @param theKey the key which hash code is to be computed
//! range 0..Upper. //! @param theUpperBound the upper bound of the range a computing hash code must be within
static Standard_Integer HashCode (const IntTools_SurfaceRangeSample& K, const Standard_Integer Upper); //! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const IntTools_SurfaceRangeSample& theKey, Standard_Integer theUpperBound);
//! Returns True when the two keys are the same. Two //! Returns True when the two keys are the same. Two
//! same keys must have the same hashcode, the //! same keys must have the same hashcode, the
//! contrary is not necessary. //! contrary is not necessary.

View File

@ -13,12 +13,17 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
inline Standard_Integer IntTools_SurfaceRangeSampleMapHasher::HashCode(const IntTools_SurfaceRangeSample& K, //=======================================================================
const Standard_Integer Upper) { // function : HashCode
// return (((K.GetDepthU() % Upper) ^ (K.GetDepthV() % Upper)) % Upper); // purpose :
return ((K.GetIndexU() * K.GetIndexV()) % Upper); //=======================================================================
inline Standard_Integer IntTools_SurfaceRangeSampleMapHasher::HashCode (const IntTools_SurfaceRangeSample& theKey,
const Standard_Integer theUpperBound)
{
// return (((K.GetDepthU() % Upper) ^ (K.GetDepthV() % Upper)) % Upper);
return ::HashCode (theKey.GetIndexU() * theKey.GetIndexV(), theUpperBound);
} }
inline Standard_Boolean IntTools_SurfaceRangeSampleMapHasher::IsEqual(const IntTools_SurfaceRangeSample& S1, inline Standard_Boolean IntTools_SurfaceRangeSampleMapHasher::IsEqual(const IntTools_SurfaceRangeSample& S1,
const IntTools_SurfaceRangeSample& S2) { const IntTools_SurfaceRangeSample& S2) {
return S1.IsEqual(S2); return S1.IsEqual(S2);

View File

@ -16,13 +16,13 @@
#include <TCollection_AsciiString.hxx> #include <TCollection_AsciiString.hxx>
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
Standard_Integer Interface_MapAsciiStringHasher::HashCode(const TCollection_AsciiString& K, Standard_Integer Interface_MapAsciiStringHasher::HashCode (const TCollection_AsciiString& theAsciiString,
const Standard_Integer Upper) const Standard_Integer theUpperBound)
{ {
return ::HashCode(K.ToCString(),Upper); return ::HashCode (theAsciiString.ToCString(), theAsciiString.Length(), theUpperBound);
} }
//======================================================================= //=======================================================================

View File

@ -32,9 +32,13 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the given ASCII string, in the range [1, theUpperBound]
Standard_EXPORT static Standard_Integer HashCode (const TCollection_AsciiString& K, const Standard_Integer Upper); //! @param theAsciiString the ASCII string which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT static Standard_Integer HashCode (const TCollection_AsciiString& theAsciiString,
Standard_Integer theUpperBound);
Standard_EXPORT static Standard_Boolean IsEqual (const TCollection_AsciiString& K1, const TCollection_AsciiString& K2); Standard_EXPORT static Standard_Boolean IsEqual (const TCollection_AsciiString& K1, const TCollection_AsciiString& K2);

View File

@ -32,11 +32,14 @@ class MAT2d_MapBiIntHasher
public: public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the given key, in the range [1, theUpperBound]
//! @param theKey the key which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const MAT2d_BiInt& theKey, const Standard_Integer theUpperBound);
static Standard_Boolean IsEqual (const MAT2d_BiInt& Key1, const MAT2d_BiInt& Key2);
static Standard_Integer HashCode (const MAT2d_BiInt& Key1, const Standard_Integer Upper);
static Standard_Boolean IsEqual (const MAT2d_BiInt& Key1, const MAT2d_BiInt& Key2);

View File

@ -18,13 +18,12 @@
#include <TColStd_MapIntegerHasher.hxx> #include <TColStd_MapIntegerHasher.hxx>
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
inline Standard_Integer MAT2d_MapBiIntHasher::HashCode inline Standard_Integer MAT2d_MapBiIntHasher::HashCode (const MAT2d_BiInt& theKey, const Standard_Integer theUpperBound)
(const MAT2d_BiInt& Key1, const Standard_Integer upper)
{ {
return TColStd_MapIntegerHasher::HashCode(Key1.FirstIndex(),upper); return TColStd_MapIntegerHasher::HashCode (theKey.FirstIndex(), theUpperBound);
} }
//======================================================================= //=======================================================================

View File

@ -21,9 +21,13 @@ typedef std::pair<Standard_Integer, Standard_Integer> MeshVS_NodePair;
//! Provides symmetric hash methods pair of integers. //! Provides symmetric hash methods pair of integers.
struct MeshVS_SymmetricPairHasher struct MeshVS_SymmetricPairHasher
{ {
static Standard_Integer HashCode (const MeshVS_NodePair& thePair, const Standard_Integer theMaxCode) //! Computes a hash code for the node pair, in the range [1, theUpperBound]
//! @param theNodePair the node pair which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const MeshVS_NodePair& theNodePair, const Standard_Integer theUpperBound)
{ {
return ((thePair.first + thePair.second) & 0x7FFFFFFF) % theMaxCode + 1; return ::HashCode(theNodePair.first + theNodePair.second, theUpperBound);
} }
static Standard_Boolean IsEqual (const MeshVS_NodePair& thePair1, const MeshVS_NodePair& thePair2) static Standard_Boolean IsEqual (const MeshVS_NodePair& thePair1, const MeshVS_NodePair& thePair2)

View File

@ -17,18 +17,17 @@
//================================================================ //================================================================
// Function : HashCode // function : HashCode
// Purpose : // purpose :
//================================================================ //================================================================
Standard_Integer HashCode ( const MeshVS_TwoColors& theKey, Standard_Integer HashCode (const MeshVS_TwoColors& theKey, const Standard_Integer theUpperBound)
const Standard_Integer theUpper)
{ {
#define MESHPRS_HASH_BYTE(val) { \ #define MESHPRS_HASH_BYTE(val) { \
aHash += (val); \ aHash += (val); \
aHash += (aHash << 10); \ aHash += (aHash << 10); \
aHash ^= (aHash >> 6); \ aHash ^= (aHash >> 6); \
} }
Standard_Integer aHash = 0; unsigned int aHash = 0;
MESHPRS_HASH_BYTE (theKey.r1) MESHPRS_HASH_BYTE (theKey.r1)
MESHPRS_HASH_BYTE (theKey.g1) MESHPRS_HASH_BYTE (theKey.g1)
MESHPRS_HASH_BYTE (theKey.b1) MESHPRS_HASH_BYTE (theKey.b1)
@ -38,7 +37,7 @@ Standard_Integer HashCode ( const MeshVS_TwoColors& theKey,
aHash += (aHash << 3); aHash += (aHash << 3);
aHash ^= (aHash >> 11); aHash ^= (aHash >> 11);
aHash += (aHash << 15); aHash += (aHash << 15);
return (( aHash & 0x7fffffff ) % theUpper) + 1; return HashCode(aHash, theUpperBound);
#undef MESHPRS_HASH_BYTE #undef MESHPRS_HASH_BYTE
} }

View File

@ -28,8 +28,11 @@ typedef struct {
} MeshVS_TwoColors; } MeshVS_TwoColors;
Standard_EXPORT Standard_Integer HashCode ( const MeshVS_TwoColors& theKey, //! Computes a hash code for the key, in the range [1, theUpperBound]
const Standard_Integer theUpper ); //! @param theKey the key which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT Standard_Integer HashCode (const MeshVS_TwoColors& theKey, Standard_Integer theUpperBound);
Standard_EXPORT Standard_Boolean IsEqual (const MeshVS_TwoColors& K1, Standard_EXPORT Standard_Boolean IsEqual (const MeshVS_TwoColors& K1,
const MeshVS_TwoColors& K2 ); const MeshVS_TwoColors& K2 );

View File

@ -32,17 +32,15 @@ struct MeshVS_TwoNodes
: First(aFirst), Second(aSecond) {} : First(aFirst), Second(aSecond) {}
}; };
//================================================================ //! Computes a hash code for two nodes, in the range [1, theUpperBound]
// Function : HashCode //! @param theTwoNodes the object of structure containing two IDs which hash code is to be computed
// Purpose : //! @param theUpperBound the upper bound of the range a computing hash code must be within
//================================================================ //! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const MeshVS_TwoNodes& theTwoNodes, const Standard_Integer theUpperBound)
inline Standard_Integer HashCode( const MeshVS_TwoNodes& obj,
const Standard_Integer Upper )
{ {
// symmetrical with respect to obj.First and obj.Second // symmetrical with respect to theTwoNodes.First and theTwoNodes.Second
const Standard_Integer aKey = obj.First + obj.Second; const Standard_Integer aKey = theTwoNodes.First + theTwoNodes.Second;
return HashCode (aKey, Upper); return HashCode (aKey, theUpperBound);
} }
//================================================================ //================================================================

View File

@ -15,10 +15,14 @@
#include <MoniTool_Element.hxx> #include <MoniTool_Element.hxx>
#include <MoniTool_ElemHasher.hxx> #include <MoniTool_ElemHasher.hxx>
Standard_Integer MoniTool_ElemHasher::HashCode //============================================================================
(const Handle(MoniTool_Element)& K, const Standard_Integer Upper) // function : HashCode
// purpose :
//============================================================================
Standard_Integer MoniTool_ElemHasher::HashCode (const Handle (MoniTool_Element) & theElement,
const Standard_Integer theUpperBound)
{ {
return ((K->GetHashCode() - 1) % Upper) + 1; return ::HashCode(theElement->GetHashCode() - 1, theUpperBound);
} }
Standard_Boolean MoniTool_ElemHasher::IsEqual Standard_Boolean MoniTool_ElemHasher::IsEqual

View File

@ -38,12 +38,14 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Returns hash code for the given element, in the range [1, theUpperBound].
//! Returns a HashCode in the range <0,Upper> for a Element : //! Asks theElement its HashCode, then transforms it to be in the required range.
//! asks the Element its HashCode then transforms it to be in the //! @param theElement the element which hash code is to be computed
//! required range //! @param theUpperBound the upper bound of the range a computing hash code must be within
Standard_EXPORT static Standard_Integer HashCode (const Handle(MoniTool_Element)& K, const Standard_Integer Upper); //! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT static Standard_Integer HashCode (const Handle (MoniTool_Element) & theElement,
Standard_Integer theUpperBound);
//! Returns True if two keys are the same. //! Returns True if two keys are the same.
//! The test does not work on the Elements themselves but by //! The test does not work on the Elements themselves but by
//! calling their methods Equates //! calling their methods Equates

View File

@ -33,12 +33,12 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Returns hash code for the given string, in the range [1, theUpperBound]
//! Returns a HasCode value for the CString <Str> in the //! @param theString the string which hash code is to be computed
//! range 0..Upper. //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! Default ::HashCode(Str,Upper) //! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const Standard_CString Str, const Standard_Integer Upper); static Standard_Integer HashCode (Standard_CString theString, Standard_Integer theUpperBound);
//! Returns True when the two CString are the same. Two //! Returns True when the two CString are the same. Two
//! same strings must have the same hashcode, the //! same strings must have the same hashcode, the
//! contrary is not necessary. //! contrary is not necessary.

View File

@ -14,14 +14,13 @@
#include <string.h> #include <string.h>
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
inline Standard_Integer MoniTool_MTHasher::HashCode (const Standard_CString theString,
inline Standard_Integer MoniTool_MTHasher::HashCode(const Standard_CString Str, const Standard_Integer theUpperBound)
const Standard_Integer Upper)
{ {
return ::HashCode(Str,Upper); return ::HashCode (theString, theUpperBound);
} }
//======================================================================= //=======================================================================

View File

@ -108,8 +108,14 @@ protected:
class Hasher class Hasher
{ {
public: public:
static Standard_Integer HashCode(const Key theKey, const Standard_Integer theUpper) //! Returns hash code for the given key, in the range [1, theUpperBound]
{ return theKey.Value % theUpper + 1; } //! @param theKey the key which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const Key theKey, const Standard_Integer theUpperBound)
{
return ::HashCode (theKey.Value, theUpperBound);
}
static Standard_Boolean IsEqual(const Key theOne, const Key theTwo) static Standard_Boolean IsEqual(const Key theOne, const Key theTwo)
{ return theOne.Value == theTwo.Value; } { return theOne.Value == theTwo.Value; }

View File

@ -317,26 +317,38 @@ protected:
return Standard_True; return Standard_True;
} }
//! Compute hash code //! Returns hash code for this cell, in the range [1, theUpperBound]
Standard_Integer HashCode (const Standard_Integer theUpper) const //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_Integer HashCode (const Standard_Integer theUpperBound) const
{ {
// number of bits per each dimension in the hash code // number of bits per each dimension in the hash code
Standard_Integer aDim = Standard_Integer(index.Size()); const std::size_t aDim = index.Size();
const Standard_Size aShiftBits = (BITS(long)-1) / aDim; const std::size_t aShiftBits = (BITS (long) - 1) / aDim;
long aCode=0; unsigned int aCode = 0;
for (int i=0; i < aDim; i++)
aCode = ( aCode << aShiftBits ) ^ index[i]; for (std::size_t i = 0; i < aDim; ++i)
return (unsigned)aCode % theUpper; {
aCode = (aCode << aShiftBits) ^ index[i];
}
return ::HashCode(aCode, theUpperBound);
} }
public: public:
NCollection_LocalArray<long, 10> index; NCollection_LocalArray<long, 10> index;
ListNode *Objects; ListNode *Objects;
}; };
//! Returns hash code for the given cell, in the range [1, theUpperBound]
//! @param theCell the cell object which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
friend Standard_Integer HashCode (const Cell& theCell, const Standard_Integer theUpperBound)
{
return theCell.HashCode (theUpperBound);
}
// definition of global functions is needed for map
friend Standard_Integer HashCode (const Cell &aCell, const Standard_Integer theUpper)
{ return aCell.HashCode(theUpper); }
friend Standard_Boolean IsEqual (const Cell &aCell1, const Cell &aCell2) friend Standard_Boolean IsEqual (const Cell &aCell1, const Cell &aCell2)
{ return aCell1.IsEqual(aCell2); } { return aCell1.IsEqual(aCell2); }

View File

@ -23,11 +23,15 @@
//purpose : Function is required to call the global function HashCode. //purpose : Function is required to call the global function HashCode.
//======================================================================= //=======================================================================
template <class TheKeyType> //! Returns hash code for the given key, in the range [1, theUpperBound]
inline Standard_Integer HashCode_Proxy (const TheKeyType& theKey, //! @tparam TheKeyType the type of the given key
const Standard_Integer Upper) //! @param theKey the key which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
template <class TheKeyType>
inline Standard_Integer HashCode_Proxy (const TheKeyType& theKey, const Standard_Integer theUpperBound)
{ {
return HashCode (theKey, Upper); return HashCode (theKey, theUpperBound);
} }
//======================================================================= //=======================================================================
@ -65,11 +69,15 @@ inline Standard_Boolean IsEqual_Proxy (const TheKeyType& theKey1,
*/ */
template <class TheKeyType> class NCollection_DefaultHasher { template <class TheKeyType> class NCollection_DefaultHasher {
public: public:
// //! Returns hash code for the given key, in the range [1, theUpperBound]
static Standard_Integer HashCode(const TheKeyType& theKey, //! @param theKey the key which hash code is to be computed
const Standard_Integer Upper) { //! @param theUpperBound the upper bound of the range a computing hash code must be within
return HashCode_Proxy(theKey, Upper); //! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const TheKeyType& theKey, const Standard_Integer theUpperBound)
{
return HashCode_Proxy (theKey, theUpperBound);
} }
// //
static Standard_Boolean IsEqual(const TheKeyType& theKey1, static Standard_Boolean IsEqual(const TheKeyType& theKey1,
const TheKeyType& theKey2) { const TheKeyType& theKey2) {

View File

@ -144,9 +144,10 @@ Standard_Boolean OSD_Thread::Run (const Standard_Address data,
adata->func = myFunc; adata->func = myFunc;
// then try to create a new thread // then try to create a new thread
DWORD aThreadId = DWORD();
myThread = CreateThread ( NULL, WNTStackSize, WNTthread_func, myThread = CreateThread ( NULL, WNTStackSize, WNTthread_func,
adata, 0, &myThreadId ); adata, 0, &aThreadId );
myThreadId = aThreadId;
if ( myThread ) if ( myThread )
SetThreadPriority (myThread, myPriority); SetThreadPriority (myThread, myPriority);
else { else {
@ -162,7 +163,7 @@ Standard_Boolean OSD_Thread::Run (const Standard_Address data,
} }
else else
{ {
myThreadId = myThread; myThreadId = (Standard_ThreadId)myThread;
} }
#endif #endif
return myThread != 0; return myThread != 0;
@ -328,6 +329,6 @@ Standard_ThreadId OSD_Thread::Current ()
#ifdef _WIN32 #ifdef _WIN32
return GetCurrentThreadId(); return GetCurrentThreadId();
#else #else
return pthread_self(); return (Standard_ThreadId)pthread_self();
#endif #endif
} }

View File

@ -250,13 +250,13 @@ private:
TColStd_PackedMapOfInteger myHangIndices; TColStd_PackedMapOfInteger myHangIndices;
}; };
/** //! Computes a hash code for the given link, in the range [1, theUpperBound]
* HashCode method is needed for maps //! @param theLink the link which hash code is to be computed
*/ //! @param theUpperBound the upper bound of the range a computing hash code must be within
inline Standard_Integer HashCode(const Poly_MakeLoops::Link& theKey, //! @return a computed hash code, in the range [1, theUpperBound]
int theLimit) inline Standard_Integer HashCode (const Poly_MakeLoops::Link& theLink, const Standard_Integer theUpperBound)
{ {
return HashCode(theKey.node1 + theKey.node2, theLimit); return HashCode (theLink.node1 + theLink.node2, theUpperBound);
} }
/** /**

View File

@ -73,9 +73,14 @@ DEFINE_SEQUENCE(QANCollection_SequenceFunc,QANCollection_BaseColFunc,ItemType)
DEFINE_HSEQUENCE(QANCollection_HSequenceFunc,QANCollection_SequenceFunc) DEFINE_HSEQUENCE(QANCollection_HSequenceFunc,QANCollection_SequenceFunc)
// HashCode and IsEquel must be defined for key types of maps // HashCode and IsEquel must be defined for key types of maps
Standard_Integer HashCode(const gp_Pnt thePnt, int theUpper)
//! Computes a hash code for the point, in the range [1, theUpperBound]
//! @param thePoint the point which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_Integer HashCode (const gp_Pnt& thePoint, int theUpperBound)
{ {
return HashCode(thePnt.X(),theUpper); return HashCode (thePoint.X(), theUpperBound);
} }
Standard_Boolean IsEqual(const gp_Pnt& theP1, const gp_Pnt& theP2) Standard_Boolean IsEqual(const gp_Pnt& theP1, const gp_Pnt& theP2)

View File

@ -20,22 +20,27 @@
//! Hasher of Quantity_Color. //! Hasher of Quantity_Color.
struct Quantity_ColorHasher struct Quantity_ColorHasher
{ {
//! Returns hash code for the given color. //! Returns hash code for the given RGB color, in the range [1, theUpperBound]
//! @param theColor the RGB color object which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing range must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const Quantity_Color& theColor, static Standard_Integer HashCode (const Quantity_Color& theColor,
const Standard_Integer theUpper) const Standard_Integer theUpperBound)
{ {
Standard_Integer aRed = Standard_Integer (255 * theColor.Red()); Standard_Integer aRed = Standard_Integer (255 * theColor.Red());
Standard_Integer aGreen = Standard_Integer (255 * theColor.Green()); Standard_Integer aGreen = Standard_Integer (255 * theColor.Green());
Standard_Integer aBlue = Standard_Integer (255 * theColor.Blue()); Standard_Integer aBlue = Standard_Integer (255 * theColor.Blue());
Standard_Integer aHash = 0; unsigned int aHash = 0;
updateHash (aHash, aRed); updateHash (aHash, aRed);
updateHash (aHash, aGreen); updateHash (aHash, aGreen);
updateHash (aHash, aBlue); updateHash (aHash, aBlue);
aHash += (aHash << 3); aHash += (aHash << 3);
aHash ^= (aHash >> 11); aHash ^= (aHash >> 11);
aHash += (aHash << 15); aHash += (aHash << 15);
return ((aHash & 0x7fff) % theUpper) + 1;
return IntegerHashCode(aHash, 0x7fff, theUpperBound);
} }
//! Returns true if two colors are equal. //! Returns true if two colors are equal.
@ -46,8 +51,7 @@ struct Quantity_ColorHasher
} }
protected: protected:
static void updateHash (Standard_Integer& theHash, static void updateHash (unsigned int& theHash, const Standard_Integer theValue)
const Standard_Integer theValue)
{ {
theHash += theValue; theHash += theValue;
theHash += (theHash << 10); theHash += (theHash << 10);

View File

@ -21,16 +21,19 @@
struct Quantity_ColorRGBAHasher struct Quantity_ColorRGBAHasher
{ {
//! Returns hash code for the given color. //! Returns hash code for the given RGBA color, in the range [1, theUpperBound]
//! @param theColor the RGBA color object which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const Quantity_ColorRGBA& theColor, static Standard_Integer HashCode (const Quantity_ColorRGBA& theColor,
const Standard_Integer theUpper) const Standard_Integer theUpperBound)
{ {
const NCollection_Vec4<float>& aColor = theColor; const NCollection_Vec4<float>& aColor = theColor;
uint32_t aColor32 = (uint32_t(aColor.a() * 255.0f) << 24) uint32_t aColor32 = (uint32_t(aColor.a() * 255.0f) << 24)
+ (uint32_t(aColor.b() * 255.0f) << 16) + (uint32_t(aColor.b() * 255.0f) << 16)
+ (uint32_t(aColor.g() * 255.0f) << 8) + (uint32_t(aColor.g() * 255.0f) << 8)
+ uint32_t(aColor.r() * 255.0f); + uint32_t(aColor.r() * 255.0f);
return ((aColor32 & 0x7fffffff) % theUpper) + 1; return ::HashCode(aColor32, theUpperBound);
} }
//! Returns true if two colors are equal. //! Returns true if two colors are equal.

View File

@ -75,9 +75,13 @@ namespace
return (thePnt1 - thePnt2).SquareModulus() < Precision::SquareConfusion(); return (thePnt1 - thePnt2).SquareModulus() < Precision::SquareConfusion();
} }
static Standard_Integer HashCode (const gp_XYZ& thePnt, Standard_Integer theUpper) //! Computes a hash code for the point, in the range [1, theUpperBound]
//! @param thePoint the point which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const gp_XYZ& thePoint, const Standard_Integer theUpperBound)
{ {
return ::HashCode (thePnt.X() * M_LN10 + thePnt.Y() * M_PI + thePnt.Z() * M_E, theUpper); return ::HashCode (thePoint.X() * M_LN10 + thePoint.Y() * M_PI + thePoint.Z() * M_E, theUpperBound);
} }
private: private:

View File

@ -32,11 +32,12 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the point, in the range [1, theUpperBound]
//! Returns a HasCode value for the Key <K> in the //! @param thePoint the point which hash code is to be computed
//! range 0..Upper. //! @param theUpperBound the upper bound of the range a computing hash code must be within
static Standard_Integer HashCode (const gp_Pnt& Point, const Standard_Integer Upper); //! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const gp_Pnt& thePoint, const Standard_Integer theUpperBound);
//! Returns True when the two keys are the same. Two //! Returns True when the two keys are the same. Two
//! same keys must have the same hashcode, the //! same keys must have the same hashcode, the
//! contrary is not necessary. //! contrary is not necessary.

View File

@ -12,22 +12,20 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
inline Standard_Integer STEPConstruct_PointHasher::HashCode inline Standard_Integer STEPConstruct_PointHasher::HashCode (const gp_Pnt& thePoint,
(const gp_Pnt& point, const Standard_Integer Upper) const Standard_Integer theUpperBound)
{ {
union union
{ {
Standard_Real R[3]; Standard_Real R[3];
Standard_Integer I[6]; Standard_Integer I[6];
} U; } U;
point.Coord(U.R[0],U.R[1],U.R[2]); thePoint.Coord (U.R[0], U.R[1], U.R[2]);
return ::HashCode(U.I[0]/23+U.I[1]/19+U.I[2]/17+U.I[3]/13+U.I[4]/11+U.I[5]/7,Upper);
// return ::HashCode((U.I[0]>>4)+(U.I[1]>>3)+(U.I[2]>>2)+(U.I[3]>>1)+(U.I[4]>>4)+(U.I[5]>>3),Upper);
return ::HashCode (U.I[0] / 23 + U.I[1] / 19 + U.I[2] / 17 + U.I[3] / 13 + U.I[4] / 11 + U.I[5] / 7, theUpperBound);
// return ::HashCode((U.I[0]>>4)+(U.I[1]>>3)+(U.I[2]>>2)+(U.I[3]>>1)+(U.I[4]>>4)+(U.I[5]>>3),theUpperBound);
} }

View File

@ -82,6 +82,7 @@ Standard_ShortReal.cxx
Standard_ShortReal.hxx Standard_ShortReal.hxx
Standard_Size.hxx Standard_Size.hxx
Standard_SStream.hxx Standard_SStream.hxx
Standard_Std.hxx
Standard_Stream.hxx Standard_Stream.hxx
Standard_Strtod.cxx Standard_Strtod.cxx
Standard_ThreadId.hxx Standard_ThreadId.hxx

View File

@ -17,18 +17,23 @@
#include <Standard_Integer.hxx> #include <Standard_Integer.hxx>
//============================================================================ //! Returns a hash code of the given memory pointer
//==== HashCode : Returns a HashCode CString //! @param thePointer the memory pointer which hash code it to be computed
//============================================================================ //! @param theUpperBound the upper bound of the range a resulting hash code must be within
inline Standard_Integer HashCode (const Standard_Address Value, //! @return a value of a computed hash code, in range [1, UpperBound]
const Standard_Integer Upper) inline Standard_Integer HashCode (const void* const thePointer, const Standard_Integer theUpperBound)
{ {
union {Standard_Address L ; union
Standard_Integer I[2] ;} U ; {
U.I[0] = 0 ; const void* L;
U.I[1] = 0 ; Standard_Integer I[2];
U.L = Value; } U;
return HashCode( ( ( U.I[0] ^ U.I[1] ) & 0x7fffffff ) , Upper ) ;
U.I[0] = 0;
U.I[1] = 0;
U.L = thePointer;
return HashCode (U.I[0] ^ U.I[1], theUpperBound);
} }
//============================================================================ //============================================================================

View File

@ -28,31 +28,33 @@
#include <stdarg.h> #include <stdarg.h>
//============================================================================ //============================================================================
//==== HashCode of a CString // function : HashCode
// purpose :
//============================================================================ //============================================================================
Standard_Integer HashCode (const Standard_CString Value, Standard_Integer HashCode (const Standard_CString theString, const Standard_Integer theUpperBound)
const Standard_Integer Upper )
{ {
Standard_Integer aLen = (Standard_Integer)strlen(Value); const Standard_Integer aLength = static_cast<Standard_Integer> (strlen (theString));
return HashCode (HashCodes (Value, aLen), Upper);
return HashCode (theString, aLength, theUpperBound);
} }
//============================================================================ //============================================================================
//==== HashCode of a CString // function : HashCodes
// purpose :
//============================================================================ //============================================================================
Standard_Integer HashCodes (const Standard_CString Value, Standard_Integer HashCodes (const Standard_CString theString, const Standard_Integer theLength)
const Standard_Integer Len)
{ {
// compute DJB2 hash of a string // compute DJB2 hash of a string
Standard_Integer hash = 0; unsigned int hash = 0;
const Standard_Character *c = Value; const Standard_Character* c = theString;
for (Standard_Integer i = 0; i < Len; i++, c++)
for (Standard_Integer i = 0; i < theLength; ++i, ++c)
{ {
/* hash = hash * 33 ^ c */ /* hash = hash * 33 ^ c */
hash = ((hash << 5) + hash) ^ (*c); hash = ((hash << 5) + hash) ^ (*c);
} }
return hash; return static_cast<Standard_Integer>(hash);
} }
//====================================================================== //======================================================================

View File

@ -31,20 +31,30 @@
#include <Standard_Integer.hxx> #include <Standard_Integer.hxx>
//! Returns bounded hash code for a null-terminated string, in range [1, theUpper] //! Returns bounded hash code for the null-terminated string, in the range [1, theUpperBound]
Standard_EXPORT Standard_Integer HashCode (const Standard_CString theStr, const Standard_Integer theUpper); //! @param theString the null-terminated string which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT Standard_Integer HashCode (Standard_CString theString, Standard_Integer theUpperBound);
//! Returns 32-bit hash code for the first theLen characters in the string theStr //! Returns 32-bit hash code for the first theLen characters in the string theStr.
Standard_EXPORT Standard_Integer HashCodes (const Standard_CString theStr, const Standard_Integer theLen); //! The result is unbound (may be not only positive, but also negative)
//! @param theString the string which hash code is to be computed
//! @param theLength the length of the given string
//! @return a computed hash code of the given string
Standard_EXPORT Standard_Integer HashCodes (Standard_CString theString, Standard_Integer theLength);
//! Returns bounded hash code for the first theLen characters in //! Returns bounded hash code for the first theLength characters in the string theString, in the range [1, theUpperBound]
//! the string theStr, in range [1, theUpper] //! @param theString the string which hash code is to be computed
inline Standard_Integer HashCode (const Standard_CString theStr, //! @param theLength the length of the initial substring of the given string which hash code is to be computed
const Standard_Integer theLen, //! @param theUpperBound the upper bound of the range a computing hash code must be within
const Standard_Integer theUpper) //! @return a computed hash code of the given string
inline Standard_Integer HashCode (const Standard_CString theString,
const Standard_Integer theLength,
const Standard_Integer theUpperBound)
{ {
// return (Abs( HashCodes( Value , Len ) ) % Upper ) + 1 ; // return (Abs( HashCodes( Value , Len ) ) % Upper ) + 1 ;
return HashCode (HashCodes (theStr, theLen), theUpper); return HashCode (HashCodes (theString, theLength), theUpperBound);
} }
//! Returns Standard_True if two strings are equal //! Returns Standard_True if two strings are equal

View File

@ -47,7 +47,7 @@ static Standard_Mutex theMutex;
static inline Standard_ThreadId GetThreadID() static inline Standard_ThreadId GetThreadID()
{ {
#ifndef _WIN32 #ifndef _WIN32
return pthread_self(); return (Standard_ThreadId)pthread_self();
#else #else
return GetCurrentThreadId(); return GetCurrentThreadId();
#endif #endif

View File

@ -13,19 +13,22 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <Standard_ExtString.hxx> #include <Standard_ExtString.hxx>
#include <Standard_Type.hxx> #include <Standard_Type.hxx>
#include <Standard_OStream.hxx>
Standard_Integer HashCode (const Standard_ExtString Value, //============================================================================
const Standard_Integer Upper) // function : HashCode
// purpose :
//============================================================================
Standard_Integer HashCode (const Standard_ExtString theExtString, const Standard_Integer theUpperBound)
{ {
// compute SDBM hash of an ext string // compute SDBM hash of an ext string
Standard_Integer hash = 0; unsigned int hash = 0;
for (const Standard_ExtCharacter *c = Value; *c; c++)
for (const Standard_ExtCharacter* c = theExtString; *c; ++c)
{ {
/* hash = hash * 33 ^ c */ /* hash = hash * 33 ^ c */
hash = (*c) + (hash << 6) + (hash << 16) - hash; hash = (*c) + (hash << 6) + (hash << 16) - hash;
} }
return HashCode (hash, Upper); return HashCode (hash, theUpperBound);
} }

View File

@ -24,9 +24,10 @@
#include <Standard_TypeDef.hxx> #include <Standard_TypeDef.hxx>
//============================================================================ //! Computes a hash code for the given wide character string, in the range [1, theUpperBound]
//==== HashCode : Returns a HashCode ExtString //! @param theExtString the wide character string which hash code is to be computed
//============================================================================ //! @param theUpperBound the upper bound of the range a computing hash code must be within
Standard_EXPORT Standard_Integer HashCode (const Standard_ExtString, const Standard_Integer); //! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT Standard_Integer HashCode (Standard_ExtString theExtString, Standard_Integer theUpperBound);
#endif #endif

View File

@ -388,9 +388,13 @@ void Standard_GUID::ShallowDump(Standard_OStream& aStream) const
aStream << sguid; aStream << sguid;
} }
Standard_Integer Standard_GUID::HashCode(const Standard_GUID& aGuid,const Standard_Integer Upper) //============================================================================
// function : HashCode
// purpose :
//============================================================================
Standard_Integer Standard_GUID::HashCode (const Standard_GUID& theGuid, const Standard_Integer theUpperBound)
{ {
return aGuid.Hash(Upper); return theGuid.Hash (theUpperBound);
} }
Standard_Integer Standard_GUID::Hash(const Standard_Integer Upper) const Standard_Integer Standard_GUID::Hash(const Standard_Integer Upper) const

View File

@ -112,9 +112,12 @@ void operator = (const Standard_UUID& uid)
//! Hash function for GUID. //! Hash function for GUID.
Standard_EXPORT Standard_Integer Hash (const Standard_Integer Upper) const; Standard_EXPORT Standard_Integer Hash (const Standard_Integer Upper) const;
//! H method used by collections. //! Computes a hash code for the given GUID of the Standard_Integer type, in the range [1, theUpperBound]
Standard_EXPORT static Standard_Integer HashCode (const Standard_GUID& aguid, const Standard_Integer Upper); //! @param theGUID the GUID which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT static Standard_Integer HashCode (const Standard_GUID& theGUID, Standard_Integer theUpperBound);
//! Returns True when the two GUID are the same. //! Returns True when the two GUID are the same.
Standard_EXPORT static Standard_Boolean IsEqual (const Standard_GUID& string1, const Standard_GUID& string2); Standard_EXPORT static Standard_Boolean IsEqual (const Standard_GUID& string1, const Standard_GUID& string2);

View File

@ -15,67 +15,15 @@
#define _Standard_Handle_HeaderFile #define _Standard_Handle_HeaderFile
#include <Standard_Address.hxx> #include <Standard_Address.hxx>
#include <Standard_Std.hxx>
#include <Standard_Stream.hxx> #include <Standard_Stream.hxx>
#include <Standard_Transient.hxx> #include <Standard_Transient.hxx>
#include <type_traits>
class Standard_Transient; class Standard_Transient;
//! Namespace opencascade is intended for low-level template classes and functions //! Namespace opencascade is intended for low-level template classes and functions
namespace opencascade { namespace opencascade {
//! Namespace opencascade::std includes templates from C++11 std namespace used by
//! OCCT classes. These definitions are imported from std namespace, plus (on older
//! compilers) from std::tr1, or implemented by custom code where neither std
//! not std::tr1 provide necessary definitions.
namespace std
{
// import all available standard stuff from std namespace
using namespace ::std;
// for old MSVC compiler, some standard templates are defined in std::tr1 namespace,
// and some missing ones are implemented here
#if(defined(_MSC_VER) && (_MSC_VER < 1600))
using namespace ::std::tr1;
// C++11 template class enable_if
template<bool Test, class Type = void>
struct enable_if
{// type is undefined for assumed !_Test
};
template<class _Type>
struct enable_if<true, _Type>
{// type is _Type for _Test
typedef _Type type;
};
template<bool Condition, typename TypeTrue, typename TypeFalse>
struct conditional
{
typedef TypeTrue type;
};
template<typename TypeTrue, typename TypeFalse>
struct conditional<false, TypeTrue, TypeFalse>
{
typedef TypeFalse type;
};
#endif
} // namespace opencascade::std
//! Trait yielding true if class T1 is base of T2 but not the same
template <class T1, class T2, class Dummy = void>
struct is_base_but_not_same : opencascade::std::is_base_of <T1, T2> {};
//! Explicit specialization of is_base_of trait to workaround the
//! requirement of type to be complete when T1 and T2 are the same.
template <class T1, class T2>
struct is_base_but_not_same <T1, T2, typename opencascade::std::enable_if <opencascade::std::is_same <T1, T2>::value>::type> : opencascade::std::false_type {};
//! Intrusive smart pointer for use with Standard_Transient class and its descendants. //! Intrusive smart pointer for use with Standard_Transient class and its descendants.
//! //!
//! This class is similar to boost::intrusive_ptr<>. The reference counter //! This class is similar to boost::intrusive_ptr<>. The reference counter
@ -462,11 +410,15 @@ namespace opencascade {
//! Define Handle() macro //! Define Handle() macro
#define Handle(Class) opencascade::handle<Class> #define Handle(Class) opencascade::handle<Class>
//! Global method HashCode(), for use in hash maps //! Computes a hash code for the standard handle, in the range [1, theUpperBound]
template <class T> //! @param TheTransientType the type of the object the handle is referred to
inline Standard_Integer HashCode (const Handle(T)& theHandle, const Standard_Integer theUpper) //! @param theHandle the standard handle which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
template <class TheTransientType>
Standard_Integer HashCode (const Handle (TheTransientType) & theHandle, const Standard_Integer theUpperBound)
{ {
return ::HashCode (const_cast<Standard_Address>(static_cast<const void*>(theHandle.get())), theUpper); return ::HashCode (theHandle.get(), theUpperBound);
} }
//! For compatibility with previous versions of OCCT, define Handle_Class alias for opencascade::handle<Class>. //! For compatibility with previous versions of OCCT, define Handle_Class alias for opencascade::handle<Class>.

View File

@ -15,6 +15,7 @@
#ifndef _Standard_Integer_HeaderFile #ifndef _Standard_Integer_HeaderFile
#define _Standard_Integer_HeaderFile #define _Standard_Integer_HeaderFile
#include <Standard_Std.hxx>
#include <Standard_TypeDef.hxx> #include <Standard_TypeDef.hxx>
#include <Standard_values.h> #include <Standard_values.h>
@ -30,54 +31,6 @@ inline Standard_Integer Abs (const Standard_Integer Value)
return Value >= 0 ? Value : -Value; return Value >= 0 ? Value : -Value;
} }
// ------------------------------------------------------------------
// Hascode : Computes a hascoding value for a given Integer
// ------------------------------------------------------------------
inline Standard_Integer HashCode (const Standard_Integer theMe,
const Standard_Integer theUpper)
{
//return (Abs (theMe) % theUpper) + 1;
return ((theMe & 0x7fffffff ) % theUpper) + 1;
}
// ------------------------------------------------------------------
// IsEqual : Returns Standard_True if two integers are equal
// ------------------------------------------------------------------
inline Standard_Boolean IsEqual (const Standard_Integer theOne,
const Standard_Integer theTwo)
{
return theOne == theTwo;
}
// ------------------------------------------------------------------
// Hascode : Computes a hascoding value for a given long long integer
// ------------------------------------------------------------------
inline Standard_Integer HashCode(const long long int theMe,
const Standard_Integer theUpper)
{
return ((theMe & 0x7fffffffffffffff) % theUpper) + 1;
}
#if (defined(_LP64) || defined(__LP64__) || defined(_WIN64)) || defined(__APPLE__)
// ------------------------------------------------------------------
// Hascode : Computes a hascoding value for a given unsigned integer
// ------------------------------------------------------------------
inline Standard_Integer HashCode (const Standard_Utf32Char theMe,
const Standard_Integer theUpper)
{
return ((theMe & 0x7fffffff ) % theUpper) + 1;
}
// ------------------------------------------------------------------
// IsEqual : Returns Standard_True if two integers are equal
// ------------------------------------------------------------------
inline Standard_Boolean IsEqual (const Standard_Utf32Char theOne,
const Standard_Utf32Char theTwo)
{
return theOne == theTwo;
}
#endif
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// IsEven : Returns Standard_True if an integer is even // IsEven : Returns Standard_True if an integer is even
// ------------------------------------------------------------------ // ------------------------------------------------------------------
@ -140,4 +93,87 @@ inline Standard_Integer IntegerLast()
inline Standard_Integer IntegerSize() inline Standard_Integer IntegerSize()
{ return BITS(Standard_Integer); } { return BITS(Standard_Integer); }
//! Computes a hash code for the given value of some integer type, in range [1, theUpperBound]
//! @tparam TheInteger the type of the integer which hash code is to be computed
//! @param theValue the value of the TheInteger type which hash code is to be computed
//! @param theMask the mask for the last bits of the value that are used in the computation of a hash code
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in range [1, theUpperBound]
template <typename TheInteger>
typename opencascade::std::enable_if<opencascade::is_integer<TheInteger>::value, Standard_Integer>::type
IntegerHashCode (const TheInteger theValue,
const typename opencascade::disable_deduction<TheInteger>::type theMask,
const Standard_Integer theUpperBound)
{
return static_cast<Standard_Integer> ((theValue & theMask) % theUpperBound + 1);
}
//! Computes a hash code for the given value of the Standard_Integer type, in range [1, theUpperBound]
//! @param theValue the value of the Standard_Integer type which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in range [1, theUpperBound]
inline Standard_Integer HashCode (const Standard_Integer theValue,
const Standard_Integer theUpperBound)
{
// return (Abs (theMe) % theUpper) + 1;
return IntegerHashCode(theValue, IntegerLast(), theUpperBound);
}
// ------------------------------------------------------------------
// IsEqual : Returns Standard_True if two integers are equal
// ------------------------------------------------------------------
inline Standard_Boolean IsEqual (const Standard_Integer theOne,
const Standard_Integer theTwo)
{
return theOne == theTwo;
}
//! Computes a hash value for the given unsigned integer, in range [1, theUpperBound]
//! @tparam TheUnsignedInteger the type of the given value (it is "unsigned int",
//! and must not be the same as Standard_Size, because the overload of the HashCode function
//! for Standard_Size type is already presented in Standard_Size.hxx)
//! @param theValue the unsigned integer which hash code is to be computed
//! @return a hash value computed for the given unsigned integer, in range [1, theUpperBound]
template <typename TheUnsignedInteger>
typename opencascade::std::enable_if<!opencascade::std::is_same<Standard_Size, unsigned int>::value
&& opencascade::std::is_same<TheUnsignedInteger, unsigned int>::value,
Standard_Integer>::type
HashCode (const TheUnsignedInteger theValue, const Standard_Integer theUpperBound)
{
return HashCode (static_cast<Standard_Integer> (theValue), theUpperBound);
}
//! Computes a hash code for the given value of the "long long int" type, in range [1, theUpperBound]
//! @param theValue the value of the "long long int" type which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in range [1, theUpperBound]
inline Standard_Integer HashCode (const long long int theValue, const Standard_Integer theUpperBound)
{
return IntegerHashCode(theValue, 0x7fffffffffffffff, theUpperBound);
}
#if (defined(_LP64) || defined(__LP64__) || defined(_WIN64)) || defined(__APPLE__)
//! Computes a hash code for the given value of the Standard_Utf32Char type, in range [1, theUpperBound]
//! @param theValue the value of the Standard_Utf32Char type which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in range [1, theUpperBound]
inline Standard_Integer HashCode (const Standard_Utf32Char theValue,
const Standard_Integer theUpperBound)
{
return IntegerHashCode(theValue, IntegerLast(), theUpperBound);
}
// ------------------------------------------------------------------
// IsEqual : Returns Standard_True if two integers are equal
// ------------------------------------------------------------------
inline Standard_Boolean IsEqual (const Standard_Utf32Char theOne,
const Standard_Utf32Char theTwo)
{
return theOne == theTwo;
}
#endif
#endif #endif

View File

@ -22,23 +22,27 @@
static const Standard_Real ACosLimit = 1. + Epsilon(1.); static const Standard_Real ACosLimit = 1. + Epsilon(1.);
// ------------------------------------------------------------------ //============================================================================
// Hascode : Computes a hascoding value for a given real // function : HashCode
// ------------------------------------------------------------------ // purpose :
Standard_Integer HashCode(const Standard_Real me, const Standard_Integer Upper) //============================================================================
Standard_Integer HashCode (const Standard_Real theReal, const Standard_Integer theUpperBound)
{ {
if (Upper < 1){ if (theUpperBound < 1)
throw Standard_RangeError("Try to apply HashCode method with negative or null argument."); {
throw Standard_RangeError ("Try to apply HashCode method with negative or null argument.");
} }
union union
{ {
Standard_Real R; Standard_Real R;
Standard_Integer I[2]; Standard_Integer I[2];
} U; } U;
// U.R = Abs(me); // Treat me = -0.0 ADN 27/11/97
U.R = me ; // U.R = Abs(me); // Treat me = -0.0 ADN 27/11/97
return HashCode( ( U.I[0] ^ U.I[1] ) , Upper ) ; U.R = theReal;
}
return HashCode (U.I[0] ^ U.I[1], theUpperBound);
}
//------------------------------------------------------------------- //-------------------------------------------------------------------
// ACos : Returns the value of the arc cosine of a real // ACos : Returns the value of the arc cosine of a real

View File

@ -30,7 +30,12 @@
// ================================== // ==================================
// Methods implemeted in Standard_Real.cxx // Methods implemeted in Standard_Real.cxx
// ================================== // ==================================
Standard_EXPORT Standard_Integer HashCode (const Standard_Real, const Standard_Integer);
//! Computes a hash code for the given real, in the range [1, theUpperBound]
//! @param theReal the real value which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT Standard_Integer HashCode (Standard_Real theReal, Standard_Integer theUpperBound);
Standard_EXPORT Standard_Real ACos (const Standard_Real ); Standard_EXPORT Standard_Real ACos (const Standard_Real );
Standard_EXPORT Standard_Real ACosApprox (const Standard_Real ); Standard_EXPORT Standard_Real ACosApprox (const Standard_Real );

View File

@ -18,19 +18,22 @@
#include <Standard_Stream.hxx> #include <Standard_Stream.hxx>
#include <Standard_OStream.hxx> #include <Standard_OStream.hxx>
// ------------------------------------------------------------------ //============================================================================
// Hascode : Computes a hascoding value for a given ShortReal // function : HashCode
// ------------------------------------------------------------------ // purpose :
Standard_Integer HashCode(const Standard_ShortReal me, const Standard_Integer Upper) //============================================================================
Standard_Integer HashCode (const Standard_ShortReal theShortReal, const Standard_Integer theUpperBound)
{ {
if (Upper < 1){ if (theUpperBound < 1)
throw Standard_RangeError("Try to apply HashCode method with negative or null argument."); {
throw Standard_RangeError ("Try to apply HashCode method with negative or null argument.");
} }
union union
{ {
Standard_ShortReal R; Standard_ShortReal R;
Standard_Integer I; Standard_Integer I;
} U; } U;
U.R = me; U.R = theShortReal;
return HashCode( U.I , Upper) ;
return HashCode (U.I, theUpperBound);
} }

View File

@ -138,7 +138,12 @@ inline Standard_ShortReal Min (const Standard_ShortReal Val1,
// ================================== // ==================================
// Methods implemeted in Standard_ShortReal.cxx // Methods implemeted in Standard_ShortReal.cxx
// ================================== // ==================================
Standard_EXPORT Standard_Integer HashCode (const Standard_ShortReal, const Standard_Integer);
//! Computes a hash code for the given short real, in the range [1, theUpperBound]
//! @param theShortReal the short real value which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT Standard_Integer HashCode (Standard_ShortReal theShortReal, Standard_Integer theUpperBound);
//------------------------------------------------------------------- //-------------------------------------------------------------------
// IsEqual : Returns Standard_True if two ShortReals are equal // IsEqual : Returns Standard_True if two ShortReals are equal

View File

@ -16,21 +16,23 @@
#ifndef _Standard_Size_HeaderFile #ifndef _Standard_Size_HeaderFile
#define _Standard_Size_HeaderFile #define _Standard_Size_HeaderFile
#include <Standard_Integer.hxx>
// msv 26.05.2009: add HashCode and IsEqual functions // msv 26.05.2009: add HashCode and IsEqual functions
// ------------------------------------------------------------------ //! Computes a hash code for the given value of the Standard_Size type, in the range [1, theUpperBound]
// Hascode : Computes a hashcoding value for a given value //! @param theValue the value of the Standard_Size type which hash code is to be computed
// ------------------------------------------------------------------ //! @param theUpperBound the upper bound of the range a computing hash code must be within
inline Standard_Integer HashCode(const Standard_Size Val, //! @return a computed hash code, in the range [1, theUpperBound]
const Standard_Integer Upper) inline Standard_Integer HashCode (const Standard_Size theValue, const Standard_Integer theUpperBound)
{ {
Standard_Size aKey = ~Val + (Val << 18); Standard_Size aKey = ~theValue + (theValue << 18);
aKey ^= (aKey >> 31); aKey ^= (aKey >> 31);
aKey *= 21; aKey *= 21;
aKey ^= (aKey >> 11); aKey ^= (aKey >> 11);
aKey += (aKey << 6); aKey += (aKey << 6);
aKey ^= (aKey >> 22); aKey ^= (aKey >> 22);
return (Standard_Integer(aKey & 0x7fffffff) % Upper) + 1; return IntegerHashCode(aKey, IntegerLast(), theUpperBound);
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@ -0,0 +1,106 @@
// Created on: 2019-03-27
// Created by: Timur Izmaylov
// Copyright (c) 2019 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 _Standard_Std_HeaderFile
#define _Standard_Std_HeaderFile
#include <type_traits>
//! Namespace opencascade is intended for low-level template classes and functions
namespace opencascade
{
//! Namespace opencascade::std includes templates from C++11 std namespace used by
//! OCCT classes. These definitions are imported from std namespace, plus (on older
//! compilers) from std::tr1, or implemented by custom code where neither std
//! not std::tr1 provide necessary definitions.
namespace std
{
// import all available standard stuff from std namespace
using namespace ::std;
// for old MSVC compiler, some standard templates are defined in std::tr1 namespace,
// and some missing ones are implemented here
#if (defined(_MSC_VER) && (_MSC_VER < 1600))
using namespace ::std::tr1;
// C++11 template class enable_if
template <bool Test, class Type = void>
struct enable_if
{ // type is undefined for assumed !_Test
};
template <class _Type>
struct enable_if<true, _Type>
{ // type is _Type for _Test
typedef _Type type;
};
template <bool Condition, typename TypeTrue, typename TypeFalse>
struct conditional
{
typedef TypeTrue type;
};
template <typename TypeTrue, typename TypeFalse>
struct conditional<false, TypeTrue, TypeFalse>
{
typedef TypeFalse type;
};
#endif
} // namespace std
//! Trait yielding true if class T1 is base of T2 but not the same
template <class T1, class T2, class Dummy = void>
struct is_base_but_not_same : opencascade::std::is_base_of<T1, T2>
{
};
//! Explicit specialization of is_base_of trait to workaround the
//! requirement of type to be complete when T1 and T2 are the same.
template <class T1, class T2>
struct is_base_but_not_same<T1,
T2,
typename opencascade::std::enable_if<opencascade::std::is_same<T1, T2>::value>::type>
: opencascade::std::false_type
{
};
//! The type trait that checks if the passed type is integer (it must be integral and not boolean)
//! @tparam TheInteger the checked type
template <typename TheInteger>
struct is_integer : std::integral_constant<bool,
opencascade::std::is_integral<TheInteger>::value
&& !opencascade::std::is_same<TheInteger, bool>::value>
{
};
//! The auxiliary template that is used for template argument deduction in function templates. A function argument
//! which type is a template type parameter and it is not needed to be deducted must be declared using this class
//! template based on the type of some other template type parameter of a function template
//! @tparam TheType the type that is used as a function argument type to prevent its deduction
template <typename TheType>
struct disable_deduction
{
typedef TheType type;
};
} // namespace opencascade
#endif

View File

@ -16,25 +16,9 @@
#ifndef Standard_ThreadId_HeaderFile #ifndef Standard_ThreadId_HeaderFile
#define Standard_ThreadId_HeaderFile #define Standard_ThreadId_HeaderFile
// Platform-dependent definition of the thread identifier type #include <Standard_Size.hxx>
#ifdef _WIN32 // Platform-independent definition of the thread identifier type
typedef Standard_Size Standard_ThreadId;
#include <windows.h>
typedef DWORD Standard_ThreadId;
inline Standard_Integer HashCode(const Standard_ThreadId Value,
const Standard_Integer Upper)
{
// Size of int == size of unsigned long == 4 for WIN32 and WIN64
return HashCode((Standard_Integer)Value, Upper);
}
#else
#include <pthread.h>
typedef pthread_t Standard_ThreadId;
#endif
#endif #endif

View File

@ -105,10 +105,15 @@ private:
mutable volatile Standard_Integer count; mutable volatile Standard_Integer count;
}; };
//! Global method HashCode(), for use in hash maps
inline Standard_Integer HashCode (const Standard_Transient* theObject, const Standard_Integer theUpper) //! Computes a hash code for the given transient object, in the range [1, theUpperBound]
//! @param theTransientObject the transient object which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const Standard_Transient* const theTransientObject,
const Standard_Integer theUpperBound)
{ {
return ::HashCode ((Standard_Address*)theObject, theUpper); return ::HashCode (static_cast<const void*> (theTransientObject), theUpperBound);
} }
//! Definition of Handle_Standard_Transient as typedef for compatibility //! Definition of Handle_Standard_Transient as typedef for compatibility

View File

@ -74,9 +74,13 @@ namespace {
// Value-based hasher for plain C string (char*) // Value-based hasher for plain C string (char*)
struct CStringHasher struct CStringHasher
{ {
static Standard_Integer HashCode (const Standard_CString& theKey, const Standard_Integer Upper) //! Computes a hash code of the given Standard_CString, in the range [1, theUpperBound]
//! @param theKey the key which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const Standard_CString& theKey, const Standard_Integer theUpperBound)
{ {
return ::HashCode (theKey, Upper); return ::HashCode (theKey, theUpperBound);
} }
static bool IsEqual (const Standard_CString& theKey1, const Standard_CString& theKey2) static bool IsEqual (const Standard_CString& theKey1, const Standard_CString& theKey2)
{ {

View File

@ -19,13 +19,14 @@
#include <StepToTopoDS_CartesianPointHasher.hxx> #include <StepToTopoDS_CartesianPointHasher.hxx>
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
Standard_Integer StepToTopoDS_CartesianPointHasher::HashCode Standard_Integer StepToTopoDS_CartesianPointHasher::HashCode (const Handle (StepGeom_CartesianPoint)
(const Handle(StepGeom_CartesianPoint)& K, const Standard_Integer Upper) & theCartesianPoint,
const Standard_Integer theUpperBound)
{ {
return ::HashCode(K,Upper); return ::HashCode (theCartesianPoint, theUpperBound);
} }
//======================================================================= //=======================================================================

View File

@ -33,10 +33,13 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the cartesian point, in the range [1, theUpperBound]
//! Returns a HasCode value for the CartesianPoint //! @param theCartesianPoint the cartesian point which hash code is to be computed
Standard_EXPORT static Standard_Integer HashCode (const Handle(StepGeom_CartesianPoint)& K, const Standard_Integer Upper); //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT static Standard_Integer HashCode (const Handle (StepGeom_CartesianPoint) & theCartesianPoint,
Standard_Integer theUpperBound);
//! Returns True when the two CartesianPoint are the same //! Returns True when the two CartesianPoint are the same
Standard_EXPORT static Standard_Boolean IsEqual (const Handle(StepGeom_CartesianPoint)& K1, const Handle(StepGeom_CartesianPoint)& K2); Standard_EXPORT static Standard_Boolean IsEqual (const Handle(StepGeom_CartesianPoint)& K1, const Handle(StepGeom_CartesianPoint)& K2);

View File

@ -20,13 +20,14 @@
#include <StepToTopoDS_PointPairHasher.hxx> #include <StepToTopoDS_PointPairHasher.hxx>
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
Standard_Integer StepToTopoDS_PointPairHasher::HashCode Standard_Integer StepToTopoDS_PointPairHasher::HashCode (const StepToTopoDS_PointPair& thePointPair,
(const StepToTopoDS_PointPair& P, const Standard_Integer Upper) const Standard_Integer theUpperBound)
{ {
return (::HashCode(P.myP1,Upper) + ::HashCode(P.myP2,Upper)) % Upper; return ::HashCode (::HashCode (thePointPair.myP1, theUpperBound) + ::HashCode (thePointPair.myP2, theUpperBound),
theUpperBound);
} }
//======================================================================= //=======================================================================

View File

@ -33,9 +33,11 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the point pair, in the range [1, theUpperBound]
//! Returns a HasCode value for the PointPair //! @param thePointPair the point pair which hash code is to be computed
Standard_EXPORT static Standard_Integer HashCode (const StepToTopoDS_PointPair& K, const Standard_Integer Upper); //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT static Standard_Integer HashCode (const StepToTopoDS_PointPair& thePointPair, Standard_Integer theUpperBound);
//! Returns True when the two PointPair are the same //! Returns True when the two PointPair are the same
Standard_EXPORT static Standard_Boolean IsEqual (const StepToTopoDS_PointPair& K1, const StepToTopoDS_PointPair& K2); Standard_EXPORT static Standard_Boolean IsEqual (const StepToTopoDS_PointPair& K1, const StepToTopoDS_PointPair& K2);

View File

@ -79,12 +79,12 @@ public:
*/ */
Standard_Integer FindNext (unsigned int& theMask) const; Standard_Integer FindNext (unsigned int& theMask) const;
/** //! Computes a hash code for this map in the range [1, theUpperBound]
* Support of Map interface. //! @param theUpperBound the upper bound of the range a computing hash code must be within
*/ //! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const Standard_Integer theUpper) const inline Standard_Integer HashCode (const Standard_Integer theUpperBound) const
{ {
return ::HashCode (Standard_Integer(myMask >> 5), theUpper); return ::HashCode (myMask >> 5, theUpperBound);
} }
/** /**

View File

@ -679,10 +679,13 @@ friend Standard_EXPORT Standard_IStream& operator >> (Standard_IStream& astream,
//! aString.Value(2) returns 'e' //! aString.Value(2) returns 'e'
Standard_EXPORT Standard_Character Value (const Standard_Integer where) const; Standard_EXPORT Standard_Character Value (const Standard_Integer where) const;
//! Hash function for AsciiString //! Computes a hash code for the given ASCII string, in the range [1, theUpperBound].
//! (returns the same Integer value that the hash function for ExtendedString) //! Returns the same integer value as the hash function for TCollection_ExtendedString
static Standard_Integer HashCode (const TCollection_AsciiString& astring, const Standard_Integer Upper); //! @param theAsciiString the ASCII string which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const TCollection_AsciiString& theAsciiString, Standard_Integer theUpperBound);
//! Returns True when the two strings are the same. //! Returns True when the two strings are the same.
//! (Just for HashCode for AsciiString) //! (Just for HashCode for AsciiString)
static Standard_Boolean IsEqual (const TCollection_AsciiString& string1, const TCollection_AsciiString& string2); static Standard_Boolean IsEqual (const TCollection_AsciiString& string1, const TCollection_AsciiString& string2);

View File

@ -15,14 +15,15 @@
#include <Standard_OutOfRange.hxx> #include <Standard_OutOfRange.hxx>
#include <Standard_CString.hxx> #include <Standard_CString.hxx>
//definition global methods for using in NCollection // definition global methods for using in NCollection
//------------------------------------------------------------------------
// HashCode //! Computes a hash code for the given ASCII string, in the range [1, theUpperBound]
//------------------------------------------------------------------------ //! @param theAsciiString the ASCII string which hash code is to be computed
inline Standard_Integer HashCode(const TCollection_AsciiString& astring, //! @param theUpperBound the upper bound of the range a computing hash code must be within
const Standard_Integer Upper) //! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const TCollection_AsciiString& theAsciiString, const Standard_Integer theUpperBound)
{ {
return TCollection_AsciiString::HashCode(astring,Upper); return TCollection_AsciiString::HashCode (theAsciiString, theUpperBound);
} }
@ -78,13 +79,14 @@ inline TCollection_AsciiString TCollection_AsciiString::Cat(const Standard_Real
return TCollection_AsciiString( *this , TCollection_AsciiString(other) ) ; return TCollection_AsciiString( *this , TCollection_AsciiString(other) ) ;
} }
//------------------------------------------------------------------------ //============================================================================
// HashCode // function : HashCode
//------------------------------------------------------------------------ // purpose :
inline Standard_Integer TCollection_AsciiString::HashCode(const TCollection_AsciiString& astring, //============================================================================
const Standard_Integer Upper) inline Standard_Integer TCollection_AsciiString::HashCode (const TCollection_AsciiString& theAsciiString,
const Standard_Integer theUpperBound)
{ {
return ::HashCode(astring.ToCString(),Upper); return ::HashCode (theAsciiString.ToCString(), theAsciiString.Length(), theUpperBound);
} }

View File

@ -335,13 +335,16 @@ friend Standard_EXPORT Standard_OStream& operator << (Standard_OStream& astream,
//! the bounds of this extended string. //! the bounds of this extended string.
Standard_EXPORT Standard_ExtCharacter Value (const Standard_Integer where) const; Standard_EXPORT Standard_ExtCharacter Value (const Standard_Integer where) const;
//! Returns a hashed value for the extended string within the range 1..theUpper. //! Returns a hashed value for the extended string within the range 1 .. theUpper.
//! Note: if string is ASCII, the computed value is the same as the value computed with the HashCode function on a //! Note: if string is ASCII, the computed value is the same as the value computed with the HashCode function on a
//! TCollection_AsciiString string composed with equivalent ASCII characters. //! TCollection_AsciiString string composed with equivalent ASCII characters.
//! @param theExtendedString the extended string which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const TCollection_ExtendedString& theString, static Standard_Integer HashCode (const TCollection_ExtendedString& theString,
const Standard_Integer theUpper) const Standard_Integer theUpperBound)
{ {
return ::HashCode (theString.ToExtString(), theUpper); return ::HashCode (theString.ToExtString(), theUpperBound);
} }
//! Returns true if the characters in this extended //! Returns true if the characters in this extended
@ -376,11 +379,14 @@ private:
}; };
//! Compute hash code for extended string //! Computes a hash code for the given extended string, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const TCollection_ExtendedString& theString, //! @param theExtendedString the extended string which hash code is to be computed
const Standard_Integer theUpper) //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const TCollection_ExtendedString& theExtendedString,
const Standard_Integer theUpperBound)
{ {
return TCollection_ExtendedString::HashCode (theString, theUpper); return TCollection_ExtendedString::HashCode (theExtendedString, theUpperBound);
} }
#endif // _TCollection_ExtendedString_HeaderFile #endif // _TCollection_ExtendedString_HeaderFile

View File

@ -22,11 +22,13 @@
class TDF_LabelMapHasher class TDF_LabelMapHasher
{ {
public: public:
//! Computes a hash code for the given label, in the range [1, theUpperBound]
//! Returns a HasCode value for the Key <K> in the range 0..Upper. //! @param theLabel the label which hash code is to be computed
static Standard_Integer HashCode(const TDF_Label& aLab, const Standard_Integer Upper) //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode(const TDF_Label& theLabel, const Standard_Integer theUpperBound)
{ {
return ::HashCode((Standard_Address)aLab.myLabelNode, Upper); return ::HashCode(theLabel.myLabelNode, theUpperBound);
} }
//! Returns True when the two keys are the same. Two //! Returns True when the two keys are the same. Two

View File

@ -31,10 +31,14 @@
//! Methods inline implimentation for HExtendedString //! Methods inline implimentation for HExtendedString
inline Standard_Integer HashCode (const Handle(TCollection_HExtendedString)& theStr, //! Computes a hash code for the given handle referred to extended string, in the range [1, theUpperBound]
const Standard_Integer theBnd) //! @param theHExtendedString the handle referred to extended string which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const Handle (TCollection_HExtendedString) & theHExtendedString,
const Standard_Integer theUpperBound)
{ {
return TCollection_ExtendedString::HashCode(theStr->String(), theBnd); return TCollection_ExtendedString::HashCode (theHExtendedString->String(), theUpperBound);
} }
inline Standard_Boolean IsEqual (const Handle(TCollection_HExtendedString)& theStr1, inline Standard_Boolean IsEqual (const Handle(TCollection_HExtendedString)& theStr1,

View File

@ -169,11 +169,10 @@ TopLoc_Location TopLoc_Location::Powered (const Standard_Integer pwr) const
} }
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
Standard_Integer TopLoc_Location::HashCode (const Standard_Integer theUpperBound) const
Standard_Integer TopLoc_Location::HashCode(const Standard_Integer upper) const
{ {
// the HashCode computed for a Location is the bitwise exclusive or // the HashCode computed for a Location is the bitwise exclusive or
// of values computed for each element of the list // of values computed for each element of the list
@ -186,18 +185,19 @@ Standard_Integer TopLoc_Location::HashCode(const Standard_Integer upper) const
// this value is biwise rotated by depth // this value is biwise rotated by depth
// the use of depth avoids getting the same result for two permutated lists. // the use of depth avoids getting the same result for two permutated lists.
Standard_Integer depth = 0; Standard_Integer depth = 0;
unsigned int h = 0; unsigned int h = 0;
TopLoc_SListOfItemLocation items = myItems; TopLoc_SListOfItemLocation items = myItems;
while (items.More()) { while (items.More())
{
depth += 3; depth += 3;
unsigned int i = ::HashCode (items.Value().myDatum, upper); unsigned int i = ::HashCode (items.Value().myDatum, theUpperBound);
unsigned int j = ( (i + items.Value().myPower) <<depth); unsigned int j = ((i + items.Value().myPower) << depth);
j = j>>(32-depth) | j<<depth; j = j >> (32 - depth) | j << depth;
h ^= j; h ^= j;
items.Next(); items.Next ();
} }
return h % upper; return ::HashCode (h, theUpperBound);
} }
//======================================================================= //=======================================================================

View File

@ -115,11 +115,12 @@ Standard_NODISCARD TopLoc_Location operator/ (const TopLoc_Location& Other) cons
//! returns Identity. <pwr> can be lower than zero //! returns Identity. <pwr> can be lower than zero
//! (usual meaning for powers). //! (usual meaning for powers).
Standard_EXPORT Standard_NODISCARD TopLoc_Location Powered (const Standard_Integer pwr) const; Standard_EXPORT Standard_NODISCARD TopLoc_Location Powered (const Standard_Integer pwr) const;
//! Returns a hashed value for this local coordinate system. //! Returns a hashed value for this local coordinate system. This value is used, with map tables, to store and
//! This value is used, with map tables, to store and //! retrieve the object easily, and is in the range [1, theUpperBound].
//! retrieve the object easily, and is in the range [ 1..Upper ]. //! @param theUpperBound the upper bound of the range a computing hash code must be within
Standard_EXPORT Standard_Integer HashCode (const Standard_Integer Upper) const; //! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT Standard_Integer HashCode (Standard_Integer theUpperBound) const;
//! Returns true if this location and the location Other //! Returns true if this location and the location Other
//! have the same elementary data, i.e. contain the same //! have the same elementary data, i.e. contain the same
@ -166,9 +167,13 @@ private:
#include <TopLoc_Location.lxx> #include <TopLoc_Location.lxx>
//! Computes a hash code for the given location, in the range [1, theUpperBound]
inline Standard_Integer HashCode(const TopLoc_Location& me,const Standard_Integer Upper) { //! @param theLocation the location which hash code is to be computed
return me.HashCode(Upper); //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const TopLoc_Location& theLocation, const Standard_Integer theUpperBound)
{
return theLocation.HashCode (theUpperBound);
} }
inline void ShallowDump(const TopLoc_Location& me,Standard_OStream& S) { inline void ShallowDump(const TopLoc_Location& me,Standard_OStream& S) {

View File

@ -33,11 +33,12 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the given shape, in the range [1, theUpperBound]
//! Returns a HasCode value for the Key <K> in the //! @param theShape the shape which hash code is to be computed
//! range 0..Upper. //! @param theUpperBound the upper bound of the range a computing hash code must be within
static Standard_Integer HashCode (const TopoDS_Shape& S, const Standard_Integer Upper); //! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const TopoDS_Shape& theShape, const Standard_Integer theUpperBound);
//! Returns True when the two keys are equal. Two same //! Returns True when the two keys are equal. Two same
//! keys must have the same hashcode, the contrary is //! keys must have the same hashcode, the contrary is
//! not necessary. //! not necessary.

View File

@ -17,13 +17,13 @@
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
inline Standard_Integer TopTools_OrientedShapeMapHasher::HashCode inline Standard_Integer TopTools_OrientedShapeMapHasher::HashCode (const TopoDS_Shape& theShape,
(const TopoDS_Shape& S, const Standard_Integer Upper) const Standard_Integer theUpperBound)
{ {
return S.HashCode(Upper); return theShape.HashCode (theUpperBound);
} }
//======================================================================= //=======================================================================

View File

@ -33,11 +33,12 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Computes a hash code for the given shape, in the range [1, theUpperBound]
//! Returns a HasCode value for the Key <K> in the //! @param theShape the shape which hash code is to be computed
//! range 0..Upper. //! @param theUpperBound the upper bound of the range a computing hash code must be within
static Standard_Integer HashCode (const TopoDS_Shape& S, const Standard_Integer Upper); //! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const TopoDS_Shape& theShape, Standard_Integer theUpperBound);
//! Returns True when the two keys are the same. Two //! Returns True when the two keys are the same. Two
//! same keys must have the same hashcode, the //! same keys must have the same hashcode, the
//! contrary is not necessary. //! contrary is not necessary.

View File

@ -17,13 +17,13 @@
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
inline Standard_Integer TopTools_ShapeMapHasher::HashCode inline Standard_Integer TopTools_ShapeMapHasher::HashCode (const TopoDS_Shape& theShape,
(const TopoDS_Shape& S, const Standard_Integer Upper) const Standard_Integer theUpperBound)
{ {
return S.HashCode(Upper); return theShape.HashCode (theUpperBound);
} }
//======================================================================= //=======================================================================

View File

@ -23,14 +23,13 @@
#include <TopoDS_TShape.hxx> #include <TopoDS_TShape.hxx>
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : // purpose :
//======================================================================= //=======================================================================
Standard_Integer TopoDS_Shape::HashCode(const Standard_Integer Upper) const Standard_Integer TopoDS_Shape::HashCode (const Standard_Integer theUpperBound) const
{ {
//PKV // PKV
const Standard_Integer aI = (Standard_Integer) ptrdiff_t(myTShape.get()); const Standard_Integer aHS = ::HashCode (myTShape.get(), theUpperBound);
const Standard_Integer aHS = ::HashCode(aI,Upper); const Standard_Integer aHL = myLocation.HashCode (theUpperBound);
const Standard_Integer aHL = myLocation.HashCode(Upper); return ::HashCode (aHS ^ aHL, theUpperBound);
return (aHS^aHL)%Upper; }
}

View File

@ -232,11 +232,11 @@ public:
Standard_Boolean IsNotEqual (const TopoDS_Shape& theOther) const { return !IsEqual (theOther); } Standard_Boolean IsNotEqual (const TopoDS_Shape& theOther) const { return !IsEqual (theOther); }
Standard_Boolean operator != (const TopoDS_Shape& theOther) const { return IsNotEqual (theOther); } Standard_Boolean operator != (const TopoDS_Shape& theOther) const { return IsNotEqual (theOther); }
//! Returns a hashed value denoting <me>. This value //! Returns a hashed value denoting <me>. This value is in the range [1, theUpperBound]. It is computed from the
//! is in the range 1..<Upper>. It is computed from //! TShape and the Location. The Orientation is not used.
//! the TShape and the Location. The Orientation is //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! not used. //! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT Standard_Integer HashCode (const Standard_Integer Upper) const; Standard_EXPORT Standard_Integer HashCode (Standard_Integer theUpperBound) const;
//! Replace <me> by a new Shape with the same //! Replace <me> by a new Shape with the same
//! Orientation and Location and a new TShape with the //! Orientation and Location and a new TShape with the
@ -263,8 +263,13 @@ private:
}; };
inline Standard_Integer HashCode(const TopoDS_Shape& me,const Standard_Integer Upper) { //! Computes a hash code for the given shape, in the range [1, theUpperBound]
return me.HashCode(Upper); //! @param theShape the shape which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
inline Standard_Integer HashCode (const TopoDS_Shape& theShape, const Standard_Integer theUpperBound)
{
return theShape.HashCode (theUpperBound);
} }
#endif // _TopoDS_Shape_HeaderFile #endif // _TopoDS_Shape_HeaderFile

View File

@ -15,10 +15,15 @@
#include <Transfer_Finder.hxx> #include <Transfer_Finder.hxx>
#include <Transfer_FindHasher.hxx> #include <Transfer_FindHasher.hxx>
Standard_Integer Transfer_FindHasher::HashCode
(const Handle(Transfer_Finder)& K, const Standard_Integer Upper) //============================================================================
// function : HashCode
// purpose :
//============================================================================
Standard_Integer Transfer_FindHasher::HashCode (const Handle (Transfer_Finder) & theFinder,
const Standard_Integer theUpperBound)
{ {
return ((K->GetHashCode() - 1) % Upper) + 1; return ::HashCode (theFinder->GetHashCode() - 1, theUpperBound);
} }
Standard_Boolean Transfer_FindHasher::IsEqual Standard_Boolean Transfer_FindHasher::IsEqual

View File

@ -39,11 +39,14 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Returns a HashCode in the range <0,Upper> for a Finder : //! Returns hash code for the given finder, in the range [1, theUpperBound].
//! asks the Finder its HashCode then transforms it to be in the //! Asks the finder its hash code, then transforms it to be in the required range
//! required range //! @param theFinder the finder which hash code is to be computed
Standard_EXPORT static Standard_Integer HashCode (const Handle(Transfer_Finder)& K, const Standard_Integer Upper); //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT static Standard_Integer HashCode (const Handle (Transfer_Finder) & theFinder,
Standard_Integer theUpperBound);
//! Returns True if two keys are the same. //! Returns True if two keys are the same.
//! The test does not work on the Finders themselves but by //! The test does not work on the Finders themselves but by
//! calling their methods Equates //! calling their methods Equates

View File

@ -51,15 +51,12 @@ Standard_Boolean IsEqual (const Handle(VrmlData_Node)& theOne,
} }
//======================================================================= //=======================================================================
//function : HashCode // function : HashCode
//purpose : Global method // purpose : Global method
//======================================================================= //=======================================================================
Standard_Integer HashCode (const Handle (VrmlData_Node) & theNode, const Standard_Integer theUpperBound)
Standard_Integer HashCode(const Handle(VrmlData_Node)& theNode,
const Standard_Integer theUpper)
{ {
return (theNode->Name() == 0L ? 0 return (theNode->Name () == NULL ? 1 : HashCode (theNode->Name (), theUpperBound));
: HashCode((Standard_CString)theNode->Name(), theUpper));
} }
//======================================================================= //=======================================================================

View File

@ -201,8 +201,12 @@ class VrmlData_Node : public Standard_Transient
// Definition of HANDLE object using Standard_DefineHandle.hxx // Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Node, Standard_Transient) DEFINE_STANDARD_HANDLE (VrmlData_Node, Standard_Transient)
Standard_EXPORT Standard_Integer HashCode(const Handle(VrmlData_Node)& theNode, //! Computes a hash code for the given VRML node, in the range [1, theUpperBound]
const Standard_Integer theUpper); //! @param theNode the VRML node which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
Standard_EXPORT Standard_Integer HashCode (const Handle (VrmlData_Node) & theNode, Standard_Integer theUpperBound);
Standard_EXPORT Standard_Boolean IsEqual (const Handle(VrmlData_Node)& theOne, Standard_EXPORT Standard_Boolean IsEqual (const Handle(VrmlData_Node)& theOne,
const Handle(VrmlData_Node)& theTwo); const Handle(VrmlData_Node)& theTwo);

View File

@ -79,10 +79,15 @@ public:
struct Hasher struct Hasher
{ {
static int HashCode(const XCAFDoc_AssemblyItemId& theItem,
const int upper) //! Computes a hash code for the given value of the XCAFDoc_AssemblyItemId, in range [1, theUpperBound]
//! @param theAssemblyItemId the value of the XCAFDoc_AssemblyItemId type which hash code is to be computed
//! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in range [1, theUpperBound]
static Standard_Integer HashCode (const XCAFDoc_AssemblyItemId& theAssemblyItemId,
const Standard_Integer theUpperBound)
{ {
return ::HashCode(theItem.ToString(), upper); return ::HashCode (theAssemblyItemId.ToString(), theUpperBound);
} }
static int IsEqual(const XCAFDoc_AssemblyItemId& theItem1, static int IsEqual(const XCAFDoc_AssemblyItemId& theItem1,

View File

@ -92,25 +92,27 @@ public:
return IsEqual (theOther); return IsEqual (theOther);
} }
//! Returns a HasCode value. //! Computes a hash code for the given set of styling settings, in the range [1, theUpperBound]
static Standard_Integer HashCode (const XCAFPrs_Style& theStyle, //! @param theStyle the set of styling settings which hash code is to be computed
const Standard_Integer theUpper) //! @param theUpperBound the upper bound of the range a computing hash code must be within
//! @return a computed hash code, in the range [1, theUpperBound]
static Standard_Integer HashCode (const XCAFPrs_Style& theStyle, const Standard_Integer theUpperBound)
{ {
if (!theStyle.myIsVisible) if (!theStyle.myIsVisible)
{ {
return 1; return 1;
} }
int aHashCode = 0; Standard_Integer aHashCode = 0;
if (theStyle.myHasColorSurf) if (theStyle.myHasColorSurf)
{ {
aHashCode = aHashCode ^ Quantity_ColorRGBAHasher::HashCode (theStyle.myColorSurf, theUpper); aHashCode = aHashCode ^ Quantity_ColorRGBAHasher::HashCode (theStyle.myColorSurf, theUpperBound);
} }
if (theStyle.myHasColorCurv) if (theStyle.myHasColorCurv)
{ {
aHashCode = aHashCode ^ Quantity_ColorHasher::HashCode (theStyle.myColorCurv, theUpper); aHashCode = aHashCode ^ Quantity_ColorHasher::HashCode (theStyle.myColorCurv, theUpperBound);
} }
return ((aHashCode & 0x7fffffff) % theUpper) + 1; return ::HashCode (aHashCode, theUpperBound);
} }
//! Returns True when the two keys are the same. //! Returns True when the two keys are the same.