spot  1.2.1a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lowlink_stack.hh
1 // Copyright (C) 2013 Laboratoire de Recherche et Développement
2 // de l'Epita (LRDE).
3 //
4 // This file is part of Spot, a model checking library.
5 //
6 // Spot is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // Spot is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef SPOT_FASTTGBAALGOS_EC_LOWLINK_STACK_HH
20 # define SPOT_FASTTGBAALGOS_EC_LOWLINK_STACK_HH
21 
22 #include <stack>
23 #include <tuple>
24 #include <string>
25 #include "misc/hash.hh"
26 #include "union_find.hh"
27 #include "fasttgba/fasttgba.hh"
28 #include "ec.hh"
29 
30 namespace spot
31 {
36  {
37  public:
39  empty_(new markset(acc)),
40  max_size_(0)
41  { }
42 
43 
46  {
47  while (!stack_.empty())
48  {
49  pop();
50  }
51  delete empty_;
52  }
53 
55  virtual void push(int lowlink)
56  {
57  //std::cout << "[push] " << lowlink << std::endl;
58  stack_.push(std::make_pair(lowlink, empty_));
59  }
60 
62  virtual int top()
63  {
64  return stack_.top().first;
65  }
66 
69  virtual const markset& top_acceptance()
70  {
71  assert(!stack_.empty());
72  return *stack_.top().second;
73  }
74 
76  virtual int pop()
77  {
78  max_size_ = max_size_ > stack_.size()? max_size_ : stack_.size();
79  int t = top();
80  if (stack_.top().second != empty_)
81  delete stack_.top().second;
82  stack_.pop();
83  //std::cout << "[pop] " << t << std::endl;
84  return t;
85  }
86 
89  virtual void set_top(int ll, markset m)
90  {
91  //std::cout << "[stop] " << ll << std::endl;
92  stack_.top().first = ll;
93  if (stack_.top().second != empty_)
94  delete stack_.top().second;
95  stack_.top().second = new markset(m);
96  }
97 
99  virtual void set_top(int ll)
100  {
101  stack_.top().first = ll;
102  }
103 
105  virtual unsigned int max_size()
106  {
107  return max_size_;
108  }
109 
111  virtual unsigned int size()
112  {
113  return stack_.size();
114  }
115 
116  private:
117  std::stack<std::pair<unsigned int, markset*>> stack_; // The stack
118 
119  protected:
121  unsigned int max_size_;
122  };
123 
124 
127  {
128  public:
129  // This struct defines a base element that will be store into the stack
130  struct ll_elt
131  {
132  int lowlink;
134  union {
135  int range;
137  };
138  };
139 
141  stack_of_lowlink(acc)
142  { }
143 
144 
147  {
148  while (!stack_.empty())
149  {
150  pop();
151  }
152  }
153 
155  virtual void push(int lowlink)
156  {
157  //std::cout << "Push : " << lowlink << std::endl;
158 
159  if (stack_.empty())
160  stack_.push({lowlink, false, {0}});
161  else if (stack_.top().backedge_updated)
162  stack_.push({lowlink, false, {0}});
163  else
164  {
165  assert(stack_.top().backedge_updated == false);
166  assert(stack_.top().range + 1 + stack_.top().lowlink == lowlink);
167  stack_.top().range = stack_.top().range + 1;
168  }
169  }
170 
172  virtual int top()
173  {
174  if (stack_.top().backedge_updated)
175  return stack_.top().lowlink;
176  else
177  return stack_.top().range + stack_.top().lowlink;
178  }
179 
182  virtual const markset& top_acceptance()
183  {
184  if (!stack_.top().backedge_updated)
185  return *empty_;
186  return *stack_.top().mark;
187  }
188 
190  virtual int pop()
191  {
192  int t = top();
193  //std::cout << "Pop : " << t << std::endl;
194  if (stack_.top().backedge_updated)
195  {
196  if (stack_.top().mark != empty_)
197  delete stack_.top().mark;
198  stack_.pop();
199  return t;
200  }
201  else if (stack_.top().range == 0)
202  {
203  if (stack_.top().mark != empty_)
204  delete stack_.top().mark;
205  stack_.pop();
206  return t;
207  }
208  else
209  {
210  stack_.top().range = stack_.top().range - 1;
211  }
212  return t;
213  }
214 
217  virtual void set_top(int ll, markset m)
218  {
219  //std::cout << "Settop : " << ll << std::endl;
220  if (stack_.top().backedge_updated)
221  {
222  assert(ll <= stack_.top().lowlink);
223  if (m == *empty_)
224  stack_.top().mark = empty_;
225  else
226  stack_.top().mark = new markset(m);
227  stack_.top().lowlink = ll;
228  }
229  else
230  {
231 
232  if (stack_.top().range == 0)
233  {
234  if (m == *empty_)
235  stack_.top().mark = empty_;
236  else
237  stack_.top().mark = new markset(m);
238  stack_.top().backedge_updated = true;
239  stack_.top().lowlink = ll;
240  }
241  else
242  {
243  stack_.top().range = stack_.top().range -1;
244  stack_.push({ll, true, {0}});
245  if (m == *empty_)
246  stack_.top().mark = empty_;
247  else
248  stack_.top().mark = new markset(m);
249  }
250  }
251 
252  }
253 
255  virtual void set_top(int ll)
256  {
257  set_top(ll, *empty_);
258  }
259 
261  virtual unsigned int max_size()
262  {
263  return max_size_;
264  }
265 
267  virtual unsigned int size()
268  {
269  return stack_.size();
270  }
271 
272  private:
273  std::stack<ll_elt> stack_; // The stack
274  };
275 }
276 
277 
278 #endif // SPOT_FASTTGBAALGOS_EC_LOWLINK_STACK_HH
This class represents a set of acceptance marks.
Definition: markset.hh:35
Definition: acc_dict.hh:31

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Tue Jan 21 2014 16:52:01 for spot by doxygen 1.8.5