summaryrefslogtreecommitdiff
path: root/src/context/cdtrail_queue.h
blob: 94d758cedeabbf5415ffd3fb9ee261d665d3a8b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*********************                                                        */
/*! \file cdtrail_queue.h
 ** \verbatim
 ** Original author: taking
 ** Major contributors: none
 ** Minor contributors (to current version): none
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009, 2010, 2011  The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.\endverbatim
 **
 ** \brief Context-dependent queue class with an explicit trail of elements
 **
 ** Context-dependent First-In-First-Out queue class.
 ** The implementation is based on a combination of CDList and a CDO<size_t>
 ** for tracking the next element to dequeue from the list.
 ** The implementation is currently not full featured.
 **/


#include "cvc4_private.h"

#ifndef __CVC4__CONTEXT__CDTRAIL_QUEUE_H
#define __CVC4__CONTEXT__CDTRAIL_QUEUE_H

#include "context/context.h"
#include "context/cdlist.h"

namespace CVC4 {
namespace context {


template <class T>
class CDTrailQueue {
private:

  /** List of elements in the queue. */
  CDList<T> d_list;

  /** Points to the next element in the current context to dequeue. */
  CDO<size_t> d_iter;


public:

  /** Creates a new CDTrailQueue associated with the current context. */
  CDTrailQueue(Context* context)
    : d_list(context),
      d_iter(context, 0)
  {}

  /** Returns true if the queue is empty in the current context. */
  bool empty() const{
    return d_iter >= d_list.size();
  }

  /**
   * Enqueues an element in the current context.
   * Returns its index in the queue.
   */
  size_t enqueue(const T& data){
    size_t res = d_list.size();
    d_list.push_back(data);
    return res;
  }

  size_t frontIndex() const{
    return d_iter;
  }

  const T& front() const{
    return d_list[frontIndex()];
  }

  /** Moves the iterator for the queue forward. */
  void dequeue(){
    Assert(!empty(), "Attempting to queue from an empty queue.");
    d_iter = d_iter + 1;
  }

  const T& operator[](size_t index) const{
    Assert(index < d_list.size());
    return d_list[index];
  }

  size_t size() const{
    return d_list.size();
  }

};/* class CDTrailQueue<> */

}/* CVC4::context namespace */
}/* CVC4 namespace */

#endif /* __CVC4__CONTEXT__CDTRAIL_QUEUE_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback