2007-09-30 02:47:20 +02:00
|
|
|
//===- llvm/ADT/DenseSet.h - Dense probed hash table ------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-09-30 02:47:20 +02: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-25 01:48:12 +02:00
|
|
|
typedef DenseMap<ValueT, char, ValueInfoT> MapTy;
|
|
|
|
MapTy TheMap;
|
2007-09-30 02:47:20 +02:00
|
|
|
public:
|
|
|
|
DenseSet(const DenseSet &Other) : TheMap(Other.TheMap) {}
|
|
|
|
explicit DenseSet(unsigned NumInitBuckets = 64) : TheMap(NumInitBuckets) {}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-09-30 02:47:20 +02:00
|
|
|
bool empty() const { return TheMap.empty(); }
|
2009-01-09 20:25:42 +01:00
|
|
|
unsigned size() const { return TheMap.size(); }
|
|
|
|
|
2007-09-30 02:47:20 +02:00
|
|
|
void clear() {
|
|
|
|
TheMap.clear();
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-10-05 19:40:38 +02:00
|
|
|
bool count(const ValueT &V) const {
|
2007-09-30 02:47:20 +02:00
|
|
|
return TheMap.count(V);
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-09-30 02:47:20 +02:00
|
|
|
void erase(const ValueT &V) {
|
|
|
|
TheMap.erase(V);
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-09-30 02:47:20 +02:00
|
|
|
DenseSet &operator=(const DenseSet &RHS) {
|
|
|
|
TheMap = RHS.TheMap;
|
|
|
|
return *this;
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-04-25 01:48:12 +02:00
|
|
|
// Iterators.
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-04-25 01:48:12 +02:00
|
|
|
class Iterator {
|
|
|
|
typename MapTy::iterator I;
|
|
|
|
public:
|
|
|
|
Iterator(const typename MapTy::iterator &i) : I(i) {}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-04-25 01:48:12 +02:00
|
|
|
ValueT& operator*() { return I->first; }
|
|
|
|
ValueT* operator->() { return &I->first; }
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-04-25 01:48:12 +02:00
|
|
|
Iterator& operator++() { ++I; return *this; };
|
|
|
|
bool operator==(const Iterator& X) const { return I == X.I; }
|
2008-04-25 01:49:45 +02:00
|
|
|
bool operator!=(const Iterator& X) const { return I != X.I; }
|
2008-04-25 01:48:12 +02:00
|
|
|
};
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-04-25 01:48:12 +02:00
|
|
|
class ConstIterator {
|
|
|
|
typename MapTy::const_iterator I;
|
|
|
|
public:
|
|
|
|
ConstIterator(const typename MapTy::const_iterator &i) : I(i) {}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-04-25 01:48:12 +02:00
|
|
|
const ValueT& operator*() { return I->first; }
|
|
|
|
const ValueT* operator->() { return &I->first; }
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-04-25 01:48:12 +02:00
|
|
|
ConstIterator& operator++() { ++I; return *this; };
|
|
|
|
bool operator==(const ConstIterator& X) const { return I == X.I; }
|
2008-04-25 01:49:45 +02:00
|
|
|
bool operator!=(const ConstIterator& X) const { return I != X.I; }
|
2008-04-25 01:48:12 +02:00
|
|
|
};
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-04-25 01:48:12 +02:00
|
|
|
typedef Iterator iterator;
|
|
|
|
typedef ConstIterator const_iterator;
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-04-25 01:48:12 +02:00
|
|
|
iterator begin() { return Iterator(TheMap.begin()); }
|
|
|
|
iterator end() { return Iterator(TheMap.end()); }
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-04-25 01:48:12 +02:00
|
|
|
const_iterator begin() const { return ConstIterator(TheMap.begin()); }
|
|
|
|
const_iterator end() const { return ConstIterator(TheMap.end()); }
|
2008-07-07 19:46:23 +02:00
|
|
|
|
|
|
|
std::pair<iterator, bool> insert(const ValueT &V) {
|
|
|
|
return TheMap.insert(std::make_pair(V, 0));
|
|
|
|
}
|
2009-04-01 21:50:49 +02:00
|
|
|
|
|
|
|
// Range insertion of values.
|
|
|
|
template<typename InputIt>
|
|
|
|
void insert(InputIt I, InputIt E) {
|
|
|
|
for (; I != E; ++I)
|
|
|
|
insert(*I);
|
|
|
|
}
|
2007-09-30 02:47:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|