summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-02-03 11:24:21 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-02-03 11:24:21 +0000
commit17fec838c461638fefb4c33ee242adb776b1b3d5 (patch)
tree2080881ebee9ad5bec8215c347aa3b55d3f9a80d /include
parente3f87943291d589059a9f2838e5dbb05bc91d7dd (diff)
downloadllvm-17fec838c461638fefb4c33ee242adb776b1b3d5.tar.gz
llvm-17fec838c461638fefb4c33ee242adb776b1b3d5.tar.bz2
llvm-17fec838c461638fefb4c33ee242adb776b1b3d5.tar.xz
Introduce SmallPtrSetImpl<T *> which allows insert, erase, count, and
iteration. This alows the majority of operations to be performed without encoding a specific small size. It follows the model of SmallVectorImpl<T>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200688 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/SmallPtrSet.h67
1 files changed, 45 insertions, 22 deletions
diff --git a/include/llvm/ADT/SmallPtrSet.h b/include/llvm/ADT/SmallPtrSet.h
index b073005321..03d8990cb4 100644
--- a/include/llvm/ADT/SmallPtrSet.h
+++ b/include/llvm/ADT/SmallPtrSet.h
@@ -235,30 +235,27 @@ struct RoundUpToPowerOfTwo {
};
-/// SmallPtrSet - This class implements a set which is optimized for holding
-/// SmallSize or less elements. This internally rounds up SmallSize to the next
-/// power of two if it is not already a power of two. See the comments above
-/// SmallPtrSetImplBase for details of the algorithm.
-template<class PtrType, unsigned SmallSize>
-class SmallPtrSet : public SmallPtrSetImplBase {
- // Make sure that SmallSize is a power of two, round up if not.
- enum { SmallSizePowTwo = RoundUpToPowerOfTwo<SmallSize>::Val };
- /// SmallStorage - Fixed size storage used in 'small mode'.
- const void *SmallStorage[SmallSizePowTwo];
+/// \brief A templated base class for \c SmallPtrSet which provides the
+/// typesafe interface that is common across all small sizes.
+///
+/// This is particularly useful for passing around between interface boundaries
+/// to avoid encoding a particular small size in the interface boundary.
+template <typename PtrType>
+class SmallPtrSetImpl : public SmallPtrSetImplBase {
typedef PointerLikeTypeTraits<PtrType> PtrTraits;
-public:
- SmallPtrSet() : SmallPtrSetImplBase(SmallStorage, SmallSizePowTwo) {}
- SmallPtrSet(const SmallPtrSet &that) : SmallPtrSetImplBase(SmallStorage, that) {}
+protected:
+ // Constructors that forward to the base.
+ SmallPtrSetImpl(const void **SmallStorage, const SmallPtrSetImpl &that)
+ : SmallPtrSetImplBase(SmallStorage, that) {}
#if LLVM_HAS_RVALUE_REFERENCES
- SmallPtrSet(SmallPtrSet &&that)
- : SmallPtrSetImplBase(SmallStorage, SmallSizePowTwo, std::move(that)) {}
+ SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize,
+ SmallPtrSetImpl &&that)
+ : SmallPtrSetImplBase(SmallStorage, SmallSize, std::move(that)) {}
#endif
+ explicit SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize)
+ : SmallPtrSetImplBase(SmallStorage, SmallSize) {}
- template<typename It>
- SmallPtrSet(It I, It E) : SmallPtrSetImplBase(SmallStorage, SmallSizePowTwo) {
- insert(I, E);
- }
-
+public:
/// insert - This returns true if the pointer was new to the set, false if it
/// was already in the set.
bool insert(PtrType Ptr) {
@@ -290,11 +287,37 @@ public:
inline iterator end() const {
return iterator(CurArray+CurArraySize, CurArray+CurArraySize);
}
+};
+
+/// SmallPtrSet - This class implements a set which is optimized for holding
+/// SmallSize or less elements. This internally rounds up SmallSize to the next
+/// power of two if it is not already a power of two. See the comments above
+/// SmallPtrSetImplBase for details of the algorithm.
+template<class PtrType, unsigned SmallSize>
+class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
+ typedef SmallPtrSetImpl<PtrType> BaseT;
+
+ // Make sure that SmallSize is a power of two, round up if not.
+ enum { SmallSizePowTwo = RoundUpToPowerOfTwo<SmallSize>::Val };
+ /// SmallStorage - Fixed size storage used in 'small mode'.
+ const void *SmallStorage[SmallSizePowTwo];
+public:
+ SmallPtrSet() : BaseT(SmallStorage, SmallSizePowTwo) {}
+ SmallPtrSet(const SmallPtrSet &that) : BaseT(SmallStorage, that) {}
+#if LLVM_HAS_RVALUE_REFERENCES
+ SmallPtrSet(SmallPtrSet &&that)
+ : BaseT(SmallStorage, SmallSizePowTwo, std::move(that)) {}
+#endif
+
+ template<typename It>
+ SmallPtrSet(It I, It E) : BaseT(SmallStorage, SmallSizePowTwo) {
+ this->insert(I, E);
+ }
SmallPtrSet<PtrType, SmallSize> &
operator=(const SmallPtrSet<PtrType, SmallSize> &RHS) {
if (&RHS != this)
- CopyFrom(RHS);
+ this->CopyFrom(RHS);
return *this;
}
@@ -302,7 +325,7 @@ public:
SmallPtrSet<PtrType, SmallSize>&
operator=(SmallPtrSet<PtrType, SmallSize> &&RHS) {
if (&RHS != this)
- MoveFrom(SmallSizePowTwo, std::move(RHS));
+ this->MoveFrom(SmallSizePowTwo, std::move(RHS));
return *this;
}
#endif