16 #define BOOTCHUNKEDSEQ_CHECK 1
25 #include "cmdline.hpp"
27 #include "bootchunkedseqnew.hpp"
42 IntItem() : value(0) {}
43 size_t get_cached()
const {
50 class IntItemGenerator {
52 static IntItem* from_int(
int n) {
53 IntItem* x =
new IntItem();
58 static int to_int(
const IntItem*& x) {
62 static int to_int(IntItem*& x) {
66 static void print(
const IntItem* x) {
67 printf(
"%d", IntItemGenerator::to_int(x));
70 static void free(IntItem*& x) {
79 template<
int Chunk_capacity>
80 class IntPointerSeqOf {
84 template <
class Item,
class Size>
88 using size_type = Size;
96 measured_type operator()(
const value_type& v)
const {
97 return v->get_cached();
101 measured_type m = algebra_type::identity();
102 for (
auto p = lo; p < hi; p++)
103 m = algebra_type::combine(m,
operator()(*p));
109 static void swap(measured_type& x, measured_type y) {
116 using sized_cache_measure = cache_size<value_type, size_t>;
118 using measure_type =
typename sized_cache_measure::measure_type;
119 using measured_type =
typename sized_cache_measure::measured_type;
120 using size_type = size_t;
121 using self_type = IntPointerSeqOf<Chunk_capacity>;
128 inline size_t size() {
133 seq.push_front(x, meas(x));
137 seq.push_back(x, meas(x));
141 return seq.pop_front();
145 return seq.pop_back();
148 void concat(self_type& other) {
149 seq.concat(other.seq);
153 class middle_measured_fields {
155 static size_type& size(measured_type& m) {
158 static size_type csize(measured_type m) {
173 void split(
size_t index, self_type& other) {
174 seq.split(index, other.seq);
182 static void print(
typename seq_type::measured_type& c) {
187 template <
class ItemPr
inter>
189 seq.template print<ItemPrinter>();
202 int main(
int argc,
char** argv) {
203 pasl::util::cmdline::set(argc, argv);
205 size_t chunk_capacity = (size_t) pasl::util::cmdline::parse_or_default_int(
"chunk_capacity", 2);
206 if (chunk_capacity == 2)
208 else if (chunk_capacity == 4)
211 pasl::util::cmdline::die(
"unsupported capacity");
Unit tests for sequences.
int main(int argc, char **argv)
Routines for finding an item in a container via binary search.
measured_type get_cached() const
const int chunk_capacity
[weighted_split_example]