From cfdda5e5210ef3ba37eab8b7e0cc47588fdc78f8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 3 Feb 2007 23:56:03 +0000 Subject: [PATCH] Convert SetVector to be a true adapter class and add SmallSetVector. llvm-svn: 33846 --- include/llvm/ADT/SetVector.h | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/include/llvm/ADT/SetVector.h b/include/llvm/ADT/SetVector.h index e70af611a7f..ec3fd536b31 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 +#include "llvm/ADT/SmallSet.h" #include #include #include 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 +template , + typename Set = std::set > class SetVector { public: typedef T value_type; typedef T key_type; typedef T& reference; typedef const T& const_reference; - typedef std::set set_type; - typedef std::vector 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 +class SmallSetVector : public SetVector, SmallSet > { + SmallSetVector() {} + + /// @brief Initialize a SmallSetVector with a range of elements + template + SmallSetVector(It Start, It End) { + this->insert(Start, End); + } +}; + } // End llvm namespace // vim: sw=2 ai