1
//===- llvm/ADT/DenseSet.h - Dense probed hash table ------------*- C++ -*-===//
3
// The LLVM Compiler Infrastructure
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
8
//===----------------------------------------------------------------------===//
10
// This file defines the DenseSet class.
12
//===----------------------------------------------------------------------===//
14
#ifndef LLVM_ADT_DENSESET_H
15
#define LLVM_ADT_DENSESET_H
17
#include "llvm/ADT/DenseMap.h"
21
/// DenseSet - This implements a dense probed hash-table based set.
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> >
27
typedef DenseMap<ValueT, char, ValueInfoT> MapTy;
30
DenseSet(const DenseSet &Other) : TheMap(Other.TheMap) {}
31
explicit DenseSet(unsigned NumInitBuckets = 64) : TheMap(NumInitBuckets) {}
33
bool empty() const { return TheMap.empty(); }
34
unsigned size() const { return TheMap.size(); }
40
bool count(const ValueT &V) const {
41
return TheMap.count(V);
44
bool erase(const ValueT &V) {
45
return TheMap.erase(V);
48
DenseSet &operator=(const DenseSet &RHS) {
56
typename MapTy::iterator I;
58
Iterator(const typename MapTy::iterator &i) : I(i) {}
60
ValueT& operator*() { return I->first; }
61
ValueT* operator->() { return &I->first; }
63
Iterator& operator++() { ++I; return *this; }
64
bool operator==(const Iterator& X) const { return I == X.I; }
65
bool operator!=(const Iterator& X) const { return I != X.I; }
69
typename MapTy::const_iterator I;
71
ConstIterator(const typename MapTy::const_iterator &i) : I(i) {}
73
const ValueT& operator*() { return I->first; }
74
const ValueT* operator->() { return &I->first; }
76
ConstIterator& operator++() { ++I; return *this; }
77
bool operator==(const ConstIterator& X) const { return I == X.I; }
78
bool operator!=(const ConstIterator& X) const { return I != X.I; }
81
typedef Iterator iterator;
82
typedef ConstIterator const_iterator;
84
iterator begin() { return Iterator(TheMap.begin()); }
85
iterator end() { return Iterator(TheMap.end()); }
87
const_iterator begin() const { return ConstIterator(TheMap.begin()); }
88
const_iterator end() const { return ConstIterator(TheMap.end()); }
90
std::pair<iterator, bool> insert(const ValueT &V) {
91
return TheMap.insert(std::make_pair(V, 0));
94
// Range insertion of values.
95
template<typename InputIt>
96
void insert(InputIt I, InputIt E) {
102
} // end namespace llvm