in kll/include/kll_helper_impl.hpp [131:156]
void kll_helper::merge_sorted_arrays(T* buf, uint32_t start_a, uint32_t len_a, uint32_t start_b, uint32_t len_b, uint32_t start_c) {
const uint32_t len_c = len_a + len_b;
const uint32_t lim_a = start_a + len_a;
const uint32_t lim_b = start_b + len_b;
const uint32_t lim_c = start_c + len_c;
uint32_t a = start_a;
uint32_t b = start_b;
for (uint32_t c = start_c; c < lim_c; c++) {
if (a == lim_a) {
if (b != c) buf[c] = std::move(buf[b]);
b++;
} else if (b == lim_b) {
if (a != c) buf[c] = std::move(buf[a]);
a++;
} else if (C()(buf[a], buf[b])) {
if (a != c) buf[c] = std::move(buf[a]);
a++;
} else {
if (b != c) buf[c] = std::move(buf[b]);
b++;
}
}
if (a != lim_a || b != lim_b) throw std::logic_error("inconsistent state");
}