Files
nd-wfc/prompts/10-bit-container
2025-09-04 09:51:32 +09:00

10 lines
1.3 KiB
Plaintext

We're using c++20, I want you to create a file wfc_bit_container.hpp in include\nd-wfc which contains a templated class whose goal is to minimize the amount of bits we use for masking. The template type should be a number (The number of bits stored) and should have the Size of the container (how many of these integers should we store). The size is 0 by default, which means it's resizable and it should use an std::vector instead of an std::array.
examples of given parameters:
- Bits: 2; Size: 8; -> 2 requires 2 bits, std::array<uint8_t, 2>
- Bits: 3; size: 4; -> 3 requires 4 bits, std::array<uint8_t, 2>
- Bits: 0; size 128; -> 0*128 == 0; std::array<uint8_t, 0>
- Bits: 32; size: 100; -> std::array<uint32_t, 100>
- Bits: 256; size: 0; -> std::vector<uint64_t[2]>
Make sure that the amount of bits used is a power of 2: 0, 1, 2, 4, 8, 16, 32, 64. If more than 64 bits are required, make sure it is a multiple of 64: 64, 128, 196, 256, etc.
We should be able to get/set values with an index, do bit operations like |, &, ^ on individual elements, do std::countl_zero, std::countl_one, std::countr_zero, std::countr_one & std::popcount.
This repo tries to be as optimized as possible. Make good use of `asserts` instead of `if conditions` wherever you are checking something.