tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
edge.hpp
Go to the documentation of this file.
1 /**
2  * Copyright (C) 2011
3  * University of Rochester Department of Computer Science
4  * and
5  * Lehigh University Department of Computer Science and Engineering
6  *
7  * License: Modified BSD
8  * Please see the file LICENSE.RSTM for licensing information
9  */
10 
11 /* edge.hpp
12  *
13  * Edges encapsulate the bulk of the information about the triangulation.
14  * Each edge contains references to its endpoints and to the next
15  * edges clockwise and counterclockwise about those endpoints.
16  */
17 
18 #ifndef EDGE_HPP__
19 #define EDGE_HPP__
20 
21 #include <iostream>
22  using std::ostream;
23  using std::cout;
24  using std::cerr;
25 #include <sstream>
26  using std::stringstream;
27 #include <string>
28  using std::string;
29 
30 #include "queues.hpp"
31 #include "common.hpp"
32 #include "point.hpp"
33 #include "my_thread.hpp"
34 #include "lock.hpp"
35 
36 class edge {
37 
38  // Utility routine for constructor.
39  //
41  void initialize_end(point* p, edge* e, int end, int dir) {
42  if (e == 0) {
43  neighbors[end][dir] = this;
44  neighbors[end][1-dir] = this;
45  p->first_edge = this;
46  } else {
47  int i = e->index_of(p);
48  neighbors[end][1-dir] = e;
49  neighbors[end][dir] = e->neighbors[i][dir];
50  e->neighbors[i][dir] = this;
51  edge* nbor = neighbors[end][dir];
52  i = nbor->index_of(p);
53  nbor->neighbors[i][1-dir] = this;
54  }
55  }
56 
57 public:
59  edge* neighbors[2][2];
60  // indexed first by edge end and then by direction
61  bool deleted;
62  // Has this edge been deleted from the mesh because it isn't Delaunay?
63 
64  // print self in canonical form (leftmost point first)
65  // send to cout if not in transaction; else to currentThread->vout
66  //
67  TRANSACTION_PURE void print(const char* prefix = "") const {
68  point* a = points[0];
69  point* b = points[1];
70  if (*b < *a) {
71  point* t = a; a = b; b = t;
72  }
73  stringstream ss;
74  ss << prefix
75  << a->coord[xdim] << " " << a->coord[ydim] << " "
76  << b->coord[xdim] << " " << b->coord[ydim] << "\n";
77  if (currentThread->in_transaction()) {
78  currentThread->vout << ss.str();
79  } else {
80  with_lock cs(io_lock);
81  cout << ss.str();
82  }
83  }
84 
85  // Return index of point p within edge, or (in FGL version) -1 if not
86  // found.
87  //
89  if (points[0] == p) return 0;
90  if (points[1] == p) return 1;
91 #ifndef FGL
92  assert(false);
93 #endif
94  return -1;
95  }
96 
97  // Edge may not be Delaunay. See if it's the diagonal of a convex
98  // quadrilateral. If so, check whether it should be flipped.
99  // If so, queue the edges of the quadrilateral for future
100  // reconsideration. Do all of this only if all points I touch
101  // are closest to my seam. If I don't own what I need to, return
102  // false, so caller knows to queue /this/ for future, synchronized
103  // reconsideration. If I _do_ own what I need to, return edges of
104  // quadrilateral for reconsideration.
105  //
107  bool reconsider(const int seam, bool txnal,
108  edge** surrounding_edges);
109 
110 #ifdef FGL
111  // Like regular reconsider above, but optimistically fine-grain
112  // synchronized: identifies the relevant edges and points, then
113  // locks them in canonical order, then double-checks to make
114  // sure nothing has changed.
115  //
116  void synchronized_reconsider(const int seam,
117  simple_queue<edge*> *tentative_edges);
118 #endif // FGL
119 
120  // Edge constructor and destructor are separately compiled to avoid a
121  // circular dependence on edge_set.hpp.
122 
123  // Edge constructor: connect points A and B, inserting dir (CW or CCW)
124  // of edge Ea at the A end and 1-dir of edge Eb at the B end.
125  // Either or both of Ea and Eb may be null.
126  //
128  edge(point* a, point* b, edge* ea, edge* eb, int dir);
129 
130  // Edge removal: take self out of edges, point edge lists, but do not
131  // delete /this/. Should only be called when flipping an edge, so
132  // destroyed edge should have neighbors at both ends. In FGL version,
133  // caller should hold locks that cover endpoints and neighbors.
134  //
136  void destroy();
137 
138  // Edge objects must never be deleted: they may be looked at after
139  // some other thread has deleted them.
140  //
141  ~edge() {assert(false);} // Should never be called.
142 };
143 
144 #endif // EDGE_HPP__
TRANSACTION_SAFE edge(point *a, point *b, edge *ea, edge *eb, int dir)
Definition: edge.cpp:25
#define TRANSACTION_SAFE
Definition: common.hpp:87
TRANSACTION_SAFE bool reconsider(const int seam, bool txnal, edge **surrounding_edges)
Definition: edge.cpp:65
~edge()
Definition: edge.hpp:141
int coord[2]
Definition: point.hpp:43
Definition: point.hpp:33
d_lock io_lock
Definition: mesh.cpp:33
Definition: lock.hpp:46
edge * first_edge
Definition: point.hpp:44
TRANSACTION_SAFE void initialize_end(point *p, edge *e, int end, int dir)
Definition: edge.hpp:41
Definition: edge.hpp:36
bool deleted
Definition: edge.hpp:61
static const int ydim
Definition: point.hpp:21
edge * neighbors[2][2]
Definition: edge.hpp:59
#define TRANSACTION_PURE
Definition: common.hpp:88
TRANSACTION_SAFE int index_of(const point *p)
Definition: edge.hpp:88
point * points[2]
Definition: edge.hpp:58
struct @18 p
TRANSACTION_SAFE void destroy()
Definition: edge.cpp:39
static const int xdim
Definition: point.hpp:20
TRANSACTION_PURE void print(const char *prefix="") const
Definition: edge.hpp:67