WPILibC++ 2024.3.2
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>
115 : public StringMapImpl,
116 private detail::AllocatorHolder<AllocatorTy> {
118
119public:
121
122 StringMap() : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {}
123
124 explicit StringMap(unsigned InitialSize)
125 : StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))) {}
126
127 explicit StringMap(AllocatorTy A)
128 : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))), AllocTy(A) {}
129
130 StringMap(unsigned InitialSize, AllocatorTy A)
131 : StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))),
132 AllocTy(A) {}
133
134 StringMap(std::initializer_list<std::pair<std::string_view, ValueTy>> List)
135 : StringMapImpl(List.size(), static_cast<unsigned>(sizeof(MapEntryTy))) {
136 insert(List);
137 }
138
140 : StringMapImpl(std::move(RHS)), AllocTy(std::move(RHS.getAllocator())) {}
141
143 : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))),
144 AllocTy(RHS.getAllocator()) {
145 if (RHS.empty())
146 return;
147
148 // Allocate TheTable of the same size as RHS's TheTable, and set the
149 // sentinel appropriately (and NumBuckets).
150 init(RHS.NumBuckets);
151 unsigned *HashTable = (unsigned *)(TheTable + NumBuckets + 1),
152 *RHSHashTable = (unsigned *)(RHS.TheTable + NumBuckets + 1);
153
154 NumItems = RHS.NumItems;
155 NumTombstones = RHS.NumTombstones;
156 for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
157 StringMapEntryBase *Bucket = RHS.TheTable[I];
158 if (!Bucket || Bucket == getTombstoneVal()) {
159 TheTable[I] = Bucket;
160 continue;
161 }
162
163 TheTable[I] = MapEntryTy::create(
164 static_cast<MapEntryTy *>(Bucket)->getKey(), getAllocator(),
165 static_cast<MapEntryTy *>(Bucket)->getValue());
166 HashTable[I] = RHSHashTable[I];
167 }
168
169 // Note that here we've copied everything from the RHS into this object,
170 // tombstones included. We could, instead, have re-probed for each key to
171 // instantiate this new object without any tombstone buckets. The
172 // assumption here is that items are rarely deleted from most StringMaps,
173 // and so tombstones are rare, so the cost of re-probing for all inputs is
174 // not worthwhile.
175 }
176
179 std::swap(getAllocator(), RHS.getAllocator());
180 return *this;
181 }
182
184 // Delete all the elements in the map, but don't reset the elements
185 // to default values. This is a copy of clear(), but avoids unnecessary
186 // work not required in the destructor.
187 if (!empty()) {
188 for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
189 StringMapEntryBase *Bucket = TheTable[I];
190 if (Bucket && Bucket != getTombstoneVal()) {
191 static_cast<MapEntryTy *>(Bucket)->Destroy(getAllocator());
192 }
193 }
194 }
195 free(TheTable);
196 }
197
198 using AllocTy::getAllocator;
199
200 using key_type = const char *;
201 using mapped_type = ValueTy;
203 using size_type = size_t;
204
207
208 iterator begin() { return iterator(TheTable, NumBuckets == 0); }
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 Iter = find(Key);
240 if (Iter != end())
241 return Iter->second;
242 return ValueTy();
243 }
244
245 /// at - Return the entry for the specified key, or abort if no such
246 /// entry exists.
247 const ValueTy &at(std::string_view Val) const {
248 auto Iter = this->find(std::move(Val));
249 assert(Iter != this->end() && "StringMap::at failed due to a missing key");
250 return Iter->second;
251 }
252
253 /// Lookup the ValueTy for the \p Key, or create a default constructed value
254 /// if the key is not in the map.
255 ValueTy &operator[](std::string_view Key) { return try_emplace(Key).first->second; }
256
257 /// contains - Return true if the element is in the map, false otherwise.
258 bool contains(std::string_view Key) const { return find(Key) != end(); }
259
260 /// count - Return 1 if the element is in the map, 0 otherwise.
261 size_type count(std::string_view Key) const { return contains(Key) ? 1 : 0; }
262
263 template <typename InputTy>
264 size_type count(const StringMapEntry<InputTy> &MapEntry) const {
265 return count(MapEntry.getKey());
266 }
267
268 /// equal - check whether both of the containers are equal.
269 bool operator==(const StringMap &RHS) const {
270 if (size() != RHS.size())
271 return false;
272
273 for (const auto &KeyValue : *this) {
274 auto FindInRHS = RHS.find(KeyValue.getKey());
275
276 if (FindInRHS == RHS.end())
277 return false;
278
279 if (!(KeyValue.getValue() == FindInRHS->getValue()))
280 return false;
281 }
282
283 return true;
284 }
285
286 bool operator!=(const StringMap &RHS) const { return !(*this == RHS); }
287
288 /// insert - Insert the specified key/value pair into the map. If the key
289 /// already exists in the map, return false and ignore the request, otherwise
290 /// insert it and return true.
291 bool insert(MapEntryTy *KeyValue) {
292 unsigned BucketNo = LookupBucketFor(KeyValue->getKey());
293 StringMapEntryBase *&Bucket = TheTable[BucketNo];
294 if (Bucket && Bucket != getTombstoneVal())
295 return false; // Already exists in map.
296
297 if (Bucket == getTombstoneVal())
298 --NumTombstones;
299 Bucket = KeyValue;
300 ++NumItems;
301 assert(NumItems + NumTombstones <= NumBuckets);
302
303 RehashTable();
304 return true;
305 }
306
307 /// insert - Inserts the specified key/value pair into the map if the key
308 /// isn't already in the map. The bool component of the returned pair is true
309 /// if and only if the insertion takes place, and the iterator component of
310 /// the pair points to the element with key equivalent to the key of the pair.
311 std::pair<iterator, bool> insert(std::pair<std::string_view, ValueTy> KV) {
312 return try_emplace(KV.first, std::move(KV.second));
313 }
314
315 /// Inserts elements from range [first, last). If multiple elements in the
316 /// range have keys that compare equivalent, it is unspecified which element
317 /// is inserted .
318 template <typename InputIt> void insert(InputIt First, InputIt Last) {
319 for (InputIt It = First; It != Last; ++It)
320 insert(*It);
321 }
322
323 /// Inserts elements from initializer list ilist. If multiple elements in
324 /// the range have keys that compare equivalent, it is unspecified which
325 /// element is inserted
326 void insert(std::initializer_list<std::pair<std::string_view, ValueTy>> List) {
327 insert(List.begin(), List.end());
328 }
329
330 /// Inserts an element or assigns to the current element if the key already
331 /// exists. The return type is the same as try_emplace.
332 template <typename V>
333 std::pair<iterator, bool> insert_or_assign(std::string_view Key, V &&Val) {
334 auto Ret = try_emplace(Key, std::forward<V>(Val));
335 if (!Ret.second)
336 Ret.first->second = std::forward<V>(Val);
337 return Ret;
338 }
339
340 /// Emplace a new element for the specified key into the map if the key isn't
341 /// already in the map. The bool component of the returned pair is true
342 /// if and only if the insertion takes place, and the iterator component of
343 /// the pair points to the element with key equivalent to the key of the pair.
344 template <typename... ArgsTy>
345 std::pair<iterator, bool> try_emplace(std::string_view Key, ArgsTy &&...Args) {
346 unsigned BucketNo = LookupBucketFor(Key);
347 StringMapEntryBase *&Bucket = TheTable[BucketNo];
348 if (Bucket && Bucket != getTombstoneVal())
349 return std::make_pair(iterator(TheTable + BucketNo, false),
350 false); // Already exists in map.
351
352 if (Bucket == getTombstoneVal())
353 --NumTombstones;
354 Bucket =
355 MapEntryTy::create(Key, getAllocator(), std::forward<ArgsTy>(Args)...);
356 ++NumItems;
357 assert(NumItems + NumTombstones <= NumBuckets);
358
359 BucketNo = RehashTable(BucketNo);
360 return std::make_pair(iterator(TheTable + BucketNo, false), true);
361 }
362
363 // clear - Empties out the StringMap
364 void clear() {
365 if (empty())
366 return;
367
368 // Zap all values, resetting the keys back to non-present (not tombstone),
369 // which is safe because we're removing all elements.
370 for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
371 StringMapEntryBase *&Bucket = TheTable[I];
372 if (Bucket && Bucket != getTombstoneVal()) {
373 static_cast<MapEntryTy *>(Bucket)->Destroy(getAllocator());
374 }
375 Bucket = nullptr;
376 }
377
378 NumItems = 0;
379 NumTombstones = 0;
380 }
381
382 /// remove - Remove the specified key/value pair from the map, but do not
383 /// erase it. This aborts if the key is not in the map.
384 void remove(MapEntryTy *KeyValue) { RemoveKey(KeyValue); }
385
386 void erase(iterator I) {
387 MapEntryTy &V = *I;
388 remove(&V);
389 V.Destroy(getAllocator());
390 }
391
393 iterator I = find(Key);
394 if (I == end())
395 return false;
396 erase(I);
397 return true;
398 }
399};
400
401template <typename DerivedTy, typename ValueTy>
403 : public iterator_facade_base<DerivedTy, std::forward_iterator_tag,
404 ValueTy> {
405protected:
407
408public:
409 StringMapIterBase() = default;
410
412 bool NoAdvance = false)
413 : Ptr(Bucket) {
414 if (!NoAdvance)
415 AdvancePastEmptyBuckets();
416 }
417
418 DerivedTy &operator=(const DerivedTy &Other) {
419 Ptr = Other.Ptr;
420 return static_cast<DerivedTy &>(*this);
421 }
422
423 friend bool operator==(const DerivedTy &LHS, const DerivedTy &RHS) {
424 return LHS.Ptr == RHS.Ptr;
425 }
426
427 DerivedTy &operator++() { // Preincrement
428 ++Ptr;
429 AdvancePastEmptyBuckets();
430 return static_cast<DerivedTy &>(*this);
431 }
432
433 DerivedTy operator++(int) { // Post-increment
434 DerivedTy Tmp(Ptr);
435 ++*this;
436 return Tmp;
437 }
438
439 DerivedTy &operator--() { // Predecrement
440 --Ptr;
441 ReversePastEmptyBuckets();
442 return static_cast<DerivedTy &>(*this);
443 }
444
445 DerivedTy operator--(int) { // Post-decrement
446 DerivedTy Tmp(Ptr);
447 --*this;
448 return Tmp;
449 }
450
451private:
452 void AdvancePastEmptyBuckets() {
453 while (*Ptr == nullptr || *Ptr == StringMapImpl::getTombstoneVal())
454 ++Ptr;
455 }
456 void ReversePastEmptyBuckets() {
457 while (*Ptr == nullptr || *Ptr == StringMapImpl::getTombstoneVal())
458 --Ptr;
459 }
460};
461
462template <typename ValueTy>
464 : public StringMapIterBase<StringMapConstIterator<ValueTy>,
465 const StringMapEntry<ValueTy>> {
468
469public:
472 bool NoAdvance = false)
473 : base(Bucket, NoAdvance) {}
474
476 return *static_cast<const StringMapEntry<ValueTy> *>(*this->Ptr);
477 }
478};
479
480template <typename ValueTy>
481class StringMapIterator : public StringMapIterBase<StringMapIterator<ValueTy>,
482 StringMapEntry<ValueTy>> {
483 using base =
485
486public:
487 StringMapIterator() = default;
489 bool NoAdvance = false)
490 : base(Bucket, NoAdvance) {}
491
493 return *static_cast<StringMapEntry<ValueTy> *>(*this->Ptr);
494 }
495
497 return StringMapConstIterator<ValueTy>(this->Ptr, true);
498 }
499};
500
501template <typename ValueTy>
503 : public iterator_adaptor_base<StringMapKeyIterator<ValueTy>,
504 StringMapConstIterator<ValueTy>,
505 std::forward_iterator_tag, std::string_view> {
508 std::forward_iterator_tag, std::string_view>;
509
510public:
513 : base(std::move(Iter)) {}
514
515 std::string_view operator*() const { return this->wrapped()->getKey(); }
516};
517
518template <typename ValueTy>
520 // same instance?
521 if (&lhs == &rhs) return true;
522
523 // first check that sizes are identical
524 if (lhs.size() != rhs.size()) return false;
525
526 // copy into vectors and sort by key
528 lhs_items.reserve(lhs.size());
529 for (auto i = lhs.begin(), end = lhs.end(); i != end; ++i)
530 lhs_items.push_back(i);
531 std::sort(lhs_items.begin(), lhs_items.end(),
534 return a->getKey() < b->getKey();
535 });
536
538 rhs_items.reserve(rhs.size());
539 for (auto i = rhs.begin(), end = rhs.end(); i != end; ++i)
540 rhs_items.push_back(i);
541 std::sort(rhs_items.begin(), rhs_items.end(),
544 return a->getKey() < b->getKey();
545 });
546
547 // compare vector keys and values
548 for (auto a = lhs_items.begin(), b = rhs_items.begin(),
549 aend = lhs_items.end(), bend = rhs_items.end();
550 a != aend && b != bend; ++a, ++b) {
551 if ((*a)->first() != (*b)->first() || (*a)->second != (*b)->second)
552 return false;
553 }
554 return true;
555}
556
557template <typename ValueTy>
558inline bool operator!=(const StringMap<ValueTy>& lhs,
559 const StringMap<ValueTy>& rhs) {
560 return !(lhs == rhs);
561}
562
563template <typename ValueTy>
564bool operator<(const StringMap<ValueTy>& lhs, const StringMap<ValueTy>& rhs) {
565 // same instance?
566 if (&lhs == &rhs) return false;
567
568 // copy into vectors and sort by key
570 lhs_keys.reserve(lhs.size());
571 for (auto i = lhs.begin(), end = lhs.end(); i != end; ++i)
572 lhs_keys.push_back(i->getKey());
573 std::sort(lhs_keys.begin(), lhs_keys.end());
574
576 rhs_keys.reserve(rhs.size());
577 for (auto i = rhs.begin(), end = rhs.end(); i != end; ++i)
578 rhs_keys.push_back(i->getKey());
579 std::sort(rhs_keys.begin(), rhs_keys.end());
580
581 // use std::vector comparison
582 return lhs_keys < rhs_keys;
583}
584
585template <typename ValueTy>
586inline bool operator<=(const StringMap<ValueTy>& lhs,
587 const StringMap<ValueTy>& rhs) {
588 return !(rhs < lhs);
589}
590
591template <typename ValueTy>
592inline bool operator>(const StringMap<ValueTy>& lhs,
593 const StringMap<ValueTy>& rhs) {
594 return !(lhs <= rhs);
595}
596
597template <typename ValueTy>
598inline bool operator>=(const StringMap<ValueTy>& lhs,
599 const StringMap<ValueTy>& rhs) {
600 return !(lhs < rhs);
601}
602
603} // end namespace wpi
604
605#endif // WPIUTIL_WPI_STRINGMAP_H
This file defines MallocAllocator.
#define LLVM_ALLOCATORHOLDER_EMPTYBASE
Definition: AllocatorBase.h:25
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:1202
void reserve(size_type N)
Definition: SmallVector.h:669
void push_back(const T &Elt)
Definition: SmallVector.h:418
iterator begin()
Definition: SmallVector.h:272
iterator end()
Definition: SmallVector.h:274
Definition: StringMap.h:465
StringMapConstIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
Definition: StringMap.h:471
const StringMapEntry< ValueTy > & operator*() const
Definition: StringMap.h:475
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:106
std::string_view getKey() const
Definition: StringMapEntry.h:112
void Destroy(AllocatorTy &allocator)
Destroy - Destroy this StringMapEntry, releasing memory back to the specified allocator.
Definition: StringMapEntry.h:146
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:116
StringMap & operator=(StringMap RHS)
Definition: StringMap.h:177
void insert(InputIt First, InputIt Last)
Inserts elements from range [first, last).
Definition: StringMap.h:318
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:311
iterator find(std::string_view Key)
Definition: StringMap.h:222
void insert(std::initializer_list< std::pair< std::string_view, ValueTy > > List)
Inserts elements from initializer list ilist.
Definition: StringMap.h:326
size_t size_type
Definition: StringMap.h:203
~StringMap()
Definition: StringMap.h:183
StringMap(StringMap &&RHS)
Definition: StringMap.h:139
iterator begin()
Definition: StringMap.h:208
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:345
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:255
StringMap(AllocatorTy A)
Definition: StringMap.h:127
StringMap(unsigned InitialSize, AllocatorTy A)
Definition: StringMap.h:130
StringMap()
Definition: StringMap.h:122
StringMap(const StringMap &RHS)
Definition: StringMap.h:142
size_type count(std::string_view Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition: StringMap.h:261
const_iterator begin() const
Definition: StringMap.h:210
void erase(iterator I)
Definition: StringMap.h:386
void clear()
Definition: StringMap.h:364
void remove(MapEntryTy *KeyValue)
remove - Remove the specified key/value pair from the map, but do not erase it.
Definition: StringMap.h:384
StringMap(std::initializer_list< std::pair< std::string_view, ValueTy > > List)
Definition: StringMap.h:134
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:333
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:124
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:269
bool contains(std::string_view Key) const
contains - Return true if the element is in the map, false otherwise.
Definition: StringMap.h:258
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:291
bool erase(std::string_view Key)
Definition: StringMap.h:392
size_type count(const StringMapEntry< InputTy > &MapEntry) const
Definition: StringMap.h:264
ValueTy mapped_type
Definition: StringMap.h:201
Alloc & getAllocator()
Definition: AllocatorBase.h:115
bool operator!=(const StringMap &RHS) const
Definition: StringMap.h:286
const ValueTy & at(std::string_view Val) const
at - Return the entry for the specified key, or abort if no such entry exists.
Definition: StringMap.h:247
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:404
DerivedTy operator--(int)
Definition: StringMap.h:445
StringMapIterBase(StringMapEntryBase **Bucket, bool NoAdvance=false)
Definition: StringMap.h:411
DerivedTy & operator=(const DerivedTy &Other)
Definition: StringMap.h:418
DerivedTy operator++(int)
Definition: StringMap.h:433
DerivedTy & operator++()
Definition: StringMap.h:427
friend bool operator==(const DerivedTy &LHS, const DerivedTy &RHS)
Definition: StringMap.h:423
StringMapEntryBase ** Ptr
Definition: StringMap.h:406
DerivedTy & operator--()
Definition: StringMap.h:439
Definition: StringMap.h:482
StringMapIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
Definition: StringMap.h:488
StringMapEntry< ValueTy > & operator*() const
Definition: StringMap.h:492
Definition: StringMap.h:505
std::string_view operator*() const
Definition: StringMap.h:515
StringMapKeyIterator(StringMapConstIterator< ValueTy > Iter)
Definition: StringMap.h:512
Definition: AllocatorBase.h:110
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:42
basic_string_view< char > string_view
Definition: core.h:501
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition: core.h:2120
constexpr auto count() -> size_t
Definition: core.h:1203
uint128_t uintptr_t
Definition: format.h:484
Definition: array.h:89
WPI_BASIC_JSON_TPL_DECLARATION void swap(wpi::WPI_BASIC_JSON_TPL &j1, wpi::WPI_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< wpi::WPI_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< wpi::WPI_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.h:5219
b
Definition: data.h:44
Definition: ntcore_cpp.h:26
constexpr bool operator>(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition: expected:192
constexpr bool contains(std::string_view str, std::string_view other) noexcept
Checks if str contains the substring other.
Definition: StringExtras.h:320
constexpr bool operator<(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition: expected:184
constexpr bool operator<=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition: expected:188
constexpr bool operator>=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition: expected:196
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:75
constexpr bool operator==(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition: expected:176
constexpr bool operator!=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition: expected:180
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
Definition: PointerLikeTypeTraits.h:25