You have a packaging problem. The only idea I can get is that you want to find an LCM N and some power in two. It will not be so easy, but definitely functional.
In addition, you cannot manipulate some data with a large size, so you need to pack it into a larger integer type. The table will contain the data packed, but the "accessor" will provide the unpacked file.
Now we can build this to create a common table that will work for any package:
template <typename Pack> class Table { public: typedef typename Pack::UnpackedType UnpackedType; bool empty() const; size_t size() const; UnpackedType get(size_t i) const; void set(size_t i, UnpackedType t); private: static size_t const NumberBits = Pack::Number; static size_t const Density = Pack::Density; std::deque<Pack> data; }; template <typename Pack> bool Table<Pack>::empty() const { return data.empty(); } template <typename Pack> size_t Table<Pack>::size() const { return data.size() * Density; } template <typename Pack> typename Table<Pack>::UnpackedType Table<Pack>::get(size_t i) const { Pack const& pack = data.at(i / Density); return pack.get(i % Density); }
A smarter way for Pack<N> would be to output getters and views ... but this doesn't seem to be necessary because the Pack interface is minimal and Table can represent a richer interface without asking for more.
Matthieu M.
source share