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) {}
|
2011-07-21 23:03:59 +00:00
|
|
|
explicit DenseSet(unsigned NumInitBuckets = 0) : 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(); }
|
|
|
|
|
2011-01-27 09:10:42 +00:00
|
|
|
/// Grow the denseset so that it has at least Size buckets. Does not shrink
|
|
|
|
void resize(size_t Size) { TheMap.resize(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
|
|
|
|
2010-02-02 21:11:22 +00:00
|
|
|
bool erase(const ValueT &V) {
|
|
|
|
return TheMap.erase(V);
|
2007-09-30 00:47:20 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2010-03-08 20:45:52 +00:00
|
|
|
void swap(DenseSet& RHS) {
|
|
|
|
TheMap.swap(RHS.TheMap);
|
|
|
|
}
|
|
|
|
|
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;
|
2010-07-27 23:55:47 +00:00
|
|
|
friend class DenseSet;
|
2008-04-24 23:48:12 +00:00
|
|
|
public:
|
2010-03-08 20:45:52 +00:00
|
|
|
typedef typename MapTy::iterator::difference_type difference_type;
|
|
|
|
typedef ValueT value_type;
|
|
|
|
typedef value_type *pointer;
|
|
|
|
typedef value_type &reference;
|
|
|
|
typedef std::forward_iterator_tag iterator_category;
|
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
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
|
|
|
|
2009-12-06 16:58:41 +00:00
|
|
|
Iterator& operator++() { ++I; return *this; }
|
2008-04-24 23:48:12 +00:00
|
|
|
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;
|
2010-07-27 23:55:47 +00:00
|
|
|
friend class DenseSet;
|
2008-04-24 23:48:12 +00:00
|
|
|
public:
|
2010-03-08 20:45:52 +00:00
|
|
|
typedef typename MapTy::const_iterator::difference_type difference_type;
|
|
|
|
typedef ValueT value_type;
|
|
|
|
typedef value_type *pointer;
|
|
|
|
typedef value_type &reference;
|
|
|
|
typedef std::forward_iterator_tag iterator_category;
|
|
|
|
|
2008-04-24 23:48:12 +00:00
|
|
|
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
|
|
|
|
2009-12-09 02:58:09 +00:00
|
|
|
ConstIterator& operator++() { ++I; return *this; }
|
2008-04-24 23:48:12 +00:00
|
|
|
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
|
|
|
|
2010-07-27 23:55:47 +00:00
|
|
|
iterator find(const ValueT &V) { return Iterator(TheMap.find(V)); }
|
2010-09-01 14:00:35 +00:00
|
|
|
void erase(Iterator I) { return TheMap.erase(I.I); }
|
|
|
|
void erase(ConstIterator CI) { return TheMap.erase(CI.I); }
|
2010-07-27 23:55:47 +00:00
|
|
|
|
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
|