CoMMA 1.3.2
A geometric agglomerator for unstructured meshes
Loading...
Searching...
No Matches
Queue.h
Go to the documentation of this file.
1#ifndef STACK_PROJECT_COMMA_H
2#define STACK_PROJECT_COMMA_H
3
4/*
5 * CoMMA
6 *
7 * Copyright © 2024 ONERA
8 *
9 * Authors: Nicolas Lantos, Alberto Remigi, and Riccardo Milani
10 * Contributors: Karim Anemiche
11 *
12 * This Source Code Form is subject to the terms of the Mozilla Public
13 * License, v. 2.0. If a copy of the MPL was not distributed with this
14 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
15 */
16
17#include <cassert>
18#include <deque>
19#include <iostream>
20#include <vector>
21
22namespace comma {
23
28template<typename T>
29class Queue {
30private:
32 std::deque<T> _elems;
33
34public:
36 Queue() = default;
38 ~Queue() = default;
39
43 void push(T const &elem) { _elems.push_back(elem); }
44
48 T pop() {
49 if (_elems.empty()) {
50 return static_cast<T>(-1);
51 }
52 T elem = _elems.front(); // Copy last element
53 _elems.pop_front(); // remove last element
54 return elem;
55 }
56
60 T top() const {
61 if (_elems.empty()) {
62 return static_cast<T>(-1);
63 }
64 return _elems.front();
65 }
66
70 inline bool empty() const { return _elems.empty(); }
71};
72
73} // end namespace comma
74
75#endif
A template class implementing a custom queue data structure.
Definition: Queue.h:29
T top() const
Scope to the element on the bottom of the queue.
Definition: Queue.h:60
T pop()
pop an element from the bottom of the queue
Definition: Queue.h:48
~Queue()=default
Destructor.
bool empty() const
Whether the queue is empty.
Definition: Queue.h:70
Queue()=default
Constructor.
void push(T const &elem)
Push an element on the top of the queue.
Definition: Queue.h:43
Definition: Agglomerator.h:37