algorithm-engineering/src/container.cpp
2025-09-28 14:58:27 +02:00

30 lines
832 B
C++
Executable File

#include "container.hpp"
#include <cstddef>
#include <span>
#include <iostream>
namespace ae {
container::container(std::span<const element_type> data) {
// Reserve enough space for the chunks to avoid relocation while building the structure
container::Directory dir(data.size() / container::chunk_size + 1);
auto entry = 0;
for (auto first = data.begin(); first < data.end();) {
const auto last = (data.end() - first) < container::chunk_size ? data.end() : first + container::chunk_size;
Chunk chunk;
// This could be improved by just pointing dir[entry] to first, removing the copy process.
std::copy(first, last, chunk.begin());
dir[entry++] = chunk;
first = last;
}
this->data = dir;
this->size_ = data.size();
}
uint32_t container::size() { return this->size_; }
} // namespace ae