Skip to content

Instantly share code, notes, and snippets.

@jamesu
Created November 27, 2024 16:37
Show Gist options
  • Save jamesu/449774f1e9660f5610b3e986aa09c566 to your computer and use it in GitHub Desktop.
Save jamesu/449774f1e9660f5610b3e986aa09c566 to your computer and use it in GitHub Desktop.
template <typename V, int S, int T>
class TableLookup {
public:
TableLookup(DataChunker* chunker) : mTables((S+(T-1)) / T, nullptr), mChunker(chunker), mNumEntries(0) {}
bool insert(U32 address, const V& value);
bool lookup(U32 address, V& value) const;
void clear(U32 address);
bool isFull() const;
inline U32 size() const;
inline U32 lastTableIdx() const;
inline U32 lastTableEntry(U32 tableIdx) const;
private:
struct Table {
std::array<V, T> values;
std::bitset<T> residency;
};
DataChunker* mChunker;
std::vector<Table*> mTables;
U32 mNumEntries;
};
typedef TableLookup<U16, 2097152, 1024> CharMap;
typedef TableLookup<U16, 65536, 2048> GlyphMap;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment