14 #ifndef STXXL_CONTAINERS_QUEUE_HEADER
15 #define STXXL_CONTAINERS_QUEUE_HEADER
32 #ifndef STXXL_VERBOSE_QUEUE
33 #define STXXL_VERBOSE_QUEUE STXXL_VERBOSE2
47 template <
class ValueType,
58 block_size = BlockSize
96 D = config::get_instance()->disks_number();
115 pool =
new pool_type(p_pool_size, w_pool_size);
116 init(blocks2prefetch_);
136 init(blocks2prefetch_);
154 init(blocks2prefetch_);
164 std::swap(m_size, obj.
m_size);
166 std::swap(pool, obj.
pool);
173 std::swap(bids, obj.
bids);
174 std::swap(bm, obj.
bm);
181 void init(
int blocks2prefetch_ = -1)
183 if (pool->size_write() < 2) {
184 STXXL_ERRMSG(
"queue: invalid configuration, not enough blocks (" << pool->size_write() <<
185 ") in write pool, at least 2 are needed, resizing to 3");
186 pool->resize_write(3);
189 if (pool->size_write() < 3) {
190 STXXL_MSG(
"queue: inefficient configuration, no blocks for buffered writing available");
193 if (pool->size_prefetch() < 1) {
194 STXXL_MSG(
"queue: inefficient configuration, no blocks for prefetching available");
197 front_block = back_block = pool->steal();
198 back_element = back_block->begin() - 1;
199 front_element = back_block->begin();
200 set_prefetch_aggr(blocks2prefetch_);
213 if (blocks2prefetch_ < 0)
214 blocks2prefetch = pool->size_prefetch();
216 blocks2prefetch = blocks2prefetch_;
222 return blocks2prefetch;
232 if (
UNLIKELY(back_element == back_block->begin() + (block_type::size - 1)))
235 if (front_block == back_block)
240 else if (size() < 2 * block_type::size)
244 assert(bids.empty());
245 size_t gap = front_element - front_block->begin();
247 std::copy(front_element, front_block->end(), front_block->begin());
248 std::copy(back_block->begin(), back_block->begin() + gap, front_block->begin() + (block_type::size - gap));
249 std::copy(back_block->begin() + gap, back_block->end(), back_block->begin());
250 front_element -= gap;
265 bm->new_block(alloc_strategy, newbid, alloc_count++);
268 bids.push_back(newbid);
269 pool->write(back_block, newbid);
270 if (bids.size() <= blocks2prefetch) {
275 back_block = pool->steal();
277 back_element = back_block->begin();
292 if (
UNLIKELY(front_element == front_block->begin() + (block_type::size - 1)))
295 if (back_block == front_block)
299 assert(back_element == front_element);
300 assert(bids.empty());
302 back_element = back_block->begin() - 1;
303 front_element = back_block->begin();
309 if (m_size <= block_type::size)
312 assert(bids.empty());
314 pool->add(front_block);
315 front_block = back_block;
316 front_element = back_block->begin();
321 assert(!bids.empty());
322 request_ptr req = pool->read(front_block, bids.front());
326 for (
unsigned_type i = 0; i < blocks2prefetch && i < bids.size() - 1; ++i)
329 pool->hint(bids[i + 1]);
332 front_element = front_block->begin();
335 bm->delete_block(bids.front());
352 return *back_element;
359 return *back_element;
366 return *front_element;
373 return *front_element;
383 if (front_block != back_block)
384 pool->add(back_block);
385 pool->add(front_block);
393 bm->delete_blocks(bids.begin(), bids.end());
410 return (m_size == 0);
420 #endif // !STXXL_CONTAINERS_QUEUE_HEADER
const value_type & back() const
Returns a const reference at the back of the queue.
queue(pool_type &pool_, int blocks2prefetch_=-1)
Constructs empty queue.
#define STXXL_DEFAULT_BLOCK_SIZE(type)
value_type * back_element
#define STXXL_VERBOSE_QUEUE
unsigned_type alloc_count
unsigned long long int uint64
alloc_strategy_type alloc_strategy
bool empty() const
Returns true if queue is empty.
External FIFO queue container. Introduction to queue container: see STXXL Queue tutorial Design a...
typed_block< block_size, value_type > block_type
#define STXXL_DEFAULT_ALLOC_STRATEGY
read_write_pool< block_type > pool_type
queue(write_pool< block_type > &w_pool, prefetch_pool< block_type > &p_pool, int blocks2prefetch_=-1)
Constructs empty queue.
void push(const value_type &val)
Adds an element in the queue.
#define STXXL_DEPRECATED(x)
Implements dynamically resizable buffered writing pool.
value_type & front()
Returns a mutable reference at the front of the queue.
Implements dynamically resizable prefetching pool.
Block containing elements of fixed length.
AllocStr alloc_strategy_type
const value_type & front() const
Returns a const reference at the front of the queue.
BID< block_size > bid_type
Implements dynamically resizable buffered writing and prefetched reading pool.
choose_int_types< my_pointer_size >::int_type int_type
value_type & back()
Returns a mutable reference at the back of the queue.
value_type * front_element
#define STXXL_BEGIN_NAMESPACE
void init(int blocks2prefetch_=-1)
#define STXXL_VERBOSE1(x)
size_type size() const
Returns the size of the queue.
void set_prefetch_aggr(int_type blocks2prefetch_)
Defines the number of blocks to prefetch (front side). This method should be called whenever the pref...
queue(unsigned_type w_pool_size, unsigned_type p_pool_size, int blocks2prefetch_=-1)
Constructs empty queue with own write and prefetch block pool.
void pop()
Removes element from the queue.
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
unsigned_type blocks2prefetch
std::deque< bid_type > bids
queue(int_type D=-1)
Constructs empty queue with own write and prefetch block pool.
unsigned_type get_prefetch_aggr() const
Returns the number of blocks prefetched from the front side.
#define STXXL_END_NAMESPACE