00001 /*******************************************************************************************[Alg.h] 00002 MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 00005 associated documentation files (the "Software"), to deal in the Software without restriction, 00006 including without limitation the rights to use, copy, modify, merge, publish, distribute, 00007 sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00008 furnished to do so, subject to the following conditions: 00009 00010 The above copyright notice and this permission notice shall be included in all copies or 00011 substantial portions of the Software. 00012 00013 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 00014 NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00015 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00016 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 00017 OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00018 **************************************************************************************************/ 00019 00020 #ifndef Alg_h 00021 #define Alg_h 00022 00023 //================================================================================================= 00024 // Useful functions on vectors 00025 00026 00027 #if 1 00028 template<class V, class T> 00029 static inline void remove(V& ts, const T& t) 00030 { 00031 int j = 0; 00032 for (; j < ts.size() && ts[j] != t; j++); 00033 assert(j < ts.size()); 00034 for (; j < ts.size()-1; j++) ts[j] = ts[j+1]; 00035 ts.pop(); 00036 } 00037 #else 00038 template<class V, class T> 00039 static inline void remove(V& ts, const T& t) 00040 { 00041 int j = 0; 00042 for (; j < ts.size() && ts[j] != t; j++); 00043 assert(j < ts.size()); 00044 ts[j] = ts.last(); 00045 ts.pop(); 00046 } 00047 #endif 00048 00049 template<class V, class T> 00050 static inline bool find(V& ts, const T& t) 00051 { 00052 int j = 0; 00053 for (; j < ts.size() && ts[j] != t; j++); 00054 return j < ts.size(); 00055 } 00056 00057 #endif