SheafSystem  0.0.0.0
depth_first_itr.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 
22 #include "SheafSystem/depth_first_itr.impl.h"
23 
24 using namespace std;
25 using namespace unordered;
26 
27 // =============================================================================
28 // MEMBER FUNCTION SPECIALIZATIONS
29 // =============================================================================
30 
31 // =============================================================================
32 // ZN_TO_BOOL
33 // =============================================================================
34 
35 
36 #include "SheafSystem/zn_to_bool.h"
37 
38 template <>
39 void
42 {
43  _has_visited->make_false_sa();
44 }
45 
46 template <>
47 void
49 reserve_has_visited(pod_index_type xub)
50 {
51  _has_visited->extend_to(xub);
52 }
53 
54 template <>
55 bool
58 {
59 
60  // Preconditions:
61 
62  require(is_initialized());
63  require(anchor().host()->contains_member(xindex, true));
64 
65  // Body:
66 
67  bool result = (*_has_visited)[xindex];
68 
69  return result;
70 }
71 
72 template <>
73 void
76 {
77  // Preconditions:
78 
79  require(xanchor.state_is_read_accessible());
80  require(is_done());
81 
82  // Body:
83 
84  if(_has_visited != 0)
85  {
86  delete _has_visited;
87  }
88 
89  _has_visited = new zn_to_bool(xanchor.host()->member_index_ub().pod());
90 
91  // Postconditions:
92 
93  ensure(_has_visited != 0);
94  ensure(is_done());
95 
96  // Exit
97 
98  return;
99 }
100 
101 template <>
102 void
104 put_has_visited(pod_index_type xindex, bool xvalue)
105 {
106 
107  // Preconditions:
108 
109  require(is_initialized());
110  require(anchor().host()->contains_member(xindex, true));
111 
112  // Body:
113 
114  _has_visited->put(xindex, xvalue);
115 
116  // Postconditions:
117 
118  ensure(has_visited(xindex) == xvalue);
119 
120  return;
121 }
122 
123 // =============================================================================
124 // SET
125 // =============================================================================
126 
127 #include "SheafSystem/std_set.h"
128 
129 template <>
130 void
132 clear_has_visited()
133 {
134  _has_visited->clear();
135 }
136 
137 template <>
138 void
140 reserve_has_visited(sheaf::pod_index_type xub)
141 {
142  // No action required.
143 }
144 
145 template <>
146 bool
148 has_visited(pod_index_type xindex) const
149 {
150 
151  // Preconditions:
152 
153  require(is_initialized());
154  require(anchor().state_is_read_accessible());
155  require(anchor().host()->contains_member(xindex));
156 
157  // Body:
158 
159  bool result =
160  (_has_visited->find(xindex) != _has_visited->end());
161 
162  return result;
163 }
164 
165 template <>
166 void
168 initialize_has_visited(const abstract_poset_member& xanchor)
169 {
170  // Preconditions:
171 
172  require(xanchor.state_is_read_accessible());
173  require(is_done());
174 
175  // Body:
176 
177  if(_has_visited != 0)
178  {
179  delete _has_visited;
180  }
181 
182  _has_visited = new std::set<pod_index_type>;
183 
184  // Postconditions:
185 
186  ensure(_has_visited != 0);
187  ensure(is_done());
188 
189  // Exit
190 
191  return;
192 }
193 
194 template <>
195 void
197 put_has_visited(pod_index_type xindex, bool xvalue)
198 {
199 
200  // Preconditions:
201 
202  require(is_initialized());
203  require(anchor().state_is_read_accessible());
204  require(anchor().host()->contains_member(xindex));
205 
206  // Body:
207 
208  if(xvalue)
209  {
210  _has_visited->insert(xindex);
211  }
212  else
213  {
214  _has_visited->erase(xindex);
215  }
216 
217  // Postconditions:
218 
219  ensure(has_visited(xindex) == xvalue);
220 
221  return;
222 }
223 
224 // =============================================================================
225 // UNORDERED_SET
226 // =============================================================================
227 
228 #include "SheafSystem/std_unordered_set.h"
229 
230 template <>
231 void
233 clear_has_visited()
234 {
235  _has_visited->clear();
236 }
237 
238 template <>
239 void
241 reserve_has_visited(pod_index_type xub)
242 {
243  // Assume bucket load factor of 2.
244 
245  _has_visited->rehash(xub/2);
246 }
247 
248 template <>
249 bool
251 has_visited(pod_index_type xindex) const
252 {
253 
254  // Preconditions:
255 
256  require(is_initialized());
257  require(anchor().state_is_read_accessible());
258  require(anchor().host()->contains_member(xindex));
259 
260  // Body:
261 
262  bool result =
263  (_has_visited->find(xindex) != _has_visited->end());
264 
265  return result;
266 
267 }
268 
269 template <>
270 void
272 initialize_has_visited(const abstract_poset_member& xanchor)
273 {
274  // Preconditions:
275 
276  require(xanchor.state_is_read_accessible());
277  require(is_done());
278 
279  // Body:
280 
281  if(_has_visited != 0)
282  {
283  delete _has_visited;
284  }
285 
286  _has_visited = new unordered_set<pod_index_type>;
287 
288  // Postconditions:
289 
290  ensure(_has_visited != 0);
291  ensure(is_done());
292 
293  // Exit
294 
295  return;
296 }
297 
298 template <>
299 void
301 put_has_visited(pod_index_type xindex, bool xvalue)
302 {
303 
304  // Preconditions:
305 
306  require(is_initialized());
307  require(anchor().state_is_read_accessible());
308  require(anchor().host()->contains_member(xindex));
309 
310  // Body:
311 
312  if(xvalue)
313  {
314  _has_visited->insert(xindex);
315  }
316  else
317  {
318  _has_visited->erase(xindex);
319  }
320 
321  // Postconditions:
322 
323  ensure(has_visited(xindex) == xvalue);
324 
325  return;
326 }
327 
void clear_has_visited()
Makes has_visited(i) false for all i.
void put_has_visited(pod_index_type xhub_id, bool xvalue)
Set the visited marker for hub id xhub_id to xvalue. Intended for use reseting iterator without havin...
poset_state_handle * host() const
The poset which this is a handle to a component of.
virtual void initialize_has_visited(const abstract_poset_member &xanchor)
Initializes the has_visited markers.
bool has_visited(pod_index_type xhub_id) const
True if this has already visited member with hub id xhub_id.
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
STL namespace.
void reserve_has_visited(pod_index_type xub)
Ensures has_visited(i) is a legal call for 0 <= i < xub.
A map from Zn (the integers mod n) to bools. A characteristic function used to represent subsets of Z...
Definition: zn_to_bool.h:52
The general depth-first iterator over the intersection of a poset member anchor&#39;s whole with its down...
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual scoped_index member_index_ub() const
The upper bound on the member_index;.
An abstract client handle for a member of a poset.