X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FSetVector.h;h=965f0deacaa249475f6dedf45d5d379b052ca737;hb=a00b80b04c5edb08639c1c6b32e9231fd8b066f7;hp=e70af611a7f693178ca6d83642b764ef98f2565f;hpb=cf48cab945f1cbdf637d7d970398cbe6d89135ee;p=oota-llvm.git diff --git a/include/llvm/ADT/SetVector.h b/include/llvm/ADT/SetVector.h index e70af611a7f..965f0deacaa 100644 --- a/include/llvm/ADT/SetVector.h +++ b/include/llvm/ADT/SetVector.h @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Reid Spencer and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -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 -#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 = SmallSet > 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; @@ -95,7 +99,7 @@ public: /// @returns true iff the element was inserted into the SetVector. /// @brief Insert a new element into the SetVector. bool insert(const value_type &X) { - bool result = set_.insert(X).second; + bool result = set_.insert(X); if (result) vector_.push_back(X); return result; @@ -105,18 +109,20 @@ public: template void insert(It Start, It End) { for (; Start != End; ++Start) - if (set_.insert(*Start).second) + if (set_.insert(*Start)) vector_.push_back(*Start); } /// @brief Remove an item from the set vector. - void remove(const value_type& X) { - if (0 < set_.erase(X)) { + bool remove(const value_type& X) { + if (set_.erase(X)) { typename vector_type::iterator I = std::find(vector_.begin(), vector_.end(), X); assert(I != vector_.end() && "Corrupted SetVector instances!"); vector_.erase(I); + return true; } + return false; } @@ -138,12 +144,40 @@ public: set_.erase(back()); vector_.pop_back(); } + + T pop_back_val() { + T Ret = back(); + pop_back(); + return Ret; + } + + bool operator==(const SetVector &that) const { + return vector_ == that.vector_; + } + + bool operator!=(const SetVector &that) const { + return vector_ != that.vector_; + } private: set_type set_; ///< The set. vector_type vector_; ///< The vector. }; +/// SmallSetVector - A SetVector that performs no allocations if smaller than +/// a certain size. +template +class SmallSetVector : public SetVector, SmallSet > { +public: + 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