1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Tim King, Mathias Preiner, Gereon Kremer |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Context-dependent queue class with an explicit trail of elements |
14 |
|
* |
15 |
|
* The implementation is based on a combination of CDList and a CDO<size_t> |
16 |
|
* for tracking the next element to dequeue from the list. |
17 |
|
* The implementation is currently not full featured. |
18 |
|
*/ |
19 |
|
|
20 |
|
#include "cvc5_private.h" |
21 |
|
|
22 |
|
#ifndef CVC5__CONTEXT__CDTRAIL_QUEUE_H |
23 |
|
#define CVC5__CONTEXT__CDTRAIL_QUEUE_H |
24 |
|
|
25 |
|
#include "context/cdlist.h" |
26 |
|
#include "context/cdo.h" |
27 |
|
|
28 |
|
namespace cvc5 { |
29 |
|
namespace context { |
30 |
|
|
31 |
|
class Context; |
32 |
|
|
33 |
|
template <class T> |
34 |
9853 |
class CDTrailQueue { |
35 |
|
private: |
36 |
|
|
37 |
|
/** List of elements in the queue. */ |
38 |
|
CDList<T> d_list; |
39 |
|
|
40 |
|
/** Points to the next element in the current context to dequeue. */ |
41 |
|
CDO<size_t> d_iter; |
42 |
|
|
43 |
|
|
44 |
|
public: |
45 |
|
|
46 |
|
/** Creates a new CDTrailQueue associated with the current context. */ |
47 |
9853 |
CDTrailQueue(Context* context) |
48 |
|
: d_list(context), |
49 |
9853 |
d_iter(context, 0) |
50 |
9853 |
{} |
51 |
|
|
52 |
|
/** Returns true if the queue is empty in the current context. */ |
53 |
4826828 |
bool empty() const{ |
54 |
4826828 |
return d_iter >= d_list.size(); |
55 |
|
} |
56 |
|
|
57 |
|
/** |
58 |
|
* Enqueues an element in the current context. |
59 |
|
* Returns its index in the queue. |
60 |
|
*/ |
61 |
744605 |
size_t enqueue(const T& data){ |
62 |
744605 |
size_t res = d_list.size(); |
63 |
744605 |
d_list.push_back(data); |
64 |
744605 |
return res; |
65 |
|
} |
66 |
|
|
67 |
701788 |
size_t frontIndex() const{ |
68 |
701788 |
return d_iter; |
69 |
|
} |
70 |
|
|
71 |
701788 |
const T& front() const{ |
72 |
701788 |
return d_list[frontIndex()]; |
73 |
|
} |
74 |
|
|
75 |
|
/** Moves the iterator for the queue forward. */ |
76 |
701788 |
void dequeue(){ |
77 |
701788 |
Assert(!empty()) << "Attempting to queue from an empty queue."; |
78 |
701788 |
d_iter = d_iter + 1; |
79 |
701788 |
} |
80 |
|
|
81 |
20251 |
const T& operator[](size_t index) const{ |
82 |
20251 |
Assert(index < d_list.size()); |
83 |
20251 |
return d_list[index]; |
84 |
|
} |
85 |
|
|
86 |
860471 |
size_t size() const{ |
87 |
860471 |
return d_list.size(); |
88 |
|
} |
89 |
|
|
90 |
|
};/* class CDTrailQueue<> */ |
91 |
|
|
92 |
|
} // namespace context |
93 |
|
} // namespace cvc5 |
94 |
|
|
95 |
|
#endif /* CVC5__CONTEXT__CDTRAIL_QUEUE_H */ |