17 static constexpr std::int32_t
kUnknown = INT32_MIN;
23 chunks_.resize((n + kChunk - 1) / kChunk);
25 bool empty()
const {
return n_ == 0; }
26 std::size_t
size()
const {
return n_; }
30 auto& c = chunks_[i >> kShift];
32 c = std::make_unique<std::int32_t[]>(kChunk);
33 for (std::size_t k = 0; k < kChunk; ++k) c[k] =
kUnknown;
35 return c[i & (kChunk - 1)];
38 std::int32_t
get(std::size_t i)
const {
39 const auto& c = chunks_[i >> kShift];
40 return c ? c[i & (kChunk - 1)] :
kUnknown;
45 for (
const auto& c : chunks_) b += c ? kChunk *
sizeof(std::int32_t) : 0;
50 static constexpr std::size_t kShift = 12;
51 static constexpr std::size_t kChunk = std::size_t{1} << kShift;
53 std::vector<std::unique_ptr<std::int32_t[]>> chunks_;
std::int32_t get(std::size_t i) const
The entry without allocating: unknown where nothing was written.
static constexpr std::int32_t kUnknown
std::int32_t & operator[](std::size_t i)
The entry, allocating its chunk (all unknown) if needed.
void init(std::size_t n)
n entries, all unknown; drops any earlier contents.
std::size_t bytes() const
Bytes held by allocated chunks (diagnostics, test).