X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FSetOperations.h;h=71f5db380f6ea24d898dbf99c010f0c06927a880;hb=e19f11215d8fa29635b28317dd1cfd1915d048d4;hp=dc6e0d6029efa6e75857ddd5c1d75fa570879697;hpb=b2109ce97881269a610fa4afbcbca350e975174d;p=oota-llvm.git diff --git a/include/llvm/ADT/SetOperations.h b/include/llvm/ADT/SetOperations.h index dc6e0d6029e..71f5db380f6 100644 --- a/include/llvm/ADT/SetOperations.h +++ b/include/llvm/ADT/SetOperations.h @@ -1,10 +1,10 @@ -//===-- Support/SetOperations.h - Generic Set Operations --------*- C++ -*-===// -// +//===-- llvm/ADT/SetOperations.h - Generic Set Operations -------*- C++ -*-===// +// // The LLVM Compiler Infrastructure // -// This file was developed by the LLVM research group 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. +// //===----------------------------------------------------------------------===// // // This file defines generic set operations that may be used on set's of @@ -12,13 +12,15 @@ // //===----------------------------------------------------------------------===// -#ifndef SUPPORT_SETOPERATIONS_H -#define SUPPORT_SETOPERATIONS_H +#ifndef LLVM_ADT_SETOPERATIONS_H +#define LLVM_ADT_SETOPERATIONS_H -// set_union(A, B) - Compute A := A u B, return whether A changed. -// +namespace llvm { + +/// set_union(A, B) - Compute A := A u B, return whether A changed. +/// template -bool set_union(S1Ty &S1, const S2Ty &S2) { +bool set_union(S1Ty &S1, const S2Ty &S2) { bool Changed = false; for (typename S2Ty::const_iterator SI = S2.begin(), SE = S2.end(); @@ -29,22 +31,22 @@ bool set_union(S1Ty &S1, const S2Ty &S2) { return Changed; } -// set_intersect(A, B) - Compute A := A ^ B -// Identical to set_intersection, except that it works on set<>'s and -// is nicer to use. Functionally, this iterates through S1, removing -// elements that are not contained in S2. -// -template class S1Ty, class ETy, class S2Ty> -void set_intersect(S1Ty &S1, const S2Ty &S2) { - for (typename S1Ty::iterator I = S1.begin(); I != S1.end();) { - const ETy &E = *I; - ++I; - if (!S2.count(E)) S1.erase(E); // Erase element if not in S2 - } +/// set_intersect(A, B) - Compute A := A ^ B +/// Identical to set_intersection, except that it works on set<>'s and +/// is nicer to use. Functionally, this iterates through S1, removing +/// elements that are not contained in S2. +/// +template +void set_intersect(S1Ty &S1, const S2Ty &S2) { + for (typename S1Ty::iterator I = S1.begin(); I != S1.end();) { + const typename S1Ty::key_type &E = *I; + ++I; + if (!S2.count(E)) S1.erase(E); // Erase element if not in S2 + } } -// set_difference(A, B) - Return A - B -// +/// set_difference(A, B) - Return A - B +/// template S1Ty set_difference(const S1Ty &S1, const S2Ty &S2) { S1Ty Result; @@ -55,13 +57,15 @@ S1Ty set_difference(const S1Ty &S1, const S2Ty &S2) { return Result; } -// set_subtract(A, B) - Compute A := A - B -// +/// set_subtract(A, B) - Compute A := A - B +/// template -void set_subtract(S1Ty &S1, const S2Ty &S2) { +void set_subtract(S1Ty &S1, const S2Ty &S2) { for (typename S2Ty::const_iterator SI = S2.begin(), SE = S2.end(); - SI != SE; ++SI) + SI != SE; ++SI) S1.erase(*SI); } +} // End llvm namespace + #endif