0030550: Coding - Integer overflow in Standard_CString HashCodes
[occt.git] / src / MeshVS / MeshVS_TwoNodes.hxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef __TWO_NODES_STRUCT_HEADER__
15 #define __TWO_NODES_STRUCT_HEADER__
16
17 #ifndef _Standard_HeaderFile
18 #include <Standard.hxx>
19 #endif
20 #ifndef _Standard_Macro_HeaderFile
21 #include <Standard_Macro.hxx>
22 #endif
23
24 //! Structure containing two IDs (of nodes) for using as a key in a map
25 //! (as representation of a mesh link)
26 //!
27 struct MeshVS_TwoNodes
28 {
29   Standard_Integer First, Second;
30
31   MeshVS_TwoNodes (Standard_Integer aFirst=0, Standard_Integer aSecond=0) 
32   : First(aFirst), Second(aSecond) {}
33 };
34
35 //! Computes a hash code for two nodes, in the range [1, theUpperBound]
36 //! @param theTwoNodes the object of structure containing two IDs which hash code is to be computed
37 //! @param theUpperBound the upper bound of the range a computing hash code must be within
38 //! @return a computed hash code, in the range [1, theUpperBound]
39 inline Standard_Integer HashCode (const MeshVS_TwoNodes& theTwoNodes, const Standard_Integer theUpperBound)
40 {
41   // symmetrical with respect to theTwoNodes.First and theTwoNodes.Second
42   const Standard_Integer aKey = theTwoNodes.First + theTwoNodes.Second;
43   return HashCode (aKey, theUpperBound);
44 }
45
46 //================================================================
47 // Function : operator ==
48 // Purpose  :
49 //================================================================
50
51 inline Standard_Boolean operator==( const MeshVS_TwoNodes& obj1,
52                                     const MeshVS_TwoNodes& obj2 )
53 {
54   return ( ( obj1.First == obj2.First  ) && ( obj1.Second == obj2.Second ) ) ||
55          ( ( obj1.First == obj2.Second ) && ( obj1.Second == obj2.First  ) );
56 }
57
58 #endif