15#ifndef WPIUTIL_WPI_SMALLPTRSET_H
16#define WPIUTIL_WPI_SMALLPTRSET_H
26#include <initializer_list>
79 assert(SmallSize && (SmallSize & (SmallSize-1)) == 0 &&
80 "Initial size must be a power of two!");
93 [[nodiscard]]
bool empty()
const {
return size() == 0; }
102 return shrink_and_clear();
117 return reinterpret_cast<void*
>(-1);
127 std::pair<const void *const *, bool>
insert_imp(
const void *Ptr) {
132 const void *Value = *APtr;
134 return std::make_pair(APtr,
false);
145 return insert_imp_big(Ptr);
165 auto *Bucket = FindBucketFor(Ptr);
180 const void *
const *
find_imp(
const void * Ptr)
const {
191 auto *Bucket = FindBucketFor(Ptr);
200 std::pair<const void *const *, bool> insert_imp_big(
const void *Ptr);
202 const void *
const *FindBucketFor(
const void *Ptr)
const;
203 void shrink_and_clear();
206 void Grow(
unsigned NewSize);
269template <
typename PtrTy>
289 assert(isHandleInSync() &&
"invalid iterator access!");
291 assert(Bucket > End);
292 return PtrTraits::getFromVoidPointer(
const_cast<void *
>(Bucket[-1]));
294 assert(Bucket < End);
295 return PtrTraits::getFromVoidPointer(
const_cast<void*
>(*Bucket));
299 assert(isHandleInSync() &&
"invalid iterator access!");
322template <
typename PtrType>
344 std::pair<iterator, bool>
insert(PtrType Ptr) {
345 auto p =
insert_imp(PtrTraits::getAsVoidPointer(Ptr));
346 return std::make_pair(makeIterator(p.first), p.second);
362 return erase_imp(PtrTraits::getAsVoidPointer(Ptr));
377 template <
typename UnaryPredicate>
379 bool Removed =
false;
383 PtrType Ptr = PtrTraits::getFromVoidPointer(
const_cast<void *
>(*APtr));
397 const void *Value = *APtr;
400 PtrType Ptr = PtrTraits::getFromVoidPointer(
const_cast<void *
>(Value));
416 return makeIterator(
find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)));
422 template <
typename IterT>
428 void insert(std::initializer_list<PtrType> IL) {
429 insert(IL.begin(), IL.end());
441 iterator makeIterator(
const void *
const *P)
const {
452template <
typename PtrType>
458 for (
const auto *KV : LHS)
468template <
typename PtrType>
471 return !(LHS == RHS);
478template<
class PtrType,
unsigned SmallSize>
483 static_assert(SmallSize <= 32,
"SmallSize should be small");
489 static constexpr size_t RoundUpToPowerOfTwo(
size_t X) {
491 size_t CMax = C << (std::numeric_limits<size_t>::digits - 1);
492 while (C < X && C < CMax)
498 static constexpr size_t SmallSizePowTwo = RoundUpToPowerOfTwo(SmallSize);
500 const void *SmallStorage[SmallSizePowTwo];
506 :
BaseT(SmallStorage, SmallSizePowTwo,
std::move(that)) {}
508 template<
typename It>
514 :
BaseT(SmallStorage, SmallSizePowTwo) {
515 this->
insert(IL.begin(), IL.end());
528 this->
MoveFrom(SmallSizePowTwo, std::move(RHS));
535 this->
insert(IL.begin(), IL.end());
550 template<
class T,
unsigned N>
This file defines the DebugEpochBase and DebugEpochBase::HandleBase classes.
#define LLVM_DEBUGEPOCHBASE_HANDLEBASE_EMPTYBASE
Definition EpochTracker.h:25
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 and nanopb were all modified for use in 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:164
A base class for iterator classes ("handles") that wish to poll for iterator invalidating modificatio...
Definition EpochTracker.h:58
A base class for data structure classes wishing to make iterators ("handles") pointing into themselve...
Definition EpochTracker.h:36
void incrementEpoch()
Calling incrementEpoch invalidates all handles pointing into the calling instance.
Definition EpochTracker.h:44
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition SmallPtrSet.h:479
SmallPtrSet< PtrType, SmallSize > & operator=(SmallPtrSet< PtrType, SmallSize > &&RHS)
Definition SmallPtrSet.h:526
SmallPtrSet(SmallPtrSet &&that)
Definition SmallPtrSet.h:505
SmallPtrSet(std::initializer_list< PtrType > IL)
Definition SmallPtrSet.h:513
SmallPtrSet(It I, It E)
Definition SmallPtrSet.h:509
SmallPtrSet< PtrType, SmallSize > & operator=(const SmallPtrSet< PtrType, SmallSize > &RHS)
Definition SmallPtrSet.h:519
SmallPtrSet< PtrType, SmallSize > & operator=(std::initializer_list< PtrType > IL)
Definition SmallPtrSet.h:533
void swap(SmallPtrSet< PtrType, SmallSize > &RHS)
swap - Swaps the elements of two sets.
Definition SmallPtrSet.h:540
SmallPtrSet(const SmallPtrSet &that)
Definition SmallPtrSet.h:504
SmallPtrSet()
Definition SmallPtrSet.h:503
SmallPtrSetImplBase - This is the common code shared among all the SmallPtrSet<>'s,...
Definition SmallPtrSet.h:51
std::pair< const void *const *, bool > insert_imp(const void *Ptr)
insert_imp - This returns true if the pointer was new to the set, false if it was already in the set.
Definition SmallPtrSet.h:127
unsigned NumNonEmpty
Number of elements in CurArray that contain a value or are a tombstone.
Definition SmallPtrSet.h:66
const void ** SmallArray
SmallArray - Points to a fixed size set of buckets, used in 'small mode'.
Definition SmallPtrSet.h:56
unsigned size_type
Definition SmallPtrSet.h:89
SmallPtrSetImplBase & operator=(const SmallPtrSetImplBase &)=delete
~SmallPtrSetImplBase()
Definition SmallPtrSet.h:83
SmallPtrSetImplBase(const void **SmallStorage, const SmallPtrSetImplBase &that)
bool isSmall() const
Definition SmallPtrSet.h:197
unsigned CurArraySize
CurArraySize - The allocated size of CurArray, always a power of two.
Definition SmallPtrSet.h:61
static void * getTombstoneMarker()
Definition SmallPtrSet.h:112
static void * getEmptyMarker()
Definition SmallPtrSet.h:114
const void *const * find_imp(const void *Ptr) const
Returns the raw pointer needed to construct an iterator.
Definition SmallPtrSet.h:180
void swap(SmallPtrSetImplBase &RHS)
swap - Swaps the elements of two sets.
SmallPtrSetImplBase(const void **SmallStorage, unsigned SmallSize)
Definition SmallPtrSet.h:76
unsigned NumTombstones
Number of tombstones in CurArray.
Definition SmallPtrSet.h:68
void clear()
Definition SmallPtrSet.h:96
size_type size() const
Definition SmallPtrSet.h:94
bool erase_imp(const void *Ptr)
erase_imp - If the set contains the specified pointer, remove it and return true, otherwise return fa...
Definition SmallPtrSet.h:152
void MoveFrom(unsigned SmallSize, SmallPtrSetImplBase &&RHS)
SmallPtrSetImplBase(const void **SmallStorage, unsigned SmallSize, SmallPtrSetImplBase &&that)
const void ** EndPointer() const
Definition SmallPtrSet.h:120
void CopyFrom(const SmallPtrSetImplBase &RHS)
bool empty() const
Definition SmallPtrSet.h:93
const void ** CurArray
CurArray - This is the current set of buckets.
Definition SmallPtrSet.h:59
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition SmallPtrSet.h:323
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition SmallPtrSet.h:344
bool remove_if(UnaryPredicate P)
Remove elements that match the given predicate.
Definition SmallPtrSet.h:378
SmallPtrSetIterator< PtrType > iterator
Definition SmallPtrSet.h:333
bool erase(PtrType Ptr)
Remove pointer from the set.
Definition SmallPtrSet.h:361
iterator find(ConstPtrType Ptr) const
Definition SmallPtrSet.h:415
void insert(std::initializer_list< PtrType > IL)
Definition SmallPtrSet.h:428
iterator end() const
Definition SmallPtrSet.h:437
ConstPtrType key_type
Definition SmallPtrSet.h:335
bool contains(ConstPtrType Ptr) const
Definition SmallPtrSet.h:418
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition SmallPtrSet.h:412
iterator begin() const
Definition SmallPtrSet.h:432
iterator insert(iterator, PtrType Ptr)
Insert the given pointer with an iterator hint that is ignored.
Definition SmallPtrSet.h:352
PtrType value_type
Definition SmallPtrSet.h:336
void insert(IterT I, IterT E)
Definition SmallPtrSet.h:423
SmallPtrSetImpl(const SmallPtrSetImpl &)=delete
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
Definition SmallPtrSet.h:272
PtrTy value_type
Definition SmallPtrSet.h:276
std::ptrdiff_t difference_type
Definition SmallPtrSet.h:279
SmallPtrSetIterator(const void *const *BP, const void *const *E, const DebugEpochBase &Epoch)
Definition SmallPtrSet.h:282
PtrTy pointer
Definition SmallPtrSet.h:278
std::forward_iterator_tag iterator_category
Definition SmallPtrSet.h:280
PtrTy reference
Definition SmallPtrSet.h:277
SmallPtrSetIterator & operator++()
Definition SmallPtrSet.h:298
const PtrTy operator*() const
Definition SmallPtrSet.h:288
SmallPtrSetIterator operator++(int)
Definition SmallPtrSet.h:310
SmallPtrSetIteratorImpl - This is the common base class shared between all instances of SmallPtrSetIt...
Definition SmallPtrSet.h:225
bool operator!=(const SmallPtrSetIteratorImpl &RHS) const
Definition SmallPtrSet.h:243
void AdvanceIfNotValid()
AdvanceIfNotValid - If the current bucket isn't valid, advance to a bucket that is.
Definition SmallPtrSet.h:251
const void *const * Bucket
Definition SmallPtrSet.h:227
const void *const * End
Definition SmallPtrSet.h:228
bool operator==(const SmallPtrSetIteratorImpl &RHS) const
Definition SmallPtrSet.h:240
SmallPtrSetIteratorImpl(const void *const *BP, const void *const *E)
Definition SmallPtrSet.h:231
void RetreatIfNotValid()
Definition SmallPtrSet.h:258
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
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, cert-dcl58-cpp) is_nothrow_move_constructible< wpi::WPI_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< wpi::WPI_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.h:5258
Foonathan namespace.
Definition ntcore_cpp.h:26
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:729
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:749
bool shouldReverseIterate()
Definition ReverseIteration.h:9
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
Definition PointerLikeTypeTraits.h:25
const T type
Definition type_traits.h:55