ImutAVLTree now allocates tree nodes from the BumpPtrAllocator using
[oota-llvm.git] / include / llvm / ADT / FoldingSet.h
index d8671fb791908fbea53c35dc9de435ff3cba7ac4..c567895594b5663f19a1c0d6794fdce5f308877f 100644 (file)
@@ -21,6 +21,7 @@
 #include <string>
 
 namespace llvm {
+  class APFloat;
 
 /// This folding set used for two purposes:
 ///   1. Given information about a node we want to create, look up the unique
@@ -119,7 +120,7 @@ private:
   unsigned NumNodes;
   
 public:
-  FoldingSetImpl(unsigned Log2InitSize = 6);
+  explicit FoldingSetImpl(unsigned Log2InitSize = 6);
   virtual ~FoldingSetImpl();
   
   // Forward declaration.
@@ -149,9 +150,11 @@ public:
     void AddPointer(const void *Ptr);
     void AddInteger(signed I);
     void AddInteger(unsigned I);
+    void AddInteger(int64_t I);
     void AddInteger(uint64_t I);
     void AddFloat(float F);
     void AddDouble(double D);
+    void AddAPFloat(const APFloat& apf);
     void AddString(const std::string &String);
     
     /// ComputeHash - Compute a strong hash value for this NodeID, used to 
@@ -217,6 +220,8 @@ protected:
 typedef FoldingSetImpl::Node FoldingSetNode;
 typedef FoldingSetImpl::NodeID FoldingSetNodeID;
 
+template<class T> class FoldingSetIterator;
+
 //===----------------------------------------------------------------------===//
 /// FoldingSet - This template class is used to instantiate a specialized
 /// implementation of the folding set to the node class T.  T must be a 
@@ -224,16 +229,25 @@ typedef FoldingSetImpl::NodeID FoldingSetNodeID;
 ///
 template<class T> class FoldingSet : public FoldingSetImpl {
 private:
-  /// GetNodeProfile - Each instantiatation of the FoldingSet 
+  /// GetNodeProfile - Each instantiatation of the FoldingSet needs to provide a
+  /// way to convert nodes into a unique specifier.
   virtual void GetNodeProfile(NodeID &ID, Node *N) const {
     T *TN = static_cast<T *>(N);
     TN->Profile(ID);
   }
   
 public:
-  FoldingSet(unsigned Log2InitSize = 6)
+  explicit FoldingSet(unsigned Log2InitSize = 6)
   : FoldingSetImpl(Log2InitSize)
   {}
+  
+  typedef FoldingSetIterator<T> iterator;
+  iterator begin() { return iterator(Buckets); }
+  iterator end() { return iterator(Buckets+NumBuckets); }
+
+  typedef FoldingSetIterator<const T> const_iterator;
+  const_iterator begin() const { return const_iterator(Buckets); }
+  const_iterator end() const { return const_iterator(Buckets+NumBuckets); }
 
   /// GetOrInsertNode - If there is an existing simple Node exactly
   /// equal to the specified node, return it.  Otherwise, insert 'N' and
@@ -246,8 +260,48 @@ public:
   /// return it.  If not, return the insertion token that will make insertion
   /// faster.
   T *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos) {
-    return static_cast<T *>(FoldingSetImpl::FindNodeOrInsertPos(ID,
-                                                                InsertPos));
+    return static_cast<T *>(FoldingSetImpl::FindNodeOrInsertPos(ID, InsertPos));
+  }
+};
+
+//===----------------------------------------------------------------------===//
+/// FoldingSetIteratorImpl - This is the common iterator support shared by all
+/// folding sets, which knows how to walk the folding set hash table.
+class FoldingSetIteratorImpl {
+protected:
+  FoldingSetNode *NodePtr;
+  FoldingSetIteratorImpl(void **Bucket);
+  void advance();
+  
+public:
+  bool operator==(const FoldingSetIteratorImpl &RHS) const {
+    return NodePtr == RHS.NodePtr;
+  }
+  bool operator!=(const FoldingSetIteratorImpl &RHS) const {
+    return NodePtr != RHS.NodePtr;
+  }
+};
+
+
+template<class T>
+class FoldingSetIterator : public FoldingSetIteratorImpl {
+public:
+  FoldingSetIterator(void **Bucket) : FoldingSetIteratorImpl(Bucket) {}
+  
+  T &operator*() const {
+    return *static_cast<T*>(NodePtr);
+  }
+  
+  T *operator->() const {
+    return static_cast<T*>(NodePtr);
+  }
+  
+  inline FoldingSetIterator& operator++() {          // Preincrement
+    advance();
+    return *this;
+  }
+  FoldingSetIterator operator++(int) {        // Postincrement
+    FoldingSetIterator tmp = *this; ++*this; return tmp;
   }
 };