LLVM  13.0.0git
StringSet.h
Go to the documentation of this file.
1 //===- StringSet.h - An efficient set built on StringMap --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // StringSet - A set-like wrapper for the StringMap.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_ADT_STRINGSET_H
14 #define LLVM_ADT_STRINGSET_H
15 
16 #include "llvm/ADT/StringMap.h"
17 
18 namespace llvm {
19 
20 /// StringSet - A wrapper for StringMap that provides set-like functionality.
21 template <class AllocatorTy = MallocAllocator>
22 class StringSet : public StringMap<NoneType, AllocatorTy> {
24 
25 public:
26  StringSet() = default;
27  StringSet(std::initializer_list<StringRef> initializer) {
28  for (StringRef str : initializer)
29  insert(str);
30  }
31  explicit StringSet(AllocatorTy a) : Base(a) {}
32 
33  std::pair<typename Base::iterator, bool> insert(StringRef key) {
34  return Base::try_emplace(key);
35  }
36 
37  template <typename InputIt>
38  void insert(const InputIt &begin, const InputIt &end) {
39  for (auto it = begin; it != end; ++it)
40  insert(*it);
41  }
42 
43  template <typename ValueTy>
44  std::pair<typename Base::iterator, bool>
45  insert(const StringMapEntry<ValueTy> &mapEntry) {
46  return insert(mapEntry.getKey());
47  }
48 
49  /// Check if the set contains the given \c key.
50  bool contains(StringRef key) const { return Base::FindKey(key) != -1; }
51 };
52 
53 } // end namespace llvm
54 
55 #endif // LLVM_ADT_STRINGSET_H
llvm
Definition: AllocatorList.h:23
llvm::StringMapEntry
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMapEntry.h:98
llvm::StringSet::StringSet
StringSet(AllocatorTy a)
Definition: StringSet.h:31
it
Reference model for inliner Oz decision policy Note this model is also referenced by test Transforms Inline ML tests if replacing it
Definition: README.txt:3
llvm::StringMap< NoneType, MallocAllocator >::end
iterator end()
Definition: StringMap.h:205
llvm::StringSet::insert
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:33
a
=0.0 ? 0.0 :(a > 0.0 ? 1.0 :-1.0) a
Definition: README.txt:489
llvm::StringSet::insert
std::pair< typename Base::iterator, bool > insert(const StringMapEntry< ValueTy > &mapEntry)
Definition: StringSet.h:45
llvm::StringSet::contains
bool contains(StringRef key) const
Check if the set contains the given key.
Definition: StringSet.h:50
llvm::StringMapImpl::FindKey
int FindKey(StringRef Key) const
FindKey - Look up the bucket that contains the specified key.
Definition: StringMap.cpp:132
StringMap.h
llvm::StringSet::insert
void insert(const InputIt &begin, const InputIt &end)
Definition: StringSet.h:38
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
llvm::StringMapEntry::getKey
StringRef getKey() const
Definition: StringMapEntry.h:102
llvm::StringMap< NoneType, MallocAllocator >::begin
iterator begin()
Definition: StringMap.h:204
llvm::StringSet
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:22
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::StringSet::StringSet
StringSet(std::initializer_list< StringRef > initializer)
Definition: StringSet.h:27
llvm::StringSet::StringSet
StringSet()=default
llvm::StringMap::try_emplace
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&... Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
Definition: StringMap.h:315