LLVM: include/llvm/ADT/DenseSet.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_ADT_DENSESET_H

15#define LLVM_ADT_DENSESET_H

16

23#include

24#include <initializer_list>

25#include

26#include

27

28namespace llvm {

29

31

33

34

35

45

46

47

48

49

50

51

52

53

54

55template <typename ValueT, typename MapTy, typename ValueInfoT>

57 static_assert(sizeof(typename MapTy::value_type) == sizeof(ValueT),

58 "DenseMap buckets unexpectedly large!");

59 MapTy TheMap;

60

61 template

63

64public:

68

69 explicit DenseSetImpl(unsigned InitialReserve = 0) : TheMap(InitialReserve) {}

70

71 template

76

79 insert(Elems.begin(), Elems.end());

80 }

81

82 template

85

86 [[nodiscard]] bool empty() const { return TheMap.empty(); }

87 [[nodiscard]] size_type size() const { return TheMap.size(); }

88 [[nodiscard]] size_t getMemorySize() const { return TheMap.getMemorySize(); }

89

90

91

93

94

95

97

98 void clear() { TheMap.clear(); }

99

100 bool erase(const ValueT &V) { return TheMap.erase(V); }

101

103

104private:

105 template class DenseSetIterator {

107

108 using MapIteratorT =

109 std::conditional_t<IsConst, typename MapTy::const_iterator,

110 typename MapTy::iterator>;

111

112 MapIteratorT I;

113

114 public:

115 using difference_type = typename MapIteratorT::difference_type;

116 using iterator_category = std::forward_iterator_tag;

117 using value_type = ValueT;

118 using pointer =

119 std::conditional_t<IsConst, const value_type *, value_type *>;

120 using reference =

121 std::conditional_t<IsConst, const value_type &, value_type &>;

122

123 DenseSetIterator() = default;

124 DenseSetIterator(MapIteratorT I) : I(I) {}

125

126

127 template <bool C = IsConst, typename = std::enable_if_t>

128 DenseSetIterator(const DenseSetIterator &Other) : I(Other.I) {}

129

130 reference operator*() const { return I->getFirst(); }

131 pointer operator->() const { return &I->getFirst(); }

132

133 DenseSetIterator &operator++() {

134 ++I;

135 return *this;

136 }

137 DenseSetIterator operator++(int) {

138 auto T = *this;

139 ++I;

140 return T;

141 }

142

143 friend bool operator==(const DenseSetIterator &LHS,

144 const DenseSetIterator &RHS) {

145 return LHS.I == RHS.I;

146 }

147 friend bool operator!=(const DenseSetIterator &LHS,

148 const DenseSetIterator &RHS) {

149 return LHS.I != RHS.I;

150 }

151 };

152

153public:

154 using iterator = DenseSetIterator;

156

159

166

173

174

175 [[nodiscard]] bool contains(const_arg_type_t V) const {

176 return TheMap.contains(V);

177 }

178

179

180 [[nodiscard]] size_type count(const_arg_type_t V) const {

181 return TheMap.count(V);

182 }

183

184

185

186

187

188

189 template

191 return iterator(TheMap.find_as(Val));

192 }

193 template

194 [[nodiscard]]

198

201

202 std::pair<iterator, bool> insert(const ValueT &V) {

203 return TheMap.try_emplace(V);

204 }

205

206 std::pair<iterator, bool> insert(ValueT &&V) {

207 return TheMap.try_emplace(std::move(V));

208 }

209

210

211

212 template

213 std::pair<iterator, bool> insert_as(const ValueT &V,

214 const LookupKeyT &LookupKey) {

216 }

217 template

218 std::pair<iterator, bool> insert_as(ValueT &&V, const LookupKeyT &LookupKey) {

220 }

221

222

223 template void insert(InputIt I, InputIt E) {

224 for (; I != E; ++I)

226 }

227

231};

232

233

234

235

236

237

238

239template <typename ValueT, typename MapTy, typename ValueInfoT>

240[[nodiscard]] bool

243 if (LHS.size() != RHS.size())

244 return false;

245

246 for (auto &E : LHS)

247 if (RHS.count(E))

248 return false;

249

250 return true;

251}

252

253

254

255

256template <typename ValueT, typename MapTy, typename ValueInfoT>

257[[nodiscard]] bool

260 return !(LHS == RHS);

261}

262

263template <typename ValueT, typename ValueInfoT>

266 ValueInfoT>;

267

268template <typename ValueT, unsigned InlineBuckets, typename ValueInfoT>

273 ValueInfoT>;

274

275}

276

277

278template <typename ValueT, typename ValueInfoT = DenseMapInfo>

281

282public:

283 using BaseT::BaseT;

284};

285

286

287

288template <typename ValueT, unsigned InlineBuckets = 4,

293

294public:

295 using BaseT::BaseT;

296};

297

298}

299

300#endif

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

This file defines DenseMapInfo traits for DenseMap.

This file defines the DenseMap class.

bool operator==(const MergedFunctionsInfo &LHS, const MergedFunctionsInfo &RHS)

ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))

This file contains library features backported from future STL versions.

Implements a dense probed hash-table based set.

Definition DenseSet.h:279

Implements a dense probed hash-table based set with some number of buckets stored inline.

Definition DenseSet.h:291

Base class for DenseSet and DenseSmallSet.

Definition DenseSet.h:56

const_iterator find(const_arg_type_t< ValueT > V) const

Definition DenseSet.h:170

std::pair< iterator, bool > insert(ValueT &&V)

Definition DenseSet.h:206

DenseSetImpl(llvm::from_range_t, Range &&R)

Definition DenseSet.h:83

std::pair< iterator, bool > insert(const ValueT &V)

Definition DenseSet.h:202

void clear()

Definition DenseSet.h:98

size_t getMemorySize() const

Definition DenseSet.h:88

DenseSetIterator< false > iterator

Definition DenseSet.h:154

const_iterator end() const

Definition DenseSet.h:163

const_iterator begin() const

Definition DenseSet.h:160

iterator find(const_arg_type_t< ValueT > V)

Definition DenseSet.h:167

std::pair< iterator, bool > insert_as(const ValueT &V, const LookupKeyT &LookupKey)

Definition DenseSet.h:213

void reserve(size_t Size)

Definition DenseSet.h:96

iterator find_as(const LookupKeyT &Val)

Definition DenseSet.h:190

void insert_range(Range &&R)

Definition DenseSet.h:228

ValueT key_type

Definition DenseSet.h:65

const_iterator find_as(const LookupKeyT &Val) const

Definition DenseSet.h:195

iterator end()

Definition DenseSet.h:158

size_type size() const

Definition DenseSet.h:87

bool empty() const

Definition DenseSet.h:86

std::pair< iterator, bool > insert_as(ValueT &&V, const LookupKeyT &LookupKey)

Definition DenseSet.h:218

unsigned size_type

Definition DenseSet.h:67

void insert(InputIt I, InputIt E)

Definition DenseSet.h:223

void swap(DenseSetImpl &RHS)

Definition DenseSet.h:102

ValueT value_type

Definition DenseSet.h:66

DenseSetImpl(unsigned InitialReserve=0)

Definition DenseSet.h:69

bool contains(const_arg_type_t< ValueT > V) const

Definition DenseSet.h:175

iterator begin()

Definition DenseSet.h:157

DenseSetImpl(const InputIt &I, const InputIt &E)

Definition DenseSet.h:72

void resize(size_t Size)

Definition DenseSet.h:92

DenseSetIterator< true > const_iterator

Definition DenseSet.h:155

void erase(iterator I)

Definition DenseSet.h:199

bool erase(const ValueT &V)

Definition DenseSet.h:100

DenseSetImpl(std::initializer_list< ValueT > Elems)

Definition DenseSet.h:77

void erase(const_iterator CI)

Definition DenseSet.h:200

size_type count(const_arg_type_t< ValueT > V) const

Definition DenseSet.h:180

const DenseSetEmpty & getSecond() const

Definition DenseSet.h:43

const KeyT & getFirst() const

Definition DenseSet.h:41

DenseSetEmpty & getSecond()

Definition DenseSet.h:42

KeyT & getFirst()

Definition DenseSet.h:40

A self-contained host- and target-independent arbitrary-precision floating-point software implementat...

bool operator!=(const DenseSetImpl< ValueT, MapTy, ValueInfoT > &LHS, const DenseSetImpl< ValueT, MapTy, ValueInfoT > &RHS)

Inequality comparison for DenseSet.

Definition DenseSet.h:258

bool operator==(const DenseSetImpl< ValueT, MapTy, ValueInfoT > &LHS, const DenseSetImpl< ValueT, MapTy, ValueInfoT > &RHS)

Equality comparison for DenseSet.

Definition DenseSet.h:241

DenseSetImpl< ValueT, DenseMap< ValueT, DenseSetEmpty, ValueInfoT, DenseSetPair< ValueT > >, ValueInfoT > DenseSet

Definition DenseSet.h:264

DenseSetImpl< ValueT, SmallDenseMap< ValueT, DenseSetEmpty, InlineBuckets, ValueInfoT, DenseSetPair< ValueT > >, ValueInfoT > SmallDenseSet

Definition DenseSet.h:269

This is an optimization pass for GlobalISel generic memory operations.

constexpr auto adl_begin(RangeT &&range) -> decltype(adl_detail::begin_impl(std::forward< RangeT >(range)))

Returns the begin iterator to range using std::begin and function found through Argument-Dependent Lo...

constexpr auto adl_end(RangeT &&range) -> decltype(adl_detail::end_impl(std::forward< RangeT >(range)))

Returns the end iterator to range using std::end and functions found through Argument-Dependent Looku...

uint64_t PowerOf2Ceil(uint64_t A)

Returns the power of two which is greater than or equal to the given value.

Implement std::hash so that hash_code can be used in STL containers.

An information struct used to provide DenseMap with the various necessary components for a given valu...

std::conditional_t< std::is_pointer_v< T >, typename add_const_past_pointer< T >::type, const T & > type