chunkedseq
container library for large in-memory data sets
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
chunkedseq_6.cpp
Go to the documentation of this file.
1 
16 #include <iostream>
18 #include <string>
19 #include <assert.h>
20 
21 #include "chunkedseq.hpp"
22 
23 template <class Chunkedseq>
24 void pcopy(typename Chunkedseq::iterator first,
25  typename Chunkedseq::iterator last,
26  Chunkedseq& destination) {
27  using iterator = typename Chunkedseq::iterator;
28  using ptr = typename Chunkedseq::const_pointer;
29 
30  const long cutoff = 8192;
31 
32  long sz = last.size() - first.size();
33 
34  if (sz <= cutoff) {
35 
36  // compute result in a sequential fashion
37  Chunkedseq::for_each_segment(first, last, [&] (ptr lo, ptr hi) {
38  destination.pushn_back(lo, hi-lo);
39  });
40 
41  } else {
42 
43  // select split position to be the median
44  iterator mid = first + (sz/2);
45 
46  Chunkedseq destination2;
47 
48  // recurse on subproblems
49  // calls can execute in parallel
50  pcopy(first, mid, destination);
51  pcopy(mid, last, destination2);
52 
53  // combine results
54  destination.concat(destination2);
55 
56  }
57 }
58 
59 int main(int argc, const char * argv[]) {
60 
61  const int chunk_size = 2;
63 
64  mydeque_type mydeque = { 0, 1, 2, 3, 4, 5 };
65  mydeque_type mydeque2;
66 
67  pcopy(mydeque.begin(), mydeque.end(), mydeque2);
68 
69  std::cout << "mydeque2 contains:";
70  auto p = mydeque2.begin();
71  while (p != mydeque2.end())
72  std::cout << " " << *p++;
73  std::cout << std::endl;
74 
75  return 0;
76 
77 }
78 //! [pcopy_example]
iterator begin() const
Returns iterator to beginning.
void for_each_segment(iterator begin, iterator end, const Body &f)
void pcopy(typename Chunkedseq::iterator first, typename Chunkedseq::iterator last, Chunkedseq &destination)
[pcopy_example]
iterator end() const
Returns iterator to end.
int main(int argc, const char *argv[])
Chunked-sequence functor.