1 #ifndef _SPICA_RANDOM_QUEUE_H_
2 #define _SPICA_RANDOM_QUEUE_H_
7 #include "core/random.h"
16 static const size_t initSize;
21 std::unique_ptr<T[]> _data;
31 _data = std::make_unique<T[]>(initSize);
52 if (
this == &que)
return *
this;
58 _data = std::make_unique<T[]>(que._size);
59 std::copy(que._data.get(), que._data.get() + que._size, _data.get());
69 auto temp = std::make_unique<T[]>(_size * 2);
70 std::copy(_data.get(), _data.get() + _size, temp.get());
74 _data = std::move(temp);
81 Assertion(_pos >= 0,
"Queue is empty !!");
82 const int r = _rng.nextInt(_pos);
85 std::swap(_data[r], _data[_pos]);
103 const size_t RandomQueue<Ty>::initSize = 1024;
107 #endif // _SPICA_RANDOM_QUEUE_H_
RandomQueue(unsigned int seed=0)
The RandomQueue constructor.
Definition: random_queue.h:26
~RandomQueue()
The RandomQueue destructor.
Definition: random_queue.h:36
Random number generator with Mersenne twister.
Definition: random.h:17
bool empty() const
Check if the queue is empty.
Definition: random_queue.h:91
size_t size() const
Return the size of the queue.
Definition: random_queue.h:97
T pop()
Pop the random item in the queue.
Definition: random_queue.h:80
void push(const T &ty)
Push a new value.
Definition: random_queue.h:66
Queue of random-order popping.
Definition: random_queue.h:14
RandomQueue & operator=(const RandomQueue &que)
Assignment operator.
Definition: random_queue.h:51
RandomQueue(const RandomQueue &que)
The RandomQueue constructor (copy).
Definition: random_queue.h:41