14#ifndef WPIUTIL_WPI_STRINGMAP_H
15#define WPIUTIL_WPI_STRINGMAP_H
25#include <initializer_list>
30template <
typename ValueTy>
class StringMapConstIterator;
31template <
typename ValueTy>
class StringMapIterator;
32template <
typename ValueTy>
class StringMapKeyIterator;
53 RHS.TheTable =
nullptr;
56 RHS.NumTombstones = 0;
113template <
typename ValueTy,
typename AllocatorTy = MallocAllocator>
115 AllocatorTy Allocator;
133 StringMap(std::initializer_list<std::pair<std::string_view, ValueTy>> List)
143 Allocator(RHS.Allocator) {
155 for (
unsigned I = 0, E =
NumBuckets; I != E; ++I) {
163 static_cast<MapEntryTy *
>(Bucket)->getKey(), Allocator,
164 static_cast<MapEntryTy *
>(Bucket)->getValue());
165 HashTable[I] = RHSHashTable[I];
187 for (
unsigned I = 0, E =
NumBuckets; I != E; ++I) {
190 static_cast<MapEntryTy *
>(Bucket)->Destroy(Allocator);
252 template <
typename InputTy>
262 for (
const auto &KeyValue : *
this) {
263 auto FindInRHS = RHS.
find(KeyValue.getKey());
265 if (FindInRHS == RHS.
end())
268 if (!(KeyValue.getValue() == FindInRHS->getValue()))
300 std::pair<iterator, bool>
insert(std::pair<std::string_view, ValueTy> KV) {
301 return try_emplace(KV.first, std::move(KV.second));
307 template <
typename InputIt>
void insert(InputIt First, InputIt Last) {
308 for (InputIt It = First; It != Last; ++It)
315 void insert(std::initializer_list<std::pair<std::string_view, ValueTy>> List) {
316 insert(List.begin(), List.end());
321 template <
typename V>
325 Ret.first->second = std::forward<V>(Val);
333 template <
typename... ArgsTy>
358 for (
unsigned I = 0, E =
NumBuckets; I != E; ++I) {
361 static_cast<MapEntryTy *
>(Bucket)->Destroy(Allocator);
389template <
typename DerivedTy,
typename ValueTy>
400 bool NoAdvance =
false)
403 AdvancePastEmptyBuckets();
408 return static_cast<DerivedTy &
>(*this);
411 friend bool operator==(
const DerivedTy &LHS,
const DerivedTy &RHS) {
412 return LHS.Ptr == RHS.Ptr;
417 AdvancePastEmptyBuckets();
418 return static_cast<DerivedTy &
>(*this);
429 ReversePastEmptyBuckets();
430 return static_cast<DerivedTy &
>(*this);
440 void AdvancePastEmptyBuckets() {
444 void ReversePastEmptyBuckets() {
450template <
typename ValueTy>
453 const StringMapEntry<ValueTy>> {
460 bool NoAdvance =
false)
461 :
base(Bucket, NoAdvance) {}
468template <
typename ValueTy>
470 StringMapEntry<ValueTy>> {
477 bool NoAdvance =
false)
478 :
base(Bucket, NoAdvance) {}
489template <
typename ValueTy>
492 StringMapConstIterator<ValueTy>,
493 std::forward_iterator_tag, std::string_view> {
506template <
typename ValueTy>
509 if (&lhs == &rhs)
return true;
512 if (lhs.
size() != rhs.
size())
return false;
519 std::sort(lhs_items.
begin(), lhs_items.
end(),
522 return a->getKey() < b->getKey();
529 std::sort(rhs_items.
begin(), rhs_items.
end(),
532 return a->getKey() < b->getKey();
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)
545template <
typename ValueTy>
548 return !(lhs == rhs);
551template <
typename ValueTy>
554 if (&lhs == &rhs)
return false;
561 std::sort(lhs_keys.
begin(), lhs_keys.
end());
567 std::sort(rhs_keys.
begin(), rhs_keys.
end());
570 return lhs_keys < rhs_keys;
573template <
typename ValueTy>
579template <
typename ValueTy>
582 return !(lhs <= rhs);
585template <
typename ValueTy>
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()=default
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
StringMapIterBase()=default
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
StringMapIterator()=default
StringMapEntry< ValueTy > & operator*() const
Definition: StringMap.h:480
Definition: StringMap.h:493
std::string_view operator*() const
Definition: StringMap.h:503
StringMapKeyIterator()=default
StringMapKeyIterator(StringMapConstIterator< ValueTy > Iter)
Definition: StringMap.h:500
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:237
const StringMapConstIterator< ValueTy > & wrapped() const
Definition: iterator.h:250
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
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