LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DenseSet.h
Go to the documentation of this file.
1 //===- llvm/ADT/DenseSet.h - Dense probed hash table ------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the DenseSet class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ADT_DENSESET_H
15 #define LLVM_ADT_DENSESET_H
16 
17 #include "llvm/ADT/DenseMap.h"
18 
19 namespace llvm {
20 
21 /// DenseSet - This implements a dense probed hash-table based set.
22 ///
23 /// FIXME: This is currently implemented directly in terms of DenseMap, this
24 /// should be optimized later if there is a need.
25 template<typename ValueT, typename ValueInfoT = DenseMapInfo<ValueT> >
26 class DenseSet {
28  MapTy TheMap;
29 public:
30  DenseSet(const DenseSet &Other) : TheMap(Other.TheMap) {}
31  explicit DenseSet(unsigned NumInitBuckets = 0) : TheMap(NumInitBuckets) {}
32 
33  bool empty() const { return TheMap.empty(); }
34  unsigned size() const { return TheMap.size(); }
35  size_t getMemorySize() const { return TheMap.getMemorySize(); }
36 
37  /// Grow the DenseSet so that it has at least Size buckets. Will not shrink
38  /// the Size of the set.
39  void resize(size_t Size) { TheMap.resize(Size); }
40 
41  void clear() {
42  TheMap.clear();
43  }
44 
45  bool count(const ValueT &V) const {
46  return TheMap.count(V);
47  }
48 
49  bool erase(const ValueT &V) {
50  return TheMap.erase(V);
51  }
52 
53  void swap(DenseSet& RHS) {
54  TheMap.swap(RHS.TheMap);
55  }
56 
57  DenseSet &operator=(const DenseSet &RHS) {
58  TheMap = RHS.TheMap;
59  return *this;
60  }
61 
62  // Iterators.
63 
64  class Iterator {
65  typename MapTy::iterator I;
66  friend class DenseSet;
67  public:
69  typedef ValueT value_type;
70  typedef value_type *pointer;
72  typedef std::forward_iterator_tag iterator_category;
73 
74  Iterator(const typename MapTy::iterator &i) : I(i) {}
75 
76  ValueT& operator*() { return I->first; }
77  ValueT* operator->() { return &I->first; }
78 
79  Iterator& operator++() { ++I; return *this; }
80  bool operator==(const Iterator& X) const { return I == X.I; }
81  bool operator!=(const Iterator& X) const { return I != X.I; }
82  };
83 
84  class ConstIterator {
85  typename MapTy::const_iterator I;
86  friend class DenseSet;
87  public:
89  typedef ValueT value_type;
90  typedef value_type *pointer;
92  typedef std::forward_iterator_tag iterator_category;
93 
94  ConstIterator(const typename MapTy::const_iterator &i) : I(i) {}
95 
96  const ValueT& operator*() { return I->first; }
97  const ValueT* operator->() { return &I->first; }
98 
99  ConstIterator& operator++() { ++I; return *this; }
100  bool operator==(const ConstIterator& X) const { return I == X.I; }
101  bool operator!=(const ConstIterator& X) const { return I != X.I; }
102  };
103 
104  typedef Iterator iterator;
105  typedef ConstIterator const_iterator;
106 
107  iterator begin() { return Iterator(TheMap.begin()); }
108  iterator end() { return Iterator(TheMap.end()); }
109 
110  const_iterator begin() const { return ConstIterator(TheMap.begin()); }
111  const_iterator end() const { return ConstIterator(TheMap.end()); }
112 
113  iterator find(const ValueT &V) { return Iterator(TheMap.find(V)); }
114  void erase(Iterator I) { return TheMap.erase(I.I); }
115  void erase(ConstIterator CI) { return TheMap.erase(CI.I); }
116 
117  std::pair<iterator, bool> insert(const ValueT &V) {
118  return TheMap.insert(std::make_pair(V, 0));
119  }
120 
121  // Range insertion of values.
122  template<typename InputIt>
123  void insert(InputIt I, InputIt E) {
124  for (; I != E; ++I)
125  insert(*I);
126  }
127 };
128 
129 } // end namespace llvm
130 
131 #endif
bool operator!=(const Iterator &X) const
Definition: DenseSet.h:81
std::forward_iterator_tag iterator_category
Definition: DenseSet.h:92
MapTy::iterator::difference_type difference_type
Definition: DenseSet.h:68
value_type & reference
Definition: DenseSet.h:71
DenseSet(const DenseSet &Other)
Definition: DenseSet.h:30
Iterator(const typename MapTy::iterator &i)
Definition: DenseSet.h:74
ConstIterator(const typename MapTy::const_iterator &i)
Definition: DenseSet.h:94
size_t getMemorySize() const
Definition: DenseMap.h:527
const ValueT & operator*()
Definition: DenseSet.h:96
ValueT & operator*()
Definition: DenseSet.h:76
bool erase(const ValueT &V)
Definition: DenseSet.h:49
size_t getMemorySize() const
Definition: DenseSet.h:35
Iterator iterator
Definition: DenseSet.h:104
bool empty() const
Definition: DenseSet.h:33
ConstIterator const_iterator
Definition: DenseSet.h:105
ConstIterator & operator++()
Definition: DenseSet.h:99
void swap(DenseMap &RHS)
Definition: DenseMap.h:576
bool operator!=(const ConstIterator &X) const
Definition: DenseSet.h:101
void erase(Iterator I)
Definition: DenseSet.h:114
std::forward_iterator_tag iterator_category
Definition: DenseSet.h:72
iterator find(const ValueT &V)
Definition: DenseSet.h:113
void resize(size_t Size)
Grow the densemap so that it has at least Size buckets. Does not shrink.
Definition: DenseMap.h:73
value_type * pointer
Definition: DenseSet.h:70
iterator end()
Definition: DenseMap.h:57
const_iterator end() const
Definition: DenseSet.h:111
bool count(const KeyT &Val) const
count - Return true if the specified key is in the map.
Definition: DenseMap.h:103
const ValueT * operator->()
Definition: DenseSet.h:97
ptrdiff_t difference_type
Definition: DenseMap.h:993
void erase(ConstIterator CI)
Definition: DenseSet.h:115
void insert(InputIt I, InputIt E)
Definition: DenseSet.h:123
DenseSet(unsigned NumInitBuckets=0)
Definition: DenseSet.h:31
iterator begin()
Definition: DenseSet.h:107
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:153
bool count(const ValueT &V) const
Definition: DenseSet.h:45
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:117
bool erase(const KeyT &Val)
Definition: DenseMap.h:190
bool operator==(const ConstIterator &X) const
Definition: DenseSet.h:100
DenseSet & operator=(const DenseSet &RHS)
Definition: DenseSet.h:57
Iterator & operator++()
Definition: DenseSet.h:79
unsigned size() const
Definition: DenseMap.h:70
iterator begin()
Definition: DenseMap.h:53
void resize(size_t Size)
Definition: DenseSet.h:39
const_iterator begin() const
Definition: DenseSet.h:110
#define I(x, y, z)
Definition: MD5.cpp:54
MapTy::const_iterator::difference_type difference_type
Definition: DenseSet.h:88
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Definition: DenseMap.h:67
void clear()
Definition: DenseSet.h:41
bool operator==(const Iterator &X) const
Definition: DenseSet.h:80
unsigned size() const
Definition: DenseSet.h:34
void swap(DenseSet &RHS)
Definition: DenseSet.h:53
iterator end()
Definition: DenseSet.h:108
ValueT * operator->()
Definition: DenseSet.h:77
iterator find(const KeyT &Val)
Definition: DenseMap.h:108
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")