Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:10

0001 //===- StringSet.h - An efficient set built on StringMap --------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 ///  StringSet - A set-like wrapper for the StringMap.
0011 ///
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_ADT_STRINGSET_H
0015 #define LLVM_ADT_STRINGSET_H
0016 
0017 #include "llvm/ADT/StringMap.h"
0018 
0019 namespace llvm {
0020 
0021 /// StringSet - A wrapper for StringMap that provides set-like functionality.
0022 template <class AllocatorTy = MallocAllocator>
0023 class StringSet : public StringMap<std::nullopt_t, AllocatorTy> {
0024   using Base = StringMap<std::nullopt_t, AllocatorTy>;
0025 
0026 public:
0027   StringSet() = default;
0028   StringSet(std::initializer_list<StringRef> initializer) {
0029     for (StringRef str : initializer)
0030       insert(str);
0031   }
0032   template <typename Container> explicit StringSet(Container &&C) {
0033     for (auto &&Str : C)
0034       insert(Str);
0035   }
0036   explicit StringSet(AllocatorTy a) : Base(a) {}
0037 
0038   std::pair<typename Base::iterator, bool> insert(StringRef key) {
0039     return Base::try_emplace(key);
0040   }
0041 
0042   template <typename InputIt>
0043   void insert(InputIt begin, InputIt end) {
0044     for (auto it = begin; it != end; ++it)
0045       insert(*it);
0046   }
0047 
0048   template <typename ValueTy>
0049   std::pair<typename Base::iterator, bool>
0050   insert(const StringMapEntry<ValueTy> &mapEntry) {
0051     return insert(mapEntry.getKey());
0052   }
0053 
0054   /// Check if the set contains the given \c key.
0055   bool contains(StringRef key) const { return Base::FindKey(key) != -1; }
0056 };
0057 
0058 } // end namespace llvm
0059 
0060 #endif // LLVM_ADT_STRINGSET_H