44 std::ostream &
operator<<(std::ostream &out,
const AbaRing<Type> &rhs)
47 const int s = rhs.size();
49 for(
int i = rhs.head_; i < s; i++)
50 out << rhs.ring_[i] <<
" ";
53 for (
int i = 0; i < rhs.head_; i++)
54 out << rhs.ring_[i] <<
" ";
63 inline Type& AbaRing<Type>::operator[](
int i)
70 inline const Type& AbaRing<Type>::operator[](
int i)
const
77 void AbaRing<Type>::insert(Type elem)
81 if (++head_ ==
size()) {
82 if (!filled_) filled_ =
true;
89 inline void AbaRing<Type>::clear()
97 inline int AbaRing<Type>::size()
const
103 template <
class Type>
104 inline int AbaRing<Type>::number()
const
113 template <
class Type>
114 inline Type AbaRing<Type>::oldest()
const
116 if(filled_)
return ring_[head_];
117 else return ring_[0];
121 template <
class Type>
122 inline int AbaRing<Type>::oldestIndex()
const
124 if(filled_)
return head_;
129 template <
class Type>
130 inline Type AbaRing<Type>::newest()
const
132 if (head_)
return ring_[head_ - 1];
133 else return ring_[
size() - 1];
137 template <
class Type>
138 inline int AbaRing<Type>::newestIndex()
const
140 if (head_)
return head_ - 1;
141 else return size() - 1;
145 template <
class Type>
146 int AbaRing<Type>::previous(
int i, Type &p)
const
148 int j = head_ - 1 - i;
155 p = ring_[
size() + j];
162 template <
class Type>
163 inline bool AbaRing<Type>::empty()
const
165 return !(head_ || filled_);
169 template <
class Type>
170 inline bool AbaRing<Type>::filled()
const
176 template <
class Type>
177 void AbaRing<Type>::realloc(
int newSize)
179 Array<Type> tmp = ring_;
180 int oldSize =
size();
184 ring_.realloc(newSize);
186 if(newSize > oldSize) {
194 for(i = oldHead; i < oldSize; i++) ring_[head_++] = tmp[i];
195 for(i = 0; i < oldHead; i++) ring_[head_++] = tmp[i];
206 for (head_ =
size() - 1, i = oldHead - 1; head_ >= 0; head_--, i--) {
207 if (i < 0) i = oldSize - 1;
208 ring_[head_] = tmp[i];
212 else if (oldHead >
size()) {
213 for (head_ =
size() - 1, i = oldHead - 1; head_ >= 0; --head_, --i)
214 ring_[head_] = tmp[i];