chunkedseq
container library for large in-memory data sets
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Doubly ended queue

The deque structure implements a fast doubly ended queue that supports logarithmic-time operations for both weighted split and concatenation.

Runtime interface

The deque interface has much of the interface of the STL deque. All operations for accessing the front and back of the container (e.g., front, push_front, pop_front, etc.) are supported. In addition, the deque supports splitting and concatenation in logarithmic time and provides a random-access iterator.

Template interface

Like the STL deque, the following deque constructor takes template parameters for the Item and Item_alloc types. The constructor takes three additional template parameters:

1 namespace pasl {
2 namespace data {
3 namespace chunkedseq {
4 namespace bootstrapped {
5 
6 template <
7  class Item,
8  int Chunk_capacity = 512,
9  class Cache = cachedmeasure::trivial<Item, size_t>,
10  template <
11  class Chunk_item,
12  int Capacity,
13  class Chunk_item_alloc=std::allocator<Item>
14  >
15  class Chunk_struct = fixedcapacity::heap_allocated::ringbuffer_ptrx,
16  class Item_alloc = std::allocator<Item>
17 >
18 using deque;
19 
20 }}}}

Example: push and pop

#include <iostream>
#include <string>
#include <assert.h>
#include "chunkedseq.hpp"
int main(int argc, const char * argv[]) {
const int nb = 5;
mydeque_type mydeque;
for (int i = 0; i < nb; i++)
mydeque.push_back(i);
for (int i = 0; i < nb; i++)
mydeque.push_front(nb+i);
assert(mydeque.size() == 2*nb);
std::cout << "mydeque contains:";
for (int i = 0; i < 2*nb; i++) {
int v = (i % 2) ? mydeque.pop_front() : mydeque.pop_back();
std::cout << " " << v;
}
std::cout << std::endl;
assert(mydeque.empty());
return 0;
}

Output

mydeque contains: 4 9 3 8 2 7 1 6 0 5

Example: split and concat

#include <iostream>
#include <string>
#include <assert.h>
#include "chunkedseq.hpp"
static
void myprint(mydeque_type& mydeque) {
auto it = mydeque.begin();
while (it != mydeque.end())
std::cout << " " << *it++;
std::cout << std::endl;
}
int main(int argc, const char * argv[]) {
mydeque_type mydeque = { 0, 1, 2, 3, 4, 5 };
mydeque_type mydeque2;
mydeque.split(size_t(3), mydeque2);
mydeque.pop_back();
mydeque.push_back(8888);
mydeque2.pop_front();
mydeque2.push_front(9999);
std::cout << "Just after split:" << std::endl;
std::cout << "contents of mydeque:";
myprint(mydeque);
std::cout << "contents of mydeque2:";
myprint(mydeque2);
mydeque.concat(mydeque2);
std::cout << "Just after merge:" << std::endl;
std::cout << "contents of mydeque:";
myprint(mydeque);
std::cout << "contents of mydeque2:";
myprint(mydeque2);
return 0;
}

Output

Just after split:
contents of mydeque: 0 1 8888
contents of mydeque2: 9999 4 5
Just after merge:
contents of mydeque: 0 1 8888 9999 4 5
contents of mydeque2: