Vince's CSV Parser
Loading...
Searching...
No Matches
row_queue_batch.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <cstddef>
8#include <deque>
9#include <iterator>
10#include <vector>
11
12namespace csv {
13 namespace internals {
14 template<typename T>
15 size_t drain_front_batches(
16 std::deque<std::vector<T>>& batches,
17 size_t& front_index,
18 size_t& size,
19 std::vector<T>& out,
20 size_t max_items
21 ) {
22 const size_t drain_count = size < max_items ? size : max_items;
23 size_t remaining = drain_count;
24
25 out.reserve(out.size() + drain_count);
26
27 while (remaining > 0) {
28 auto& batch = batches.front();
29 const size_t available = batch.size() - front_index;
30 const size_t take = available < remaining ? available : remaining;
31 const auto first_offset = static_cast<typename std::vector<T>::difference_type>(front_index);
32 const auto take_offset = static_cast<typename std::vector<T>::difference_type>(take);
33 auto first = batch.begin() + first_offset;
34 auto last = first + take_offset;
35
36 out.insert(
37 out.end(),
38 std::make_move_iterator(first),
39 std::make_move_iterator(last)
40 );
41
42 front_index += take;
43 size -= take;
44 remaining -= take;
45
46 while (!batches.empty() && front_index >= batches.front().size()) {
47 batches.pop_front();
48 front_index = 0;
49 }
50 }
51
52 return drain_count;
53 }
54 }
55}
The all encompassing namespace.