HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_EdgeHash.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GA_EdgeHash.h ( GU Library, C++)
7  *
8  * COMMENTS: This has a hash object useful for holding unordered
9  * and directed edges. It is designed to be used with the
10  * UT_HashTable class.
11  */
12 
13 #ifndef __GA_EdgeHash__
14 #define __GA_EdgeHash__
15 
16 #include "GA_API.h"
17 #include <UT/UT_Hash.h>
18 
19 #include "GA_Types.h"
20 
22 
23 // The hash key for unordered edges:
24 template <typename T>
25 class SYS_DEPRECATED_REPLACE(16.0, "SYShash") GA_EdgeHashT : public UT_Hash
26 {
27 public:
28  GA_EdgeHashT(T a, T b) : myA(a), myB(b) { orderKey(); }
29  GA_EdgeHashT(GA_EdgeHashT const &h) : UT_Hash(), myA(h.myA), myB(h.myB)
30  { orderKey(); }
31  virtual ~GA_EdgeHashT() {}
32 
33  T getA() const { return myA; }
34  T getB() const { return myB; }
35 
36  virtual int compare(const UT_Hash &a) const
37  {
38  return !(myA==((const GA_EdgeHashT &)a).myA &&
39  myB==((const GA_EdgeHashT &)a).myB);
40  }
41  virtual void copy(const UT_Hash &a)
42  {
43  myA = static_cast<const GA_EdgeHashT &>(a).myA;
44  myB = static_cast<const GA_EdgeHashT &>(a).myB;
45  }
46  virtual unsigned hash() const
47  {
48  return myA * 47 + myB * 53;
49  }
50 
51  virtual UT_Hash *copy() const
52  {
53  return new GA_EdgeHashT(myA, myB);
54  }
55 
56  virtual int64 getMemoryUsage(bool inclusive) const
57  { return inclusive ? sizeof(*this) : 0; }
58 
59 private:
60  void orderKey()
61  {
62  if (myA > myB)
63  {
64  T t = myA;
65  myA = myB;
66  myB = t;
67  }
68  }
69 
70  T myA;
71  T myB;
72 };
73 
76 
77 // The hash key for directed edges:
78 template <typename T>
79 class GA_DirectedEdgeHashT : public UT_Hash
80 {
81 public:
82  GA_DirectedEdgeHashT(T a, T b) : myA(a), myB(b) { }
83  GA_DirectedEdgeHashT(GA_DirectedEdgeHashT const &h) : UT_Hash(), myA(h.myA), myB(h.myB) { }
84  virtual ~GA_DirectedEdgeHashT() {}
85 
86 
87  T getA() const { return myA; }
88  T getB() const { return myB; }
89 
90  virtual int compare(const UT_Hash &a) const
91  {
92  return !(myA==((const GA_DirectedEdgeHashT &)a).myA &&
93  myB==((const GA_DirectedEdgeHashT &)a).myB);
94  }
95  virtual void copy(const UT_Hash &a)
96  {
97  myA = static_cast<const GA_DirectedEdgeHashT &>(a).myA;
98  myB = static_cast<const GA_DirectedEdgeHashT &>(a).myB;
99  }
100  virtual unsigned hash() const
101  {
102  return myA * 47 + myB * 53;
103  }
104 
105  virtual UT_Hash *copy() const
106  {
107  return new GA_DirectedEdgeHashT(myA, myB);
108  }
109 
110  virtual int64 getMemoryUsage(bool inclusive) const
111  { return inclusive ? sizeof(*this) : 0; }
112 
113 private:
114  T myA;
115  T myB;
116 };
117 
118 typedef SYS_DEPRECATED_REPLACE(16.0, "SYShash")
120 typedef SYS_DEPRECATED_REPLACE(16.0, "SYShash")
122 
124 
125 #endif
GA_EdgeHashT< GA_Offset > GA_EdgeHash
Definition: GA_EdgeHash.h:74
virtual int compare(const UT_Hash &a) const
Definition: GA_EdgeHash.h:36
virtual unsigned hash() const
Definition: GA_EdgeHash.h:100
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
virtual int64 getMemoryUsage(bool inclusive) const
Definition: GA_EdgeHash.h:56
virtual UT_Hash * copy() const
Definition: GA_EdgeHash.h:105
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
virtual UT_Hash * copy() const
Definition: GA_EdgeHash.h:51
virtual void copy(const UT_Hash &a)
Definition: GA_EdgeHash.h:95
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:106
T getA() const
Definition: GA_EdgeHash.h:33
virtual unsigned hash() const
Definition: GA_EdgeHash.h:46
virtual int compare(const UT_Hash &a) const
Definition: GA_EdgeHash.h:90
GA_EdgeHashT(GA_EdgeHashT const &h)
Definition: GA_EdgeHash.h:29
virtual int64 getMemoryUsage(bool inclusive) const
Definition: GA_EdgeHash.h:110
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
GA_DirectedEdgeHashT(GA_DirectedEdgeHashT const &h)
Definition: GA_EdgeHash.h:83
T getB() const
Definition: GA_EdgeHash.h:34
virtual void copy(const UT_Hash &a)
Definition: GA_EdgeHash.h:41
GA_EdgeHashT(T a, T b)
Definition: GA_EdgeHash.h:28
GA_DirectedEdgeHashT(T a, T b)
Definition: GA_EdgeHash.h:82
virtual ~GA_EdgeHashT()
Definition: GA_EdgeHash.h:31
virtual ~GA_DirectedEdgeHashT()
Definition: GA_EdgeHash.h:84
GA_EdgeHashT< GA_Index > GA_IndexEdgeHash
Definition: GA_EdgeHash.h:75