diff options
Diffstat (limited to 'include/llvm/ADT/StringMap.h')
-rw-r--r-- | include/llvm/ADT/StringMap.h | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h index 9d038560bf92..700bb9e10ef7 100644 --- a/include/llvm/ADT/StringMap.h +++ b/include/llvm/ADT/StringMap.h @@ -30,6 +30,7 @@ namespace llvm { /// StringMapEntryBase - Shared base class of StringMapEntry instances. class StringMapEntryBase { unsigned StrLen; + public: explicit StringMapEntryBase(unsigned Len) : StrLen(Len) {} @@ -48,6 +49,7 @@ protected: unsigned NumItems; unsigned NumTombstones; unsigned ItemSize; + protected: explicit StringMapImpl(unsigned itemSize) : TheTable(nullptr), @@ -85,8 +87,10 @@ protected: /// RemoveKey - Remove the StringMapEntry for the specified key from the /// table, returning it. If the key is not in the table, this returns null. StringMapEntryBase *RemoveKey(StringRef Key); + private: void init(unsigned Size); + public: static StringMapEntryBase *getTombstoneVal() { return (StringMapEntryBase*)-1; @@ -112,6 +116,7 @@ public: template<typename ValueTy> class StringMapEntry : public StringMapEntryBase { StringMapEntry(StringMapEntry &E) = delete; + public: ValueTy second; @@ -205,7 +210,6 @@ public: } }; - /// StringMap - This is an unconventional map that is specialized for handling /// keys that are "strings", which are basically ranges of bytes. This does some /// funky memory allocation and hashing things to make it extremely efficient, @@ -213,9 +217,10 @@ public: template<typename ValueTy, typename AllocatorTy = MallocAllocator> class StringMap : public StringMapImpl { AllocatorTy Allocator; + public: typedef StringMapEntry<ValueTy> MapEntryTy; - + StringMap() : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {} explicit StringMap(unsigned InitialSize) : StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))) {} @@ -227,6 +232,13 @@ public: : StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))), Allocator(A) {} + StringMap(std::initializer_list<std::pair<StringRef, ValueTy>> List) + : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) { + for (const auto &P : List) { + insert(P); + } + } + StringMap(StringMap &&RHS) : StringMapImpl(std::move(RHS)), Allocator(std::move(RHS.Allocator)) {} @@ -386,11 +398,10 @@ public: } }; - -template<typename ValueTy> -class StringMapConstIterator { +template <typename ValueTy> class StringMapConstIterator { protected: StringMapEntryBase **Ptr; + public: typedef StringMapEntry<ValueTy> value_type; @@ -447,7 +458,6 @@ public: return static_cast<StringMapEntry<ValueTy>*>(*this->Ptr); } }; - } #endif |