LLVM API Documentation
00001 //===- llvm/ADT/DenseSet.h - Dense probed hash table ------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the DenseSet class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_ADT_DENSESET_H 00015 #define LLVM_ADT_DENSESET_H 00016 00017 #include "llvm/ADT/DenseMap.h" 00018 00019 namespace llvm { 00020 00021 /// DenseSet - This implements a dense probed hash-table based set. 00022 /// 00023 /// FIXME: This is currently implemented directly in terms of DenseMap, this 00024 /// should be optimized later if there is a need. 00025 template<typename ValueT, typename ValueInfoT = DenseMapInfo<ValueT> > 00026 class DenseSet { 00027 typedef DenseMap<ValueT, char, ValueInfoT> MapTy; 00028 MapTy TheMap; 00029 public: 00030 DenseSet(const DenseSet &Other) : TheMap(Other.TheMap) {} 00031 explicit DenseSet(unsigned NumInitBuckets = 64) : TheMap(NumInitBuckets) {} 00032 00033 bool empty() const { return TheMap.empty(); } 00034 unsigned size() const { return TheMap.size(); } 00035 00036 void clear() { 00037 TheMap.clear(); 00038 } 00039 00040 bool count(const ValueT &V) const { 00041 return TheMap.count(V); 00042 } 00043 00044 void erase(const ValueT &V) { 00045 TheMap.erase(V); 00046 } 00047 00048 DenseSet &operator=(const DenseSet &RHS) { 00049 TheMap = RHS.TheMap; 00050 return *this; 00051 } 00052 00053 // Iterators. 00054 00055 class Iterator { 00056 typename MapTy::iterator I; 00057 public: 00058 Iterator(const typename MapTy::iterator &i) : I(i) {} 00059 00060 ValueT& operator*() { return I->first; } 00061 ValueT* operator->() { return &I->first; } 00062 00063 Iterator& operator++() { ++I; return *this; }; 00064 bool operator==(const Iterator& X) const { return I == X.I; } 00065 bool operator!=(const Iterator& X) const { return I != X.I; } 00066 }; 00067 00068 class ConstIterator { 00069 typename MapTy::const_iterator I; 00070 public: 00071 ConstIterator(const typename MapTy::const_iterator &i) : I(i) {} 00072 00073 const ValueT& operator*() { return I->first; } 00074 const ValueT* operator->() { return &I->first; } 00075 00076 ConstIterator& operator++() { ++I; return *this; }; 00077 bool operator==(const ConstIterator& X) const { return I == X.I; } 00078 bool operator!=(const ConstIterator& X) const { return I != X.I; } 00079 }; 00080 00081 typedef Iterator iterator; 00082 typedef ConstIterator const_iterator; 00083 00084 iterator begin() { return Iterator(TheMap.begin()); } 00085 iterator end() { return Iterator(TheMap.end()); } 00086 00087 const_iterator begin() const { return ConstIterator(TheMap.begin()); } 00088 const_iterator end() const { return ConstIterator(TheMap.end()); } 00089 00090 std::pair<iterator, bool> insert(const ValueT &V) { 00091 return TheMap.insert(std::make_pair(V, 0)); 00092 } 00093 }; 00094 00095 } // end namespace llvm 00096 00097 #endif