Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
ring.inc
Go to the documentation of this file.
1
29#pragma once
30
31namespace abacus {
32
33
34template <class Type>
35inline AbaRing<Type>::AbaRing(int size)
36 :
37 ring_(size),
38 head_(0),
39 filled_(false)
40{ }
41
42
43template <class Type>
44std::ostream &operator<<(std::ostream &out, const AbaRing<Type> &rhs)
45{
46 if(rhs.filled_) {
47 const int s = rhs.size();
48
49 for(int i = rhs.head_; i < s; i++)
50 out << rhs.ring_[i] << " ";
51 }
52
53 for (int i = 0; i < rhs.head_; i++)
54 out << rhs.ring_[i] << " ";
55
56 out << std::endl;
57
58 return out;
59}
60
61
62template <class Type>
63inline Type& AbaRing<Type>::operator[](int i)
64{
65 return ring_[i];
66}
67
68
69template <class Type>
70inline const Type& AbaRing<Type>::operator[](int i) const
71{
72 return ring_[i];
73}
74
75
76template <class Type>
77void AbaRing<Type>::insert(Type elem)
78{
79 ring_[head_] = elem;
80
81 if (++head_ == size()) {
82 if (!filled_) filled_ = true;
83 head_ = 0;
84 }
85}
86
87
88template <class Type>
89inline void AbaRing<Type>::clear()
90{
91 head_ = 0;
92 filled_ = false;
93}
94
95
96template <class Type>
97inline int AbaRing<Type>::size() const
98{
99 return ring_.size();
100}
101
102
103template <class Type>
104inline int AbaRing<Type>::number() const
105{
106 if (filled_)
107 return size();
108 else
109 return head_;
110}
111
112
113template <class Type>
114inline Type AbaRing<Type>::oldest() const
115{
116 if(filled_) return ring_[head_];
117 else return ring_[0];
118}
119
120
121template <class Type>
122inline int AbaRing<Type>::oldestIndex() const
123{
124 if(filled_) return head_;
125 else return 0;
126}
127
128
129template <class Type>
130inline Type AbaRing<Type>::newest() const
131{
132 if (head_) return ring_[head_ - 1];
133 else return ring_[size() - 1];
134}
135
136
137template <class Type>
138inline int AbaRing<Type>::newestIndex() const
139{
140 if (head_) return head_ - 1;
141 else return size() - 1;
142}
143
144
145template <class Type>
146int AbaRing<Type>::previous(int i, Type &p) const
147{
148 int j = head_ - 1 - i;
149
150 if (j >= 0) {
151 p = ring_[j];
152 return 0;
153 }
154 else if (filled_) {
155 p = ring_[size() + j];
156 return 0;
157 }
158 else return 1;
159}
160
161
162template <class Type>
163inline bool AbaRing<Type>::empty() const
164{
165 return !(head_ || filled_);
166}
167
168
169template <class Type>
170inline bool AbaRing<Type>::filled() const
171{
172 return filled_;
173}
174
175
176template <class Type>
177void AbaRing<Type>::realloc(int newSize)
178{
179 Array<Type> tmp = ring_;
180 int oldSize = size();
181 int oldHead = head_;
182 int i;
183
184 ring_.realloc(newSize);
185
186 if(newSize > oldSize) {
187 // increase ring
188 /* If the ring is increased yet has not been filled, nothing has to be
189 * done. Otherwise, the elements of the old ring are copied in the correct
190 * order.
191 */
192 if (filled_) {
193 head_ = 0;
194 for(i = oldHead; i < oldSize; i++) ring_[head_++] = tmp[i];
195 for(i = 0; i < oldHead; i++) ring_[head_++] = tmp[i];
196 filled_ = false;
197 }
198 }
199 else {
200 // decrease ring
201 /* If the ring is decreased and it is filled, then we copy the elements of the
202 * old ring in the correct order. If the ring is not filled we only have
203 * to copy the elements if by decreasing the ring elements are removed.
204 */
205 if (filled_) {
206 for (head_ = size() - 1, i = oldHead - 1; head_ >= 0; head_--, i--) {
207 if (i < 0) i = oldSize - 1;
208 ring_[head_] = tmp[i];
209 }
210 head_ = 0;
211 }
212 else if (oldHead > size()) {
213 for (head_ = size() - 1, i = oldHead - 1; head_ >= 0; --head_, --i)
214 ring_[head_] = tmp[i];
215 head_ = 0;
216 filled_ = true;
217 }
218 }
219}
220
221}
AbaRing(int size)
The constructor.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:978