X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FUniqueVector.h;h=2d02d1ce166fabbd8082c7a1e750853d07200ff0;hb=b61054ff8f5568489109a0ccf2799307c3671309;hp=8f0e686bf85012aed9efc85a532835ac0f40704f;hpb=c04a1ce623c3229aa492281d00f445724868b861;p=oota-llvm.git diff --git a/include/llvm/ADT/UniqueVector.h b/include/llvm/ADT/UniqueVector.h index 8f0e686bf85..2d02d1ce166 100644 --- a/include/llvm/ADT/UniqueVector.h +++ b/include/llvm/ADT/UniqueVector.h @@ -2,14 +2,15 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by James M. Laskey 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. // //===----------------------------------------------------------------------===// #ifndef LLVM_ADT_UNIQUEVECTOR_H #define LLVM_ADT_UNIQUEVECTOR_H +#include #include #include @@ -19,7 +20,7 @@ namespace llvm { /// UniqueVector - This class produces a sequential ID number (base 1) for each /// unique entry that is added. T is the type of entries in the vector. This /// class should have an implementation of operator== and of operator<. -/// Entries can be fetched using operator[] with the entry ID. +/// Entries can be fetched using operator[] with the entry ID. template class UniqueVector { private: // Map - Used to handle the correspondence of entry to ID. @@ -28,34 +29,34 @@ private: // Vector - ID ordered vector of entries. Entries can be indexed by ID - 1. // std::vector Vector; - + public: /// insert - Append entry to the vector if it doesn't already exist. Returns /// the entry's index + 1 to be used as a unique ID. unsigned insert(const T &Entry) { // Check if the entry is already in the map. unsigned &Val = Map[Entry]; - + // See if entry exists, if so return prior ID. if (Val) return Val; // Compute ID for entry. - Val = Vector.size() + 1; - + Val = static_cast(Vector.size()) + 1; + // Insert in vector. Vector.push_back(Entry); return Val; } - + /// idFor - return the ID for an existing entry. Returns 0 if the entry is /// not found. unsigned idFor(const T &Entry) const { // Search for entry in the map. typename std::map::const_iterator MI = Map.find(Entry); - + // See if entry exists, if so return ID. if (MI != Map.end()) return MI->second; - + // No luck. return 0; } @@ -66,15 +67,15 @@ public: assert(ID-1 < size() && "ID is 0 or out of range!"); return Vector[ID - 1]; } - + /// size - Returns the number of entries in the vector. /// size_t size() const { return Vector.size(); } - + /// empty - Returns true if the vector is empty. /// bool empty() const { return Vector.empty(); } - + /// reset - Clears all the entries. /// void reset() {