31 #pragma GCC visibility push(default)
45 std::ostream &
operator<<(std::ostream &out,
const AbaRing<Type> &rhs)
48 const int s = rhs.size();
50 for(
int i = rhs.head_; i < s; i++)
51 out << rhs.ring_[i] <<
" ";
54 for (
int i = 0; i < rhs.head_; i++)
55 out << rhs.ring_[i] <<
" ";
64 inline Type& AbaRing<Type>::operator[](
int i)
71 inline const Type& AbaRing<Type>::operator[](
int i)
const
78 void AbaRing<Type>::insert(Type elem)
82 if (++head_ ==
size()) {
83 if (!filled_) filled_ =
true;
90 inline void AbaRing<Type>::clear()
98 inline int AbaRing<Type>::size()
const
104 template <
class Type>
105 inline int AbaRing<Type>::number()
const
114 template <
class Type>
115 inline Type AbaRing<Type>::oldest()
const
117 if(filled_)
return ring_[head_];
118 else return ring_[0];
122 template <
class Type>
123 inline int AbaRing<Type>::oldestIndex()
const
125 if(filled_)
return head_;
130 template <
class Type>
131 inline Type AbaRing<Type>::newest()
const
133 if (head_)
return ring_[head_ - 1];
134 else return ring_[
size() - 1];
138 template <
class Type>
139 inline int AbaRing<Type>::newestIndex()
const
141 if (head_)
return head_ - 1;
142 else return size() - 1;
146 template <
class Type>
147 int AbaRing<Type>::previous(
int i, Type &p)
const
149 int j = head_ - 1 - i;
156 p = ring_[
size() + j];
163 template <
class Type>
164 inline bool AbaRing<Type>::empty()
const
166 return !(head_ || filled_);
170 template <
class Type>
171 inline bool AbaRing<Type>::filled()
const
177 template <
class Type>
178 void AbaRing<Type>::realloc(
int newSize)
180 Array<Type> tmp = ring_;
181 int oldSize =
size();
185 ring_.realloc(newSize);
187 if(newSize > oldSize) {
195 for(i = oldHead; i < oldSize; i++) ring_[head_++] = tmp[i];
196 for(i = 0; i < oldHead; i++) ring_[head_++] = tmp[i];
207 for (head_ =
size() - 1, i = oldHead - 1; head_ >= 0; head_--, i--) {
208 if (i < 0) i = oldSize - 1;
209 ring_[head_] = tmp[i];
213 else if (oldHead >
size()) {
214 for (head_ =
size() - 1, i = oldHead - 1; head_ >= 0; --head_, --i)
215 ring_[head_] = tmp[i];
223 #pragma GCC visibility pop