Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Queue.h
1 /*
2  * avl::Queue class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2020, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_AVL_QUEUE_H_
22 #define ELM_AVL_QUEUE_H_
23 
24 #include <elm/avl/GenTree.h>
25 
26 namespace elm { namespace avl {
27 
28 template <class T, class C = elm::Comparator<T>, class A = DefaultAlloc>
29 class Queue: public GenTree<T, IdAdapter<T>, C, A> {
30 public:
31  typedef T t;
34 
35  // Queue concept
36 
37  inline const T& head() const {
38  typename base_t::Node *n = base_t::root();
39  ASSERTP(n != nullptr, "empty queue");
40  while(n->left() != nullptr) n = n->left();
41  return n->data;
42  }
43 
44  inline T get() {
45  ASSERTP(base_t::root() != nullptr, "empty queue");
46  typename base_t::Stack s;
47  typename base_t::Node *n = static_cast<typename base_t::Node *>(base_t::leftMost(s, base_t::root()));
48  T r = n->data;
49  base_t::remove(s, n);
50  return r;
51  }
52 
53  inline void put(const T& x) { base_t::add(x); }
54 
55  inline void reset() { base_t::clear(); }
56 };
57 
58 } } // elm::avl
59 
60 #endif /* ELM_AVL_SET_H_ */
elm::avl::GenTree::root
Node * root(void) const
Definition: GenTree.h:112
elm::avl::Queue::base_t
GenTree< T, IdAdapter< T >, C, A > base_t
Definition: Queue.h:33
elm::avl::GenTree::remove
void remove(const T &x)
Definition: GenTree.h:232
elm::avl::Queue::reset
void reset()
Definition: Queue.h:55
elm::avl::GenTree::Node::data
T data
Definition: GenTree.h:107
elm::avl::AbstractTree::leftMost
Node * leftMost(Stack &s, Node *n)
Definition: avl_GenTree.cpp:443
elm::avl::Queue::head
const T & head() const
Definition: Queue.h:37
elm::avl::Queue
Definition: Queue.h:29
elm::avl::GenTree::Stack
Definition: GenTree.h:114
elm::avl::GenTree::clear
void clear(void)
Definition: GenTree.h:206
elm::avl::GenTree::Node
Definition: GenTree.h:100
elm
Definition: adapter.h:26
elm::avl::GenTree::add
void add(const T &item)
Definition: GenTree.h:222
elm::avl::Queue::put
void put(const T &x)
Definition: Queue.h:53
elm::avl::Queue::t
T t
Definition: Queue.h:31
elm::avl::GenTree
Definition: GenTree.h:97
elm::avl::Queue::get
T get()
Definition: Queue.h:44
elm::avl::Queue::self_t
Queue< T, C > self_t
Definition: Queue.h:32
elm::avl::GenTree::Node::left
Node * left(void)
Definition: GenTree.h:104