Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
deque.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
43# include <Vector.H>
44 # include <ah-errors.H>
45
46template <class Key>
47class deque : public vector<Key>
48{
49private:
50 DynArray<Key> array;
51
52 typedef Key value_type;
55 typedef unsigned int size_type;
56
58
59public:
60 friend class iterator : public vector<Key>::iterator
61 {
62 private:
63
64 friend class deque<Key>;
65
66 static const int Invalid_Position = -1;
67
68 DynArray<Key> * dyn_array_ptr;
69
71
72 iterator(deque<Key> & vec, int pos = 0)
74 {
75 /* empty */
76 }
77
78 void set_pos(int pos)
79 {
81 }
82
83 int get_position() const { return current_position; }
84
85 void verify_array(DynArray<Key> * array_ptr) const
86 {
87 ah_domain_error_if(array_ptr not_eq dyn_array_ptr)
88 << "Iterator is not set to same array";
89 }
90
91 DynArray<Key> * get_dyn_array_ptr() { return dyn_array_ptr; }
92
93 public:
94
97 {
98 /* empty */
99 }
100
101 iterator(const iterator& itor)
104 {
105 /* empty */
106 }
107
108 } ;
109
110 deque() : array(0), num_elem(0) { /* empty */}
111
113 {
114 // empty
115 }
116
117 deque (size_type num) : array(num), num_elem(num)
118 {
119 array.reserve(0, num_elem);
120 }
121
122 deque (size_type num, const Key& value) : array(num), num_elem(num)
123 {
124 array.reserve(0, num_elem);
125
126 for(size_type i = 0; i < num; i++)
127 array.access(i) = value;
128 }
129
130 deque (iterator beg, iterator end) : array(0), num_elem(end - beg)
131 {
132 array.reserve(0, num_elem);
133
134 for (int i = 0; beg < end; i++, beg++, num_elem++)
135 array.access(i) = *beg;
136 }
137
138 ~deque() { /* empty */ }
139
140 void push_front(const Key& value)
141 {
142 insert(begin(), value);
143 }
144
146 {
147 erase(begin());
148 }
149
150};
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:522
Definition deque.H:48
int get_position() const
Definition deque.H:83
iterator()
Definition deque.H:95
size_type num_elem
Definition deque.H:57
void push_front(const Key &value)
Definition deque.H:140
void set_pos(int pos)
Definition deque.H:78
deque::value_type & reference
Definition deque.H:53
~deque()
Definition deque.H:138
deque(const deque &c)
Definition deque.H:112
DynArray< Key > * get_dyn_array_ptr()
Definition deque.H:91
iterator(const iterator &itor)
Definition deque.H:101
unsigned int size_type
Definition deque.H:55
deque(iterator beg, iterator end)
Definition deque.H:130
friend class iterator
Definition deque.H:64
DynArray< Key > * dyn_array_ptr
Definition deque.H:68
DynArray< Key > array
Definition deque.H:50
const deque::value_type & const_reference
Definition deque.H:54
deque(size_type num, const Key &value)
Definition deque.H:122
deque()
Definition deque.H:110
size_type current_position
Definition deque.H:70
void pop_front()
Definition deque.H:145
iterator(deque< Key > &vec, int pos=0)
Definition deque.H:72
void verify_array(DynArray< Key > *array_ptr) const
Definition deque.H:85
deque(size_type num)
Definition deque.H:117
static const int Invalid_Position
Definition deque.H:66
Key value_type
Definition deque.H:52