HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_Edge.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_Edge.h (GA Library, C++)
7  *
8  * COMMENTS: This class represents an edge as two point offsets.
9  * Comparisons treat the edge as undirected.
10  */
11 
12 #pragma once
13 
14 #ifndef __GA_Edge__
15 #define __GA_Edge__
16 
17 #include "GA_API.h"
18 #include "GA_Types.h"
19 #include <SYS/SYS_Hash.h>
20 
21 template<typename T,bool DIRECTED>
22 class GA_EdgeT
23 {
24 public:
26 
27  GA_EdgeT() : myP0(T(-1)), myP1(T(-1)) {}
28  GA_EdgeT(T pt0, T pt1) : myP0(pt0), myP1(pt1) {}
29 
30  T p0() const { return myP0; }
31  T &p0() { return myP0; }
32  T p1() const { return myP1; }
33  T &p1() { return myP1; }
34 
36  {
37  return sizeof(*this);
38  }
39 
40  bool isValid() const
41  { return GAisValid(myP0) && GAisValid(myP1); }
42 
43  /// Return whether this edge is the same undirected edge as the given edge.
44  bool operator==(const ThisType & e) const
45  {
46  if (DIRECTED)
47  {
48  return (myP0 == e.myP0 && myP1 == e.myP1);
49  }
50  else
51  {
52  return (myP0 == e.myP0 && myP1 == e.myP1)
53  || (myP0 == e.myP1 && myP1 == e.myP0);
54  }
55  }
56  bool operator!=(const ThisType & e) const
57  {
58  return !(*this == e);
59  }
60 
61  /// Hash function
62  size_t hash() const
63  {
64  size_t hash_val;
65  if (DIRECTED || myP0 < myP1)
66  {
67  hash_val = GA_Size(myP0);
68  SYShashCombine(hash_val, GA_Size(myP1));
69  }
70  else
71  {
72  hash_val = GA_Size(myP1);
73  SYShashCombine(hash_val, GA_Size(myP0));
74  }
75  return hash_val;
76  }
77 
78 private:
79  T myP0;
80  T myP1;
81 };
82 
83 template<typename T,bool DIRECTED>
85 {
86  return edge.hash();
87 }
88 
89 // Specialize the GA_EdgeT template for the known edge types
92 
95 
96 namespace std {
97 template<typename T,bool DIRECTED>
98 struct hash<GA_EdgeT<T,DIRECTED> >
99 {
101  typedef size_t result_type;
102 
103  size_t operator()(const GA_EdgeT<T,DIRECTED> &edge) const
104  {
105  return edge.hash();
106  }
107 };
108 }
109 
110 #endif
GA_EdgeT(T pt0, T pt1)
Definition: GA_Edge.h:28
bool operator==(const ThisType &e) const
Return whether this edge is the same undirected edge as the given edge.
Definition: GA_Edge.h:44
bool GAisValid(GA_Size v)
Definition: GA_Types.h:649
T & p1()
Definition: GA_Edge.h:33
size_t operator()(const GA_EdgeT< T, DIRECTED > &edge) const
Definition: GA_Edge.h:103
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:235
bool isValid() const
Definition: GA_Edge.h:40
GA_EdgeT< T, DIRECTED > ThisType
Definition: GA_Edge.h:25
T & p0()
Definition: GA_Edge.h:31
GA_EdgeT< T, DIRECTED > argument_type
Definition: GA_Edge.h:100
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
long long int64
Definition: SYS_Types.h:116
T p1() const
Definition: GA_Edge.h:32
SYS_FORCE_INLINE size_t hash_value(const GA_EdgeT< T, DIRECTED > &edge)
Definition: GA_Edge.h:84
size_t hash() const
Hash function.
Definition: GA_Edge.h:62
int64 getMemoryUsage() const
Definition: GA_Edge.h:35
GA_EdgeT()
Definition: GA_Edge.h:27
bool operator!=(const ThisType &e) const
Definition: GA_Edge.h:56
T p0() const
Definition: GA_Edge.h:30