forked from OSchip/llvm-project
Convert SetVector to be a true adapter class and add SmallSetVector.
llvm-svn: 33846
This commit is contained in:
parent
6c344e56b1
commit
2b2b6c6c97
|
@ -12,31 +12,35 @@
|
||||||
// visited later but in a deterministic order (insertion order). The interface
|
// visited later but in a deterministic order (insertion order). The interface
|
||||||
// is purposefully minimal.
|
// is purposefully minimal.
|
||||||
//
|
//
|
||||||
|
// This file defines SetVector and SmallSetVector, which performs no allocations
|
||||||
|
// if the SetVector has less than a certain number of elements.
|
||||||
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef LLVM_ADT_SETVECTOR_H
|
#ifndef LLVM_ADT_SETVECTOR_H
|
||||||
#define LLVM_ADT_SETVECTOR_H
|
#define LLVM_ADT_SETVECTOR_H
|
||||||
|
|
||||||
#include <set>
|
#include "llvm/ADT/SmallSet.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
/// This class provides a way to keep a set of things that also has the
|
/// This adapter class provides a way to keep a set of things that also has the
|
||||||
/// property of a deterministic iteration order. The order of iteration is the
|
/// property of a deterministic iteration order. The order of iteration is the
|
||||||
/// order of insertion.
|
/// order of insertion.
|
||||||
/// @brief A vector that has set insertion semantics.
|
/// @brief A vector that has set insertion semantics.
|
||||||
template <typename T>
|
template <typename T, typename Vector = std::vector<T>,
|
||||||
|
typename Set = std::set<T> >
|
||||||
class SetVector {
|
class SetVector {
|
||||||
public:
|
public:
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
typedef T key_type;
|
typedef T key_type;
|
||||||
typedef T& reference;
|
typedef T& reference;
|
||||||
typedef const T& const_reference;
|
typedef const T& const_reference;
|
||||||
typedef std::set<value_type> set_type;
|
typedef Set set_type;
|
||||||
typedef std::vector<value_type> vector_type;
|
typedef Vector vector_type;
|
||||||
typedef typename vector_type::const_iterator iterator;
|
typedef typename vector_type::const_iterator iterator;
|
||||||
typedef typename vector_type::const_iterator const_iterator;
|
typedef typename vector_type::const_iterator const_iterator;
|
||||||
typedef typename vector_type::size_type size_type;
|
typedef typename vector_type::size_type size_type;
|
||||||
|
@ -144,6 +148,19 @@ private:
|
||||||
vector_type vector_; ///< The vector.
|
vector_type vector_; ///< The vector.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// SmallSetVector - A SetVector that performs no allocations if smaller than
|
||||||
|
/// a certain size.
|
||||||
|
template <typename T, unsigned N>
|
||||||
|
class SmallSetVector : public SetVector<T, SmallVector<T, N>, SmallSet<T, N> > {
|
||||||
|
SmallSetVector() {}
|
||||||
|
|
||||||
|
/// @brief Initialize a SmallSetVector with a range of elements
|
||||||
|
template<typename It>
|
||||||
|
SmallSetVector(It Start, It End) {
|
||||||
|
this->insert(Start, End);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
// vim: sw=2 ai
|
// vim: sw=2 ai
|
||||||
|
|
Loading…
Reference in New Issue