LLVM 20.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/// \file
10/// StringSet - A set-like wrapper for the StringMap.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ADT_STRINGSET_H
15#define LLVM_ADT_STRINGSET_H
16
17#include "llvm/ADT/StringMap.h"
18
19namespace llvm {
20
21/// StringSet - A wrapper for StringMap that provides set-like functionality.
22template <class AllocatorTy = MallocAllocator>
23class StringSet : public StringMap<std::nullopt_t, AllocatorTy> {
25
26public:
27 StringSet() = default;
28 StringSet(std::initializer_list<StringRef> initializer) {
29 for (StringRef str : initializer)
30 insert(str);
31 }
32 template <typename Container> explicit StringSet(Container &&C) {
33 for (auto &&Str : C)
34 insert(Str);
35 }
36 explicit StringSet(AllocatorTy a) : Base(a) {}
37
38 std::pair<typename Base::iterator, bool> insert(StringRef key) {
39 return Base::try_emplace(key);
40 }
41
42 template <typename InputIt>
43 void insert(InputIt begin, InputIt end) {
44 for (auto it = begin; it != end; ++it)
45 insert(*it);
46 }
47
48 template <typename ValueTy>
49 std::pair<typename Base::iterator, bool>
51 return insert(mapEntry.getKey());
52 }
53
54 /// Check if the set contains the given \c key.
55 bool contains(StringRef key) const { return Base::FindKey(key) != -1; }
56};
57
58} // end namespace llvm
59
60#endif // LLVM_ADT_STRINGSET_H
This file defines the StringMap class.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef getKey() const
int FindKey(StringRef Key) const
FindKey - Look up the bucket that contains the specified key.
Definition: StringMap.h:74
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:128
iterator end()
Definition: StringMap.h:220
iterator begin()
Definition: StringMap.h:219
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:368
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:23
StringSet()=default
StringSet(AllocatorTy a)
Definition: StringSet.h:36
StringSet(Container &&C)
Definition: StringSet.h:32
std::pair< typename Base::iterator, bool > insert(const StringMapEntry< ValueTy > &mapEntry)
Definition: StringSet.h:50
void insert(InputIt begin, InputIt end)
Definition: StringSet.h:43
StringSet(std::initializer_list< StringRef > initializer)
Definition: StringSet.h:28
bool contains(StringRef key) const
Check if the set contains the given key.
Definition: StringSet.h:55
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:38
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18