2007-09-30 00:47:20 +00:00
|
|
|
//===- llvm/ADT/DenseSet.h - Dense probed hash table ------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-09-30 00:47:20 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the DenseSet class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ADT_DENSESET_H
|
|
|
|
#define LLVM_ADT_DENSESET_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// DenseSet - This implements a dense probed hash-table based set.
|
|
|
|
///
|
|
|
|
/// FIXME: This is currently implemented directly in terms of DenseMap, this
|
|
|
|
/// should be optimized later if there is a need.
|
|
|
|
template<typename ValueT, typename ValueInfoT = DenseMapInfo<ValueT> >
|
|
|
|
class DenseSet {
|
2008-04-24 23:48:12 +00:00
|
|
|
typedef DenseMap<ValueT, char, ValueInfoT> MapTy;
|
|
|
|
MapTy TheMap;
|
2007-09-30 00:47:20 +00:00
|
|
|
public:
|
|
|
|
DenseSet(const DenseSet &Other) : TheMap(Other.TheMap) {}
|
|
|
|
explicit DenseSet(unsigned NumInitBuckets = 64) : TheMap(NumInitBuckets) {}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-09-30 00:47:20 +00:00
|
|
|
bool empty() const { return TheMap.empty(); }
|
2009-01-09 19:25:42 +00:00
|
|
|
unsigned size() const { return TheMap.size(); }
|
|
|
|
|
2007-09-30 00:47:20 +00:00
|
|
|
void clear() {
|
|
|
|
TheMap.clear();
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-10-05 17:40:38 +00:00
|
|
|
bool count(const ValueT &V) const {
|
2007-09-30 00:47:20 +00:00
|
|
|
return TheMap.count(V);
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-09-30 00:47:20 +00:00
|
|
|
void erase(const ValueT &V) {
|
|
|
|
TheMap.erase(V);
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-09-30 00:47:20 +00:00
|
|
|
DenseSet &operator=(const DenseSet &RHS) {
|
|
|
|
TheMap = RHS.TheMap;
|
|
|
|
return *this;
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
// Iterators.
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
class Iterator {
|
|
|
|
typename MapTy::iterator I;
|
|
|
|
public:
|
|
|
|
Iterator(const typename MapTy::iterator &i) : I(i) {}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
ValueT& operator*() { return I->first; }
|
|
|
|
ValueT* operator->() { return &I->first; }
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
Iterator& operator++() { ++I; return *this; };
|
|
|
|
bool operator==(const Iterator& X) const { return I == X.I; }
|
2008-04-24 23:49:45 +00:00
|
|
|
bool operator!=(const Iterator& X) const { return I != X.I; }
|
2008-04-24 23:48:12 +00:00
|
|
|
};
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
class ConstIterator {
|
|
|
|
typename MapTy::const_iterator I;
|
|
|
|
public:
|
|
|
|
ConstIterator(const typename MapTy::const_iterator &i) : I(i) {}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
const ValueT& operator*() { return I->first; }
|
|
|
|
const ValueT* operator->() { return &I->first; }
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
ConstIterator& operator++() { ++I; return *this; };
|
|
|
|
bool operator==(const ConstIterator& X) const { return I == X.I; }
|
2008-04-24 23:49:45 +00:00
|
|
|
bool operator!=(const ConstIterator& X) const { return I != X.I; }
|
2008-04-24 23:48:12 +00:00
|
|
|
};
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
typedef Iterator iterator;
|
|
|
|
typedef ConstIterator const_iterator;
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
iterator begin() { return Iterator(TheMap.begin()); }
|
|
|
|
iterator end() { return Iterator(TheMap.end()); }
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
const_iterator begin() const { return ConstIterator(TheMap.begin()); }
|
|
|
|
const_iterator end() const { return ConstIterator(TheMap.end()); }
|
2008-07-07 17:46:23 +00:00
|
|
|
|
|
|
|
std::pair<iterator, bool> insert(const ValueT &V) {
|
|
|
|
return TheMap.insert(std::make_pair(V, 0));
|
|
|
|
}
|
2009-04-01 19:50:49 +00:00
|
|
|
|
|
|
|
// Range insertion of values.
|
|
|
|
template<typename InputIt>
|
|
|
|
void insert(InputIt I, InputIt E) {
|
|
|
|
for (; I != E; ++I)
|
|
|
|
insert(*I);
|
|
|
|
}
|
2007-09-30 00:47:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|