OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
DomainMap.hpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  * This program was prepared by PSI.
7  * All rights in the program are reserved by PSI.
8  * Neither PSI nor the author(s)
9  * makes any warranty, express or implied, or assumes any liability or
10  * responsibility for the use of this software
11  *
12  * Visit www.amas.web.psi for more details
13  *
14  ***************************************************************************/
15 
16 // -*- C++ -*-
17 /***************************************************************************
18  *
19  * The IPPL Framework
20  *
21  *
22  * Visit http://people.web.psi.ch/adelmann/ for more details
23  *
24  ***************************************************************************/
25 
26 // include files
27 #include "Index/NDIndex.h"
28 #include "Utility/RefCounted.h"
29 #include "Field/LField.h"
30 #include "FieldLayout/Vnode.h"
31 
32 
33 
34 
35 
36 
38 
39 // Insert a new key in the DomainMap.
40 
41 template < class Key , class T , class Touches, class Contains, class Split >
42 void
44  bool noSplit)
45 {
46 
47 
48 
49  // Tell the tree top to insert.
50  Root->insert(d, noSplit);
51  // Increment the total size.
52  Size += 1;
53  // Update the pointer to the first element.
54  update_leftmost();
55 }
56 
58 
59 // Recalculate the first element in the tree.
60 
61 template < class Key , class T , class Touches, class Contains, class Split >
62 void
64 {
65 
66 
67 
68  Node *p=Root;
69  // First dive all the way left.
70  while ( p->Left )
71  p = p->Left;
72  // Look for the first element.
73  typename Node::cont_type::iterator v;
74  while ( (v=p->cont.begin()) == p->cont.end() ) {
75  // First look right.
76  if ( p->Right ) {
77  // If it is there, go there and then all the way left.
78  p = p->Right;
79  while ( p->Left )
80  p = p->Left;
81  }
82  else {
83  // If there is no right, go up until you can go right more.
84  Node *y = p->Parent;
85  while (y && (p==y->Right)) {
86  p = y;
87  y = y->Parent;
88  }
89  p = y;
90  }
91  }
92  if ( (Leftmost.p=p) != 0 )
93  Leftmost.v = v;
94 }
95 
97 
98 // Find the range that touches a given T.
99 
100 template < class Key, class T , class Touches, class Contains, class Split >
101 std::pair<typename DomainMap<Key,T,Touches,Contains,Split>::touch_iterator,
104 {
105 
106  Node *p=Root;
107 
108  if ( p ) {
109 
110  // First dive left, checking touches.
111  for ( Node* y=p->Left; y && Touches::test(t,y->MyDomain); y=y->Left )
112  p = y;
113 
114  do {
115  // Look for the first element that actually touches.
116  for (typename Node::cont_type::iterator v=p->cont.begin();
117  v!=p->cont.end(); ++v)
118  if ( Touches::test(t,(*v).first) ) {
119  // Found it!
120  touch_iterator f;
121  f.TouchThis = t;
122  f.p = p;
123  f.v = v;
124  return std::pair<touch_iterator,touch_iterator>(f,touch_iterator());
125  }
126 
127  // Didn't find one here. Move on.
128  Node *y = p->Right;
129  if ( y && Touches::test(t,y->MyDomain) ) {
130  // If it is there, go there and then all the way left.
131  p = y;
132  for ( y=p->Left; y && Touches::test(t,y->MyDomain) ; y=y->Left )
133  p = y;
134  }
135  else {
136  // If there is no right, go up until you can go right more.
137  for ( y = p->Parent; y && (p==y->Right); y = y->Parent )
138  p = y;
139  p = y;
140  }
141  } while (p);
142  }
143  // Didn't find any.
144  return std::pair<touch_iterator,touch_iterator>(touch_iterator(),touch_iterator());
145 }
146 
148 
149 //
150 // Copy ctor and assign do deep copies.
151 //
152 
153 template < class Key, class T , class Touches, class Contains, class Split >
156 : Root( new Node(a.Root->MyDomain) ), Size(0)
157 {
158 
159 
160 
161  for (iterator p=a.begin(); p!=a.end(); ++p)
162  insert_noupdate( *p );
163  update_leftmost();
164 }
165 
166 template < class Key, class T , class Touches, class Contains, class Split >
167 void
170 {
171 
172 
173 
174  if ( this != &a ) {
175  // Clean out the current contents.
176  delete Root;
177  Root = new Node( a.Root->MyDomain );
178  Size = 0;
179  // Add the new stuff.
180  for (iterator p=a.begin(); p!=a.end(); ++p)
181  insert_noupdate( *p );
182  // Reset the pointer to the first one.
183  update_leftmost();
184  }
185 }
186 /***************************************************************************
187  * $RCSfile: DomainMap.cpp,v $ $Author: adelmann $
188  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:25 $
189  * IPPL_VERSION_ID: $Id: DomainMap.cpp,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $
190  ***************************************************************************/
Node::cont_type::iterator v
Definition: DomainMap.h:474
void operator=(const DomainMap< Key, T, Touches, Contains, Split > &)
Definition: DomainMap.hpp:169
iterator end()
Definition: DomainMap.h:502
static bool test(const NDIndex< Dim > &a, const NDIndex< Dim > &b)
Definition: NDIndex.h:274
void insert(const value_type &d, bool noSplit=false)
Definition: DomainMap.hpp:43
iterator begin()
Definition: DomainMap.h:501
std::pair< touch_iterator, touch_iterator > touch_range(const Key &t) const
Definition: DomainMap.hpp:103
void insert_noupdate(const value_type &d)
Definition: DomainMap.h:531
Node * Root
Definition: DomainMap.h:526
std::string::iterator iterator
Definition: MSLang.h:16
cont_type cont
Definition: DomainMap.h:106
void update_leftmost()
Definition: DomainMap.hpp:63