HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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>
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  ~GA_EdgeHashT() override {}
32 
33  T getA() const { return myA; }
34  T getB() const { return myB; }
35 
36  int compare(const UT_Hash &a) const override
37  {
38  return !(myA==((const GA_EdgeHashT &)a).myA &&
39  myB==((const GA_EdgeHashT &)a).myB);
40  }
41  void copy(const UT_Hash &a) override
42  {
43  myA = static_cast<const GA_EdgeHashT &>(a).myA;
44  myB = static_cast<const GA_EdgeHashT &>(a).myB;
45  }
46  unsigned hash() const override
47  {
48  return myA * 47 + myB * 53;
49  }
50 
51  UT_Hash *copy() const override
52  {
53  return new GA_EdgeHashT(myA, myB);
54  }
55 
56  int64 getMemoryUsage(bool inclusive) const override
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  ~GA_DirectedEdgeHashT() override {}
85 
86 
87  T getA() const { return myA; }
88  T getB() const { return myB; }
89 
90  int compare(const UT_Hash &a) const override
91  {
92  return !(myA==((const GA_DirectedEdgeHashT &)a).myA &&
93  myB==((const GA_DirectedEdgeHashT &)a).myB);
94  }
95  void copy(const UT_Hash &a) override
96  {
97  myA = static_cast<const GA_DirectedEdgeHashT &>(a).myA;
98  myB = static_cast<const GA_DirectedEdgeHashT &>(a).myB;
99  }
100  unsigned hash() const override
101  {
102  return myA * 47 + myB * 53;
103  }
104 
105  UT_Hash *copy() const override
106  {
107  return new GA_DirectedEdgeHashT(myA, myB);
108  }
109 
110  int64 getMemoryUsage(bool inclusive) const override
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
int compare(const UT_Hash &a) const override
Definition: GA_EdgeHash.h:36
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
UT_Hash * copy() const override
Definition: GA_EdgeHash.h:105
void copy(const UT_Hash &a) override
Definition: GA_EdgeHash.h:95
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
int64 getMemoryUsage(bool inclusive) const override
Definition: GA_EdgeHash.h:110
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
~GA_DirectedEdgeHashT() override
Definition: GA_EdgeHash.h:84
~GA_EdgeHashT() override
Definition: GA_EdgeHash.h:31
UT_Hash * copy() const override
Definition: GA_EdgeHash.h:51
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
GA_Size GA_Offset
Definition: GA_Types.h:646
T getA() const
Definition: GA_EdgeHash.h:33
GA_EdgeHashT(GA_EdgeHashT const &h)
Definition: GA_EdgeHash.h:29
long long int64
Definition: SYS_Types.h:116
int compare(const UT_Hash &a) const override
Definition: GA_EdgeHash.h:90
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
GLdouble t
Definition: glad.h:2397
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GA_DirectedEdgeHashT(GA_DirectedEdgeHashT const &h)
Definition: GA_EdgeHash.h:83
T getB() const
Definition: GA_EdgeHash.h:34
unsigned hash() const override
Definition: GA_EdgeHash.h:46
GA_EdgeHashT(T a, T b)
Definition: GA_EdgeHash.h:28
GA_DirectedEdgeHashT(T a, T b)
Definition: GA_EdgeHash.h:82
void copy(const UT_Hash &a) override
Definition: GA_EdgeHash.h:41
int64 getMemoryUsage(bool inclusive) const override
Definition: GA_EdgeHash.h:56
unsigned hash() const override
Definition: GA_EdgeHash.h:100
GA_EdgeHashT< GA_Index > GA_IndexEdgeHash
Definition: GA_EdgeHash.h:75