summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-02-03 23:56:03 +0000
committerChris Lattner <sabre@nondot.org>2007-02-03 23:56:03 +0000
commit337cde0d5ac8c28793b305d17c1ccfb5228eab11 (patch)
treea32ac6a61a7dd73baadc4ccd52e3ea4ba0d76849 /include
parent7f3da2dd13d2c420c22800845486ba5971e37eb0 (diff)
downloadllvm-337cde0d5ac8c28793b305d17c1ccfb5228eab11.tar.gz
llvm-337cde0d5ac8c28793b305d17c1ccfb5228eab11.tar.bz2
llvm-337cde0d5ac8c28793b305d17c1ccfb5228eab11.tar.xz
Convert SetVector to be a true adapter class and add SmallSetVector.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33846 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/SetVector.h27
1 files changed, 22 insertions, 5 deletions
diff --git a/include/llvm/ADT/SetVector.h b/include/llvm/ADT/SetVector.h
index e70af611a7..ec3fd536b3 100644
--- a/include/llvm/ADT/SetVector.h
+++ b/include/llvm/ADT/SetVector.h
@@ -12,31 +12,35 @@
// visited later but in a deterministic order (insertion order). The interface
// 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
#define LLVM_ADT_SETVECTOR_H
-#include <set>
+#include "llvm/ADT/SmallSet.h"
#include <vector>
#include <cassert>
#include <algorithm>
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
/// order of insertion.
/// @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 {
public:
typedef T value_type;
typedef T key_type;
typedef T& reference;
typedef const T& const_reference;
- typedef std::set<value_type> set_type;
- typedef std::vector<value_type> vector_type;
+ typedef Set set_type;
+ typedef Vector vector_type;
typedef typename vector_type::const_iterator iterator;
typedef typename vector_type::const_iterator const_iterator;
typedef typename vector_type::size_type size_type;
@@ -144,6 +148,19 @@ private:
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
// vim: sw=2 ai