@@ -174,16 +174,60 @@ template <class T, U32 N> struct fixed_queue
174174 U32 _last;
175175 T _buffer[N + 1 ];
176176
177- void reset ();
178- T& front ();
179- T& pop_front ();
180- void push_front (const T& element);
181- void push_back (const T& element);
182- bool full () const ;
183- T& back ();
184- T& pop_back ();
185- bool empty () const ;
186- U32 size () const ;
177+ void reset ()
178+ {
179+ clear ();
180+ }
181+ void clear ()
182+ {
183+ _last = 0 ;
184+ _first = 0 ;
185+ }
186+ T& front ()
187+ {
188+ fixed_queue<T, N>::iterator it = begin ();
189+ return *it;
190+ }
191+ void pop_front ()
192+ {
193+ _first = (_first + 1 ) & N;
194+ }
195+ void push_front ()
196+ {
197+ _first = (_first + N) & N;
198+ }
199+ void push_front (const T& data)
200+ {
201+ push_front ();
202+ T& new_front = front ();
203+ new_front = data;
204+ }
205+ void push_back ();
206+ U32 max_size () const
207+ {
208+ return N;
209+ }
210+ bool full () const
211+ {
212+ return size () == max_size ();
213+ }
214+ T& back ()
215+ {
216+ fixed_queue<T, N>::iterator it = end () - 1 ;
217+ return *it;
218+ }
219+ void pop_back ()
220+ {
221+ _last = (_last + N) & N;
222+ }
223+ bool empty () const
224+ {
225+ return _last == _first;
226+ }
227+ U32 size () const
228+ {
229+ return _last - _first;
230+ }
187231
188232 struct iterator {
189233 U32 _it;
@@ -201,15 +245,32 @@ template <class T, U32 N> struct fixed_queue
201245
202246 iterator* operator +=(S32 value)
203247 {
204- // This operation should be equivalent to 1 << ceil(logbase2(N)), which can be used as a mask
205- // for doing a fast modulus. This should be computed compile time, but there is no constexpr here
206- // And I don't know if this fixed_queue will see use again. So here it sits
207- const S32 mask = ((1 << (31 - __cntlzw (N))) - 1 );
208248 value += _it;
209- _it = value & mask ;
249+ _it = ( value + N) & N ;
210250 return this ;
211251 }
212252
253+ iterator* operator -=(S32 value)
254+ {
255+ iterator* tmp = operator +=(-value);
256+ return tmp;
257+ }
258+
259+ iterator* operator --()
260+ {
261+ *this -= 1 ;
262+ return this ;
263+ }
264+
265+ iterator operator -(S32 value) const
266+ {
267+ iterator tmp;
268+ tmp._it = _it;
269+ tmp._owner = _owner;
270+ tmp -= value;
271+ return tmp;
272+ }
273+
213274 iterator* operator ++()
214275 {
215276 *this += 1 ;
0 commit comments