Created
March 20, 2019 19:46
-
-
Save eugeneko/2f5f000c13ec71ef6c445bcaa36cd574 to your computer and use it in GitHub Desktop.
Prototype of container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <class T, unsigned NBoolsValue = 4, unsigned NIntsValue = 4, unsigned NVariantsValue = 1> | |
| class CompactFlatVariantMap | |
| { | |
| public: | |
| enum class PoolType { Bool, Int, Variant }; | |
| using ElementIndex = unsigned; | |
| static const unsigned PoolTypeBits = 2; | |
| static const unsigned PoolTypeMask = (1 << (PoolTypeBits + 1)) - 1; | |
| static const unsigned NBools = NBoolsValue; | |
| static const unsigned NInts = NIntsValue; | |
| static const unsigned NVariants = NVariantsValue; | |
| static const unsigned NElements = NBools + NInts + NVariants; | |
| ElementIndex Find(const T& key) const | |
| { | |
| const unsigned index = std::find(keys_.begin(), keys_.end(), key) - keys_.begin(); | |
| return index < keys_.end() ? indexes_[index] : M_MAX_UNSIGNED; | |
| } | |
| bool Has(const T& key) const { return Find(key) != M_MAX_UNSIGNED; } | |
| void SetBool(const T& key, bool value) | |
| { | |
| } | |
| void Insert(const T& key, const Variant& value) | |
| { | |
| switch (value.GetType()) | |
| { | |
| case VAR_INT: | |
| default: | |
| break; | |
| } | |
| } | |
| private: | |
| static ElementIndex EncodeIndex(unsigned index, PoolType pool) { return (index << PoolTypeBits) | static_cast<unsigned>(pool) & PoolTypeMask; } | |
| static Pair<unsigned, PoolType> DecodeIndex(ElementIndex index) { return MakePair(index >> PoolTypeBits, static_cast<PoolType>(index & PoolTypeMask)); } | |
| fixed_vector<T, NElements> keys_; | |
| fixed_vector<ElementIndex, NElements> indexes_; | |
| fixed_vector<bool, NBools> poolBools_; | |
| fixed_vector<int, NInts> poolInts_; | |
| fixed_vector<Variant, NVariants> poolVariants_; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment