diff options
Diffstat (limited to 'meowpp/utility.hpp')
-rw-r--r-- | meowpp/utility.hpp | 91 |
1 files changed, 11 insertions, 80 deletions
diff --git a/meowpp/utility.hpp b/meowpp/utility.hpp index 9f6d708..141de41 100644 --- a/meowpp/utility.hpp +++ b/meowpp/utility.hpp @@ -1,11 +1,13 @@ -#include <string> -#include <stack> +#include "utility.h" + + #include <cstdio> +#include <cstdlib> #include <cstdarg> -#include <algorithm> -#include <cctype> #include <cstring> -#include <cmath> + +#include <string> +#include <stack> namespace meow{ @@ -18,6 +20,7 @@ namespace meow{ return std::string(str); } + inline std::string stringReplace(std::string str, std::string const& from, std::string const& to){ @@ -29,6 +32,7 @@ namespace meow{ return out; } + inline bool cstringEndWith(char const* str, int n, ...){ int len = strlen(str); va_list args; @@ -44,6 +48,7 @@ namespace meow{ return false; } + inline void debugPrintf_(char const* file, char const* func, size_t line, @@ -53,6 +58,7 @@ namespace meow{ #endif // DEBUG } + inline void messagePrintf(int level_change, char const* fmt, ...){ static int level = 0; static int last_level = -5; @@ -75,23 +81,6 @@ namespace meow{ fflush(stdout); } - inline double noEPS(double value, double eps){ - return (fabs(value) <= fabs(eps) ? 0 : value); - } - - inline double normalize(double lower, double upper, double value){ - return (value - lower) / (upper - lower); - } - - inline double denormalize(double lower, double upper, double ratio){ - return lower + ratio * (upper - lower); - } - - inline double ratioMapping(double l1, double u1, double m1, - double l2, double u2){ - return denormalize(l2, u2, normalize(l1, u1, m1)); - } - inline bool filenameCompare(std::string const& f1, std::string const& f2){ char const* s1 = f1.c_str(); char const* s2 = f2.c_str(); @@ -115,62 +104,4 @@ namespace meow{ } return false; } - template<class T> - inline T inRange(T const& mn, T const& mx, T const& v){ - return std::min(mx, std::max(mn, v)); - } - template<class T> - inline T squ(T const& x){ - return x * x; - } - template<class T> - inline double average( T const& beg, T const& end, double sigs){ - int N = 0; - double av = 0; - for(T it = beg; it != end; it++, N++){ - av += *it; - } - av /= N; - double sig = 0; - for(T it = beg; it != end; it++){ - sig += (*it - av) * (*it - av); - } - sig = sqrt(sig / N); - double lower = av - sig * sigs, upper = av + sig * sigs; - double ret = 0, retn = 0; - for(T it = beg; it != end; it++){ - if(lower <= *it && *it <= upper){ - ret += *it; - retn++; - } - } - return ret / retn; - } - template<class T> - inline double average( T const& beg, T const& end, T const& p, double sigs){ - int N = 0; - double ps = 0; - for(T it = beg, ip = p; it != end; it++, N++, ip++){ - ps += *ip; - } - double av = 0; - for(T it = beg, ip = p; it != end; it++, ip++){ - av += *it * *ip / ps; - } - double sig = 0; - for(T it = beg, ip = p; it != end; it++, ip++){ - sig += *ip / ps * (*it - av) * (*it - av); - } - sig = sqrt(sig); - double lower = av - sig * sigs, upper = av + sig * sigs; - double ret = 0, retn = 0; - for(T it = beg, ip = p; it != end; it++, ip++){ - if(lower <= *it && *it <= upper){ - ret += *it * *ip; - retn += *ip; - } - } - if(retn <= 1e-10) return av; - return ret / retn; - } } |