chunkedseq
container library for large in-memory data sets
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
weighted_split.cpp
Go to the documentation of this file.
1 
16 #include <iostream>
18 #include <string>
19 
20 #include "chunkedseq.hpp"
21 
24 
25 const int chunk_capacity = 512;
26 
27 int main(int argc, const char * argv[]) {
28 
29  using value_type = std::string;
30  using weight_type = int;
31 
32  class my_weight_fct {
33  public:
34  // returns 1 if the length of the string is an even number; 0 otherwise
35  weight_type operator()(const value_type& str) const {
36  return (str.size() % 2 == 0) ? 1 : 0;
37  }
38  };
39 
40  using my_cachedmeasure_type =
42 
43  using my_weighted_deque_type =
45 
46  my_weighted_deque_type d = { "Let's", "divide", "this", "sequence", "of",
47  "strings", "into", "two", "pieces" };
48 
49  weight_type nb_even_length_strings = d.get_cached();
50  std::cout << "nb even-length strings: " << nb_even_length_strings << std::endl;
51 
52  my_weighted_deque_type f;
53 
54  d.split([=] (weight_type v) { return v >= nb_even_length_strings/2; }, f);
55 
56  std::cout << "d = " << std::endl;
57  d.for_each([] (value_type& s) { std::cout << s << " "; });
58  std::cout << std::endl;
59  std::cout << std::endl;
60 
61  std::cout << "f = " << std::endl;
62  f.for_each([] (value_type& s) { std::cout << s << " "; });
63  std::cout << std::endl;
64 
65  return 0;
66 
67 }
measured_type get_cached() const
Returns cached measurement.
const int chunk_capacity
[weighted_split_example]
int main(int argc, const char *argv[])
Chunked-sequence functor.