b19dc5e2fc34224bf2a09a4d9a56db63bdc20d91
[oota-llvm.git] / include / llvm / ADT / DenseSet.h
1 //===- llvm/ADT/DenseSet.h - Dense probed hash table ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source 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 {
27   DenseMap<ValueT, char, ValueInfoT> TheMap;
28 public:
29   DenseSet(const DenseSet &Other) : TheMap(Other.TheMap) {}
30   explicit DenseSet(unsigned NumInitBuckets = 64) : TheMap(NumInitBuckets) {}
31   
32   bool empty() const { return TheMap.empty(); }
33   unsigned size() const { return TheMap.size(); }
34   
35   // TODO add iterators.
36   
37   void clear() {
38     TheMap.clear();
39   }
40   
41   bool count(const ValueT &V) const {
42     return TheMap.count(V);
43   }
44   
45   void insert(const ValueT &V) {
46     TheMap[V] = 0;
47   }
48   
49   void erase(const ValueT &V) {
50     TheMap.erase(V);
51   }
52   
53   DenseSet &operator=(const DenseSet &RHS) {
54     TheMap = RHS.TheMap;
55     return *this;
56   }
57 };
58
59 } // end namespace llvm
60
61 #endif