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

Our bag is a generic container that trades the guarantee of order between its items for stronger guarantees on space usage and faster push and pop operations than the corresponding properties of the stack structure. In particular, the bag guarantees that there are no empty spaces in between consecutive items of the sequence, whereas stack and deque can guarantee only that no more than half of the cells of the chunks are empty.

Runtime interface

Although our bag is unordered in general, in particular use cases, order among items is guaranteed. Order of insertion and removal of the items is guaranteed by the bag under any sequence of push or pop operations that affect the back of the container. The split and concatenation operations typically reorder items.

The container supports front, push_front and pop_front operations for the sole purpose of interface compatibility. These operations simply perform the corresponding actions on the back of the container.

Template interface

The template interface of the bag is similar to that of stack.

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  class Item_alloc = std::allocator<Item>
11 >
12 using bagopt;
13 
14 }}}}

Example

#include <iostream>
#include <string>
#include "chunkedbag.hpp"
int main(int argc, const char * argv[]) {
mybag_type mybag = { 0, 1, 2, 3, 4 };
std::cout << "mybag contains:";
while (! mybag.empty())
std::cout << " " << mybag.pop();
std::cout << std::endl;
return 0;
}

Output

mybag contains: 4 3 2 1 0