WPILibC++ 2023.4.3-108-ge5452e3
StringMap.h
Go to the documentation of this file.
1//===- StringMap.h - String Hash table map interface ------------*- 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/// This file defines the StringMap class.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef WPIUTIL_WPI_STRINGMAP_H
15#define WPIUTIL_WPI_STRINGMAP_H
16
17#include "wpi/StringMapEntry.h"
18#include "wpi/iterator.h"
19#include "wpi/AllocatorBase.h"
20#include "wpi/MemAlloc.h"
21#include "wpi/SmallVector.h"
22#include "wpi/iterator.h"
23#include "wpi/iterator_range.h"
25#include <initializer_list>
26#include <iterator>
27
28namespace wpi {
29
30template <typename ValueTy> class StringMapConstIterator;
31template <typename ValueTy> class StringMapIterator;
32template <typename ValueTy> class StringMapKeyIterator;
33
34/// StringMapImpl - This is the base class of StringMap that is shared among
35/// all of its instantiations.
37protected:
38 // Array of NumBuckets pointers to entries, null pointers are holes.
39 // TheTable[NumBuckets] contains a sentinel value for easy iteration. Followed
40 // by an array of the actual hash values as unsigned integers.
42 unsigned NumBuckets = 0;
43 unsigned NumItems = 0;
44 unsigned NumTombstones = 0;
45 unsigned ItemSize;
46
47protected:
48 explicit StringMapImpl(unsigned itemSize) : ItemSize(itemSize) {}
50 : TheTable(RHS.TheTable), NumBuckets(RHS.NumBuckets),
51 NumItems(RHS.NumItems), NumTombstones(RHS.NumTombstones),
52 ItemSize(RHS.ItemSize) {
53 RHS.TheTable = nullptr;
54 RHS.NumBuckets = 0;
55 RHS.NumItems = 0;
56 RHS.NumTombstones = 0;
57 }
58
59 StringMapImpl(unsigned InitSize, unsigned ItemSize);
60 unsigned RehashTable(unsigned BucketNo = 0);
61
62 /// LookupBucketFor - Look up the bucket that the specified string should end
63 /// up in. If it already exists as a key in the map, the Item pointer for the
64 /// specified bucket will be non-null. Otherwise, it will be null. In either
65 /// case, the FullHashValue field of the bucket will be set to the hash value
66 /// of the string.
68
69 /// FindKey - Look up the bucket that contains the specified key. If it exists
70 /// in the map, return the bucket number of the key. Otherwise return -1.
71 /// This does not modify the map.
72 int FindKey(std::string_view Key) const;
73
74 /// RemoveKey - Remove the specified StringMapEntry from the table, but do not
75 /// delete it. This aborts if the value isn't in the table.
77
78 /// RemoveKey - Remove the StringMapEntry for the specified key from the
79 /// table, returning it. If the key is not in the table, this returns null.
81
82 /// Allocate the table with the specified number of buckets and otherwise
83 /// setup the map as empty.
84 void init(unsigned Size);
85
86public:
87 static constexpr uintptr_t TombstoneIntVal =
88 static_cast<uintptr_t>(-1)
90
92 return reinterpret_cast<StringMapEntryBase *>(TombstoneIntVal);
93 }
94
95 unsigned getNumBuckets() const { return NumBuckets; }
96 unsigned getNumItems() const { return NumItems; }
97
98 bool empty() const { return NumItems == 0; }
99 unsigned size() const { return NumItems; }
100
101 void swap(StringMapImpl &Other) {
106 }
107};
108
109/// StringMap - This is an unconventional map that is specialized for handling
110/// keys that are "strings", which are basically ranges of bytes. This does some
111/// funky memory allocation and hashing things to make it extremely efficient,
112/// storing the string data *after* the value in the map.
113template <typename ValueTy, typename AllocatorTy = MallocAllocator>
114class StringMap : public StringMapImpl {
115 AllocatorTy Allocator;
116
117public:
119
120 StringMap() : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {}
121
122 explicit StringMap(unsigned InitialSize)
123 : StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))) {}
124
125 explicit StringMap(AllocatorTy A)
126 : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))), Allocator(A) {
127 }
128
129 StringMap(unsigned InitialSize, AllocatorTy A)
130 : StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))),
131 Allocator(A) {}
132
133 StringMap(std::initializer_list<std::pair<std::string_view, ValueTy>> List)
134 : StringMapImpl(List.size(), static_cast<unsigned>(sizeof(MapEntryTy))) {
135 insert(List);
136 }
137
139 : StringMapImpl(std::move(RHS)), Allocator(std::move(RHS.Allocator)) {}
140
142 : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))),
143 Allocator(RHS.Allocator) {
144 if (RHS.empty())
145 return;
146
147 // Allocate TheTable of the same size as RHS's TheTable, and set the
148 // sentinel appropriately (and NumBuckets).
149 init(RHS.NumBuckets);
150 unsigned *HashTable = (unsigned *)(TheTable + NumBuckets + 1),
151 *RHSHashTable = (unsigned *)(RHS.TheTable + NumBuckets + 1);
152
153 NumItems = RHS.NumItems;
155 for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
156 StringMapEntryBase *Bucket = RHS.TheTable[I];
157 if (!Bucket || Bucket == getTombstoneVal()) {
158 TheTable[I] = Bucket;
159 continue;
160 }
161
163 static_cast<MapEntryTy *>(Bucket)->getKey(), Allocator,
164 static_cast<MapEntryTy *>(Bucket)->getValue());
165 HashTable[I] = RHSHashTable[I];
166 }
167
168 // Note that here we've copied everything from the RHS into this object,
169 // tombstones included. We could, instead, have re-probed for each key to
170 // instantiate this new object without any tombstone buckets. The
171 // assumption here is that items are rarely deleted from most StringMaps,
172 // and so tombstones are rare, so the cost of re-probing for all inputs is
173 // not worthwhile.
174 }
175
178 std::swap(Allocator, RHS.Allocator);
179 return *this;
180 }
181
183 // Delete all the elements in the map, but don't reset the elements
184 // to default values. This is a copy of clear(), but avoids unnecessary
185 // work not required in the destructor.
186 if (!empty()) {
187 for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
188 StringMapEntryBase *Bucket = TheTable[I];
189 if (Bucket && Bucket != getTombstoneVal()) {
190 static_cast<MapEntryTy *>(Bucket)->Destroy(Allocator);
191 }
192 }
193 }
194 free(TheTable);
195 }
196
197 AllocatorTy &getAllocator() { return Allocator; }
198 const AllocatorTy &getAllocator() const { return Allocator; }
199
200 using key_type = const char *;
201 using mapped_type = ValueTy;
203 using size_type = size_t;
204
207
209 iterator end() { return iterator(TheTable + NumBuckets, true); }
211 return const_iterator(TheTable, NumBuckets == 0);
212 }
214 return const_iterator(TheTable + NumBuckets, true);
215 }
216
220 }
221
223 int Bucket = FindKey(Key);
224 if (Bucket == -1)
225 return end();
226 return iterator(TheTable + Bucket, true);
227 }
228
230 int Bucket = FindKey(Key);
231 if (Bucket == -1)
232 return end();
233 return const_iterator(TheTable + Bucket, true);
234 }
235
236 /// lookup - Return the entry for the specified key, or a default
237 /// constructed value if no such entry exists.
238 ValueTy lookup(std::string_view Key) const {
239 const_iterator it = find(Key);
240 if (it != end())
241 return it->second;
242 return ValueTy();
243 }
244
245 /// Lookup the ValueTy for the \p Key, or create a default constructed value
246 /// if the key is not in the map.
247 ValueTy &operator[](std::string_view Key) { return try_emplace(Key).first->second; }
248
249 /// count - Return 1 if the element is in the map, 0 otherwise.
250 size_type count(std::string_view Key) const { return find(Key) == end() ? 0 : 1; }
251
252 template <typename InputTy>
253 size_type count(const StringMapEntry<InputTy> &MapEntry) const {
254 return count(MapEntry.getKey());
255 }
256
257 /// equal - check whether both of the containers are equal.
258 bool operator==(const StringMap &RHS) const {
259 if (size() != RHS.size())
260 return false;
261
262 for (const auto &KeyValue : *this) {
263 auto FindInRHS = RHS.find(KeyValue.getKey());
264
265 if (FindInRHS == RHS.end())
266 return false;
267
268 if (!(KeyValue.getValue() == FindInRHS->getValue()))
269 return false;
270 }
271
272 return true;
273 }
274
275 bool operator!=(const StringMap &RHS) const { return !(*this == RHS); }
276
277 /// insert - Insert the specified key/value pair into the map. If the key
278 /// already exists in the map, return false and ignore the request, otherwise
279 /// insert it and return true.
280 bool insert(MapEntryTy *KeyValue) {
281 unsigned BucketNo = LookupBucketFor(KeyValue->getKey());
282 StringMapEntryBase *&Bucket = TheTable[BucketNo];
283 if (Bucket && Bucket != getTombstoneVal())
284 return false; // Already exists in map.
285
286 if (Bucket == getTombstoneVal())
288 Bucket = KeyValue;
289 ++NumItems;
290 assert(NumItems + NumTombstones <= NumBuckets);
291
292 RehashTable();
293 return true;
294 }
295
296 /// insert - Inserts the specified key/value pair into the map if the key
297 /// isn't already in the map. The bool component of the returned pair is true
298 /// if and only if the insertion takes place, and the iterator component of
299 /// the pair points to the element with key equivalent to the key of the pair.
300 std::pair<iterator, bool> insert(std::pair<std::string_view, ValueTy> KV) {
301 return try_emplace(KV.first, std::move(KV.second));
302 }
303
304 /// Inserts elements from range [first, last). If multiple elements in the
305 /// range have keys that compare equivalent, it is unspecified which element
306 /// is inserted .
307 template <typename InputIt> void insert(InputIt First, InputIt Last) {
308 for (InputIt It = First; It != Last; ++It)
309 insert(*It);
310 }
311
312 /// Inserts elements from initializer list ilist. If multiple elements in
313 /// the range have keys that compare equivalent, it is unspecified which
314 /// element is inserted
315 void insert(std::initializer_list<std::pair<std::string_view, ValueTy>> List) {
316 insert(List.begin(), List.end());
317 }
318
319 /// Inserts an element or assigns to the current element if the key already
320 /// exists. The return type is the same as try_emplace.
321 template <typename V>
322 std::pair<iterator, bool> insert_or_assign(std::string_view Key, V &&Val) {
323 auto Ret = try_emplace(Key, std::forward<V>(Val));
324 if (!Ret.second)
325 Ret.first->second = std::forward<V>(Val);
326 return Ret;
327 }
328
329 /// Emplace a new element for the specified key into the map if the key isn't
330 /// already in the map. The bool component of the returned pair is true
331 /// if and only if the insertion takes place, and the iterator component of
332 /// the pair points to the element with key equivalent to the key of the pair.
333 template <typename... ArgsTy>
334 std::pair<iterator, bool> try_emplace(std::string_view Key, ArgsTy &&... Args) {
335 unsigned BucketNo = LookupBucketFor(Key);
336 StringMapEntryBase *&Bucket = TheTable[BucketNo];
337 if (Bucket && Bucket != getTombstoneVal())
338 return std::make_pair(iterator(TheTable + BucketNo, false),
339 false); // Already exists in map.
340
341 if (Bucket == getTombstoneVal())
343 Bucket = MapEntryTy::Create(Key, Allocator, std::forward<ArgsTy>(Args)...);
344 ++NumItems;
345 assert(NumItems + NumTombstones <= NumBuckets);
346
347 BucketNo = RehashTable(BucketNo);
348 return std::make_pair(iterator(TheTable + BucketNo, false), true);
349 }
350
351 // clear - Empties out the StringMap
352 void clear() {
353 if (empty())
354 return;
355
356 // Zap all values, resetting the keys back to non-present (not tombstone),
357 // which is safe because we're removing all elements.
358 for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
359 StringMapEntryBase *&Bucket = TheTable[I];
360 if (Bucket && Bucket != getTombstoneVal()) {
361 static_cast<MapEntryTy *>(Bucket)->Destroy(Allocator);
362 }
363 Bucket = nullptr;
364 }
365
366 NumItems = 0;
367 NumTombstones = 0;
368 }
369
370 /// remove - Remove the specified key/value pair from the map, but do not
371 /// erase it. This aborts if the key is not in the map.
372 void remove(MapEntryTy *KeyValue) { RemoveKey(KeyValue); }
373
374 void erase(iterator I) {
375 MapEntryTy &V = *I;
376 remove(&V);
377 V.Destroy(Allocator);
378 }
379
381 iterator I = find(Key);
382 if (I == end())
383 return false;
384 erase(I);
385 return true;
386 }
387};
388
389template <typename DerivedTy, typename ValueTy>
391 : public iterator_facade_base<DerivedTy, std::forward_iterator_tag,
392 ValueTy> {
393protected:
395
396public:
397 StringMapIterBase() = default;
398
400 bool NoAdvance = false)
401 : Ptr(Bucket) {
402 if (!NoAdvance)
403 AdvancePastEmptyBuckets();
404 }
405
406 DerivedTy &operator=(const DerivedTy &Other) {
407 Ptr = Other.Ptr;
408 return static_cast<DerivedTy &>(*this);
409 }
410
411 friend bool operator==(const DerivedTy &LHS, const DerivedTy &RHS) {
412 return LHS.Ptr == RHS.Ptr;
413 }
414
415 DerivedTy &operator++() { // Preincrement
416 ++Ptr;
417 AdvancePastEmptyBuckets();
418 return static_cast<DerivedTy &>(*this);
419 }
420
421 DerivedTy operator++(int) { // Post-increment
422 DerivedTy Tmp(Ptr);
423 ++*this;
424 return Tmp;
425 }
426
427 DerivedTy &operator--() { // Predecrement
428 --Ptr;
429 ReversePastEmptyBuckets();
430 return static_cast<DerivedTy &>(*this);
431 }
432
433 DerivedTy operator--(int) { // Post-decrement
434 DerivedTy Tmp(Ptr);
435 --*this;
436 return Tmp;
437 }
438
439private:
440 void AdvancePastEmptyBuckets() {
441 while (*Ptr == nullptr || *Ptr == StringMapImpl::getTombstoneVal())
442 ++Ptr;
443 }
444 void ReversePastEmptyBuckets() {
445 while (*Ptr == nullptr || *Ptr == StringMapImpl::getTombstoneVal())
446 --Ptr;
447 }
448};
449
450template <typename ValueTy>
452 : public StringMapIterBase<StringMapConstIterator<ValueTy>,
453 const StringMapEntry<ValueTy>> {
456
457public:
460 bool NoAdvance = false)
461 : base(Bucket, NoAdvance) {}
462
464 return *static_cast<const StringMapEntry<ValueTy> *>(*this->Ptr);
465 }
466};
467
468template <typename ValueTy>
469class StringMapIterator : public StringMapIterBase<StringMapIterator<ValueTy>,
470 StringMapEntry<ValueTy>> {
471 using base =
473
474public:
475 StringMapIterator() = default;
477 bool NoAdvance = false)
478 : base(Bucket, NoAdvance) {}
479
481 return *static_cast<StringMapEntry<ValueTy> *>(*this->Ptr);
482 }
483
485 return StringMapConstIterator<ValueTy>(this->Ptr, true);
486 }
487};
488
489template <typename ValueTy>
491 : public iterator_adaptor_base<StringMapKeyIterator<ValueTy>,
492 StringMapConstIterator<ValueTy>,
493 std::forward_iterator_tag, std::string_view> {
496 std::forward_iterator_tag, std::string_view>;
497
498public:
501 : base(std::move(Iter)) {}
502
503 std::string_view operator*() const { return this->wrapped()->getKey(); }
504};
505
506template <typename ValueTy>
508 // same instance?
509 if (&lhs == &rhs) return true;
510
511 // first check that sizes are identical
512 if (lhs.size() != rhs.size()) return false;
513
514 // copy into vectors and sort by key
516 lhs_items.reserve(lhs.size());
517 for (auto i = lhs.begin(), end = lhs.end(); i != end; ++i)
518 lhs_items.push_back(i);
519 std::sort(lhs_items.begin(), lhs_items.end(),
522 return a->getKey() < b->getKey();
523 });
524
526 rhs_items.reserve(rhs.size());
527 for (auto i = rhs.begin(), end = rhs.end(); i != end; ++i)
528 rhs_items.push_back(i);
529 std::sort(rhs_items.begin(), rhs_items.end(),
532 return a->getKey() < b->getKey();
533 });
534
535 // compare vector keys and values
536 for (auto a = lhs_items.begin(), b = rhs_items.begin(),
537 aend = lhs_items.end(), bend = rhs_items.end();
538 a != aend && b != bend; ++a, ++b) {
539 if ((*a)->first() != (*b)->first() || (*a)->second != (*b)->second)
540 return false;
541 }
542 return true;
543}
544
545template <typename ValueTy>
546inline bool operator!=(const StringMap<ValueTy>& lhs,
547 const StringMap<ValueTy>& rhs) {
548 return !(lhs == rhs);
549}
550
551template <typename ValueTy>
552bool operator<(const StringMap<ValueTy>& lhs, const StringMap<ValueTy>& rhs) {
553 // same instance?
554 if (&lhs == &rhs) return false;
555
556 // copy into vectors and sort by key
558 lhs_keys.reserve(lhs.size());
559 for (auto i = lhs.begin(), end = lhs.end(); i != end; ++i)
560 lhs_keys.push_back(i->getKey());
561 std::sort(lhs_keys.begin(), lhs_keys.end());
562
564 rhs_keys.reserve(rhs.size());
565 for (auto i = rhs.begin(), end = rhs.end(); i != end; ++i)
566 rhs_keys.push_back(i->getKey());
567 std::sort(rhs_keys.begin(), rhs_keys.end());
568
569 // use std::vector comparison
570 return lhs_keys < rhs_keys;
571}
572
573template <typename ValueTy>
574inline bool operator<=(const StringMap<ValueTy>& lhs,
575 const StringMap<ValueTy>& rhs) {
576 return !(rhs < lhs);
577}
578
579template <typename ValueTy>
580inline bool operator>(const StringMap<ValueTy>& lhs,
581 const StringMap<ValueTy>& rhs) {
582 return !(lhs <= rhs);
583}
584
585template <typename ValueTy>
586inline bool operator>=(const StringMap<ValueTy>& lhs,
587 const StringMap<ValueTy>& rhs) {
588 return !(lhs < rhs);
589}
590
591} // end namespace wpi
592
593#endif // WPIUTIL_WPI_STRINGMAP_H
This file defines MallocAllocator.
This file defines counterparts of C library allocation functions defined in the namespace 'std'.
This file defines the SmallVector class.
This file defines the StringMapEntry class - it is intended to be a low dependency implementation det...
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control and issue tracking systems that are managed or on behalf the Licensor for the purpose of discussing and improving the but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as Not a Contribution Contributor shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work Grant of Copyright License Subject to the terms and conditions of this each Contributor hereby grants to You a non no royalty free
Definition: ThirdPartyNotices.txt:151
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1186
void reserve(size_type N)
Definition: SmallVector.h:647
void push_back(const T &Elt)
Definition: SmallVector.h:403
iterator begin()
Definition: SmallVector.h:252
iterator end()
Definition: SmallVector.h:254
Definition: StringMap.h:453
StringMapConstIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
Definition: StringMap.h:459
const StringMapEntry< ValueTy > & operator*() const
Definition: StringMap.h:463
StringMapEntryBase - Shared base class of StringMapEntry instances.
Definition: StringMapEntry.h:29
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMapEntry.h:104
static StringMapEntry * Create(std::string_view key, AllocatorTy &allocator, InitTy &&... initVals)
Create a StringMapEntry for the specified key construct the value using InitiVals.
Definition: StringMapEntry.h:126
std::string_view getKey() const
Definition: StringMapEntry.h:108
void Destroy(AllocatorTy &allocator)
Destroy - Destroy this StringMapEntry, releasing memory back to the specified allocator.
Definition: StringMapEntry.h:142
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:114
StringMap & operator=(StringMap RHS)
Definition: StringMap.h:176
void insert(InputIt First, InputIt Last)
Inserts elements from range [first, last).
Definition: StringMap.h:307
const_iterator find(std::string_view Key) const
Definition: StringMap.h:229
const_iterator end() const
Definition: StringMap.h:213
std::pair< iterator, bool > insert(std::pair< std::string_view, ValueTy > KV)
insert - Inserts the specified key/value pair into the map if the key isn't already in the map.
Definition: StringMap.h:300
iterator find(std::string_view Key)
Definition: StringMap.h:222
AllocatorTy & getAllocator()
Definition: StringMap.h:197
void insert(std::initializer_list< std::pair< std::string_view, ValueTy > > List)
Inserts elements from initializer list ilist.
Definition: StringMap.h:315
size_t size_type
Definition: StringMap.h:203
~StringMap()
Definition: StringMap.h:182
const AllocatorTy & getAllocator() const
Definition: StringMap.h:198
StringMap(StringMap &&RHS)
Definition: StringMap.h:138
iterator begin()
Definition: StringMap.h:208
ValueTy & operator[](std::string_view Key)
Lookup the ValueTy for the Key, or create a default constructed value if the key is not in the map.
Definition: StringMap.h:247
StringMapConstIterator< ValueTy > const_iterator
Definition: StringMap.h:205
StringMap(AllocatorTy A)
Definition: StringMap.h:125
StringMap(unsigned InitialSize, AllocatorTy A)
Definition: StringMap.h:129
StringMap()
Definition: StringMap.h:120
StringMap(const StringMap &RHS)
Definition: StringMap.h:141
size_type count(std::string_view Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition: StringMap.h:250
const_iterator begin() const
Definition: StringMap.h:210
void erase(iterator I)
Definition: StringMap.h:374
void clear()
Definition: StringMap.h:352
StringMapIterator< ValueTy > iterator
Definition: StringMap.h:206
void remove(MapEntryTy *KeyValue)
remove - Remove the specified key/value pair from the map, but do not erase it.
Definition: StringMap.h:372
StringMap(std::initializer_list< std::pair< std::string_view, ValueTy > > List)
Definition: StringMap.h:133
std::pair< iterator, bool > insert_or_assign(std::string_view Key, V &&Val)
Inserts an element or assigns to the current element if the key already exists.
Definition: StringMap.h:322
std::pair< iterator, bool > try_emplace(std::string_view 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:334
const char * key_type
Definition: StringMap.h:200
ValueTy lookup(std::string_view Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: StringMap.h:238
iterator end()
Definition: StringMap.h:209
StringMap(unsigned InitialSize)
Definition: StringMap.h:122
iterator_range< StringMapKeyIterator< ValueTy > > keys() const
Definition: StringMap.h:217
bool operator==(const StringMap &RHS) const
equal - check whether both of the containers are equal.
Definition: StringMap.h:258
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:280
bool erase(std::string_view Key)
Definition: StringMap.h:380
size_type count(const StringMapEntry< InputTy > &MapEntry) const
Definition: StringMap.h:253
ValueTy mapped_type
Definition: StringMap.h:201
bool operator!=(const StringMap &RHS) const
Definition: StringMap.h:275
StringMapImpl - This is the base class of StringMap that is shared among all of its instantiations.
Definition: StringMap.h:36
StringMapImpl(unsigned InitSize, unsigned ItemSize)
unsigned getNumItems() const
Definition: StringMap.h:96
StringMapImpl(unsigned itemSize)
Definition: StringMap.h:48
StringMapEntryBase ** TheTable
Definition: StringMap.h:41
StringMapImpl(StringMapImpl &&RHS) noexcept
Definition: StringMap.h:49
unsigned NumBuckets
Definition: StringMap.h:42
unsigned NumTombstones
Definition: StringMap.h:44
int FindKey(std::string_view Key) const
FindKey - Look up the bucket that contains the specified key.
void init(unsigned Size)
Allocate the table with the specified number of buckets and otherwise setup the map as empty.
unsigned LookupBucketFor(std::string_view Key)
LookupBucketFor - Look up the bucket that the specified string should end up in.
unsigned RehashTable(unsigned BucketNo=0)
unsigned ItemSize
Definition: StringMap.h:45
unsigned NumItems
Definition: StringMap.h:43
bool empty() const
Definition: StringMap.h:98
void swap(StringMapImpl &Other)
Definition: StringMap.h:101
StringMapEntryBase * RemoveKey(std::string_view Key)
RemoveKey - Remove the StringMapEntry for the specified key from the table, returning it.
unsigned size() const
Definition: StringMap.h:99
static StringMapEntryBase * getTombstoneVal()
Definition: StringMap.h:91
void RemoveKey(StringMapEntryBase *V)
RemoveKey - Remove the specified StringMapEntry from the table, but do not delete it.
unsigned getNumBuckets() const
Definition: StringMap.h:95
static constexpr uintptr_t TombstoneIntVal
Definition: StringMap.h:87
Definition: StringMap.h:392
DerivedTy operator--(int)
Definition: StringMap.h:433
StringMapIterBase(StringMapEntryBase **Bucket, bool NoAdvance=false)
Definition: StringMap.h:399
DerivedTy & operator=(const DerivedTy &Other)
Definition: StringMap.h:406
DerivedTy operator++(int)
Definition: StringMap.h:421
DerivedTy & operator++()
Definition: StringMap.h:415
friend bool operator==(const DerivedTy &LHS, const DerivedTy &RHS)
Definition: StringMap.h:411
StringMapEntryBase ** Ptr
Definition: StringMap.h:394
DerivedTy & operator--()
Definition: StringMap.h:427
Definition: StringMap.h:470
StringMapIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
Definition: StringMap.h:476
StringMapEntry< ValueTy > & operator*() const
Definition: StringMap.h:480
Definition: StringMap.h:493
std::string_view operator*() const
Definition: StringMap.h:503
StringMapKeyIterator(StringMapConstIterator< ValueTy > Iter)
Definition: StringMap.h:500
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:237
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:80
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
basic_string_view< char > string_view
Definition: core.h:520
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
static EIGEN_DEPRECATED const end_t end
Definition: IndexedViewHelper.h:181
uint128_t uintptr_t
Definition: format.h:432
Definition: BFloat16.h:88
void swap(wpi::SmallPtrSet< T, N > &LHS, wpi::SmallPtrSet< T, N > &RHS)
Implement std::swap in terms of SmallPtrSet swap.
Definition: SmallPtrSet.h:512
b
Definition: data.h:44
Definition: AprilTagFieldLayout.h:18
bool operator>=(const StringMap< ValueTy > &lhs, const StringMap< ValueTy > &rhs)
Definition: StringMap.h:586
bool operator<(PointerUnion< PTs... > lhs, PointerUnion< PTs... > rhs)
Definition: PointerUnion.h:249
bool operator==(const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &LHS, const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &RHS)
Equality comparison for DenseMap.
Definition: DenseMap.h:686
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
bool operator!=(const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &LHS, const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &RHS)
Inequality comparison for DenseMap.
Definition: DenseMap.h:706
bool operator>(const StringMap< ValueTy > &lhs, const StringMap< ValueTy > &rhs)
Definition: StringMap.h:580
bool operator<=(const StringMap< ValueTy > &lhs, const StringMap< ValueTy > &rhs)
Definition: StringMap.h:574
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
Definition: PointerLikeTypeTraits.h:25