/*****************************************************************************/
/*!
*\file cvc_util.h
*\brief basic helper utilities
*
* Author: Clark Barrett
*
* Created: Thu Dec 1 16:35:52 2005
*
*
*
* License to use, copy, modify, sell and/or distribute this software
* and its documentation for any purpose is hereby granted without
* royalty, subject to the terms and conditions defined in the \ref
* LICENSE file provided with this distribution.
*
*
*/
/*****************************************************************************/
#ifndef _cvc3__debug_h
#include "debug.h"
#endif
#ifndef _cvc3__cvc_util_h
#define _cvc3__cvc_util_h
namespace CVC3 {
inline std::string int2string(int n) {
std::ostringstream ss;
ss << n;
return ss.str();
}
template
T abs(T t) { return t < 0 ? -t : t; }
template
T max(T a, T b) { return a > b ? a : b; }
struct ltstr{
bool operator()(const std::string& s1, const std::string& s2) const{
return s1.compare(s2) < 0;
}
};
template
class StrPairLess {
public:
bool operator()(const std::pair& p1,
const std::pair& p2) const {
return p1.first < p2.first;
}
};
template
std::pair strPair(const std::string& f, const T& t) {
return std::pair(f, t);
}
typedef std::pair StrPair;
//! Sort two vectors based on the first vector
template
void sort2(std::vector& keys, std::vector& vals) {
DebugAssert(keys.size()==vals.size(), "sort2()");
// Create std::vector of pairs
std::vector > pairs;
for(size_t i=0, iend=keys.size(); i comp;
sort(pairs.begin(), pairs.end(), comp);
DebugAssert(pairs.size() == keys.size(), "sort2()");
// Split the pairs back into the original vectors
for(size_t i=0, iend=pairs.size(); i