From 9ec5d78f273d306fb8793e73bbb658097439dbe2 Mon Sep 17 00:00:00 2001 From: cathook Date: Sun, 1 Jun 2014 14:05:05 +0800 Subject: remove hpp --- meowpp/Usage.hpp | 298 -------------------- meowpp/colors/HSL.hpp | 150 ---------- meowpp/colors/HSV.hpp | 144 ---------- meowpp/colors/RGB.hpp | 119 -------- meowpp/colors/YUV.hpp | 100 ------- meowpp/dsa/BinaryIndexTree.hpp | 51 ---- meowpp/dsa/DisjointSet.hpp | 55 ---- meowpp/dsa/KD_Tree.hpp | 272 ------------------ meowpp/dsa/MergeableHeap.hpp | 127 --------- meowpp/dsa/SegmentTree.hpp | 117 -------- meowpp/dsa/SplayTree.hpp | 437 ----------------------------- meowpp/dsa/SplayTree_Range.hpp | 506 ---------------------------------- meowpp/dsa/VP_Tree.hpp | 276 ------------------- meowpp/geo/Vector2D.hpp | 327 ---------------------- meowpp/geo/Vector3D.hpp | 359 ------------------------ meowpp/math/LinearTransformations.hpp | 148 ---------- meowpp/math/Matrix.hpp | 329 ---------------------- meowpp/math/Transformations.hpp | 193 ------------- meowpp/math/utility.hpp | 102 ------- meowpp/oo/ObjPort.hpp | 47 ---- meowpp/oo/Properties.hpp | 175 ------------ meowpp/utility.hpp | 107 ------- 22 files changed, 4439 deletions(-) delete mode 100644 meowpp/Usage.hpp delete mode 100644 meowpp/colors/HSL.hpp delete mode 100644 meowpp/colors/HSV.hpp delete mode 100644 meowpp/colors/RGB.hpp delete mode 100644 meowpp/colors/YUV.hpp delete mode 100644 meowpp/dsa/BinaryIndexTree.hpp delete mode 100644 meowpp/dsa/DisjointSet.hpp delete mode 100644 meowpp/dsa/KD_Tree.hpp delete mode 100644 meowpp/dsa/MergeableHeap.hpp delete mode 100644 meowpp/dsa/SegmentTree.hpp delete mode 100644 meowpp/dsa/SplayTree.hpp delete mode 100644 meowpp/dsa/SplayTree_Range.hpp delete mode 100644 meowpp/dsa/VP_Tree.hpp delete mode 100644 meowpp/geo/Vector2D.hpp delete mode 100644 meowpp/geo/Vector3D.hpp delete mode 100644 meowpp/math/LinearTransformations.hpp delete mode 100644 meowpp/math/Matrix.hpp delete mode 100644 meowpp/math/Transformations.hpp delete mode 100644 meowpp/math/utility.hpp delete mode 100644 meowpp/oo/ObjPort.hpp delete mode 100644 meowpp/oo/Properties.hpp delete mode 100644 meowpp/utility.hpp diff --git a/meowpp/Usage.hpp b/meowpp/Usage.hpp deleted file mode 100644 index ddf56dc..0000000 --- a/meowpp/Usage.hpp +++ /dev/null @@ -1,298 +0,0 @@ -#include "Usage.h" - - -#include "utility.h" - -#include - -#include -#include -#include -#include - -extern "C"{ -#include -} - -namespace meow{ - inline Usage::Usage(): name("nobody") { } - inline Usage::Usage(Usage::String const& _name): name(_name){ } - inline bool Usage::import(Usage const& usage){ - OptionsIterator it; - for(it = usage.options.begin(); it != usage.options.end(); it++){ - unsigned char const& chr = it->first; - Option const& opt = it->second; - if(options.find(chr) == options.end()){ - options[chr] = opt; - }else{ - return false; - } - } - for(size_t i = 0; i < usage.usage_begin.size(); i++){ - usage_begin.push_back(usage.usage_begin[i]); - } - for(size_t i = 0; i < usage.usage_end.size(); i++){ - usage_end.push_back(usage.usage_end[i]); - } - return true; - } - inline bool Usage::update(Usage const& usage){ - OptionsIterator it; - for(it = usage.options.begin(); it != usage.options.end(); it++){ - unsigned char const& chr = it->first; - if(options.find(chr) == options.end()){ - continue; - } - options[chr] = it->second; - } - return true; - } - inline bool Usage::addOption(unsigned char opt, Usage::String const& des){ - if(options.find(opt) != options.end()){ - return false; - } - options[opt] = Option(des); - return true; - } - inline bool Usage::addOption(unsigned char opt, Usage::String const& des, - Usage::String const& val_type, - Usage::String const& val_default, - bool must){ - if(options.find(opt) != options.end()){ - return false; - } - options[opt] = Option(des, val_type, val_default, must); - return true; - } - inline bool Usage::addOptionValueAccept(unsigned char opt, - Usage::String const& val, - Usage::String const& des){ - if(options.find(opt) == options.end()){ - return false; - } - return options[opt].addValueAccept(val, des); - } - inline bool Usage::hasOptionSetup(unsigned char opt) const { - return (options.find(opt) != options.end() && - options.find(opt)->second.hasSetup()); - } - inline size_t Usage::getOptionValuesCount(unsigned char opt) const { - if(options.find(opt) == options.end()){ - return 0; - } - return options.find(opt)->second.getValuesCount(); - } - inline Usage::String Usage::getOptionValue(unsigned char opt, - size_t index) const { - if(options.find(opt) == options.end()){ - return Usage::String(); - } - return options.find(opt)->second.getValue(index); - } - inline size_t Usage::getProcArgsCount() const{ - return proc_arguments.size(); - } - inline Usage::String Usage::getProcArg(size_t index) const { - if(index >= proc_arguments.size()){ - return Usage::String(); - } - return proc_arguments[index]; - } - inline Usage::Strings Usage::getProcArgs() const { - return proc_arguments; - } - inline void Usage::addUsageBegin(Usage::String const& des){ - usage_begin.push_back(stringReplace(des, "", name)); - } - inline void Usage::addUsageEnd(Usage::String const& des){ - usage_end.push_back(stringReplace(des, "", name)); - } - inline Usage::String Usage::getUsage() const { - Usage::String out = stringPrintf("USAGE\n %s", name.c_str()); - OptionsIterator it; - for(it = options.begin(); it != options.end(); it++){ - out += " " + it->second.getUsage(it->first, false); - } - out += "\n\nDESCRIPTION\n"; - for(size_t i = 0; i < usage_begin.size(); i++){ - out += " " + usage_begin[i] + "\n\n"; - } - for(it = options.begin(); it != options.end(); it++){ - out += it->second.getUsage(it->first, true); - } - for(size_t i = 0; i < usage_end.size(); i++){ - out += " " + usage_end[i] + "\n\n"; - } - return out; - } - inline bool Usage::setArguments(int argc, char** argv, Usage::String *errmsg){ - opterr = 0; - Usage::String s; - OptionsIterator it; - Usage::String zzz; - Usage::String& err = (errmsg == NULL ? zzz : *errmsg); - for(it = options.begin(); it != options.end(); it++){ - s += (char)(it->first); - if(it->second.hasValue()){ - s += ":"; - } - } - for(int opt; (opt = getopt(argc, argv, s.c_str())) != -1; ){ - if(options.find(opt) == options.end()){ - if(options.find(optopt) == options.end()){ - err += stringPrintf("Unknown option '-%c'\n", optopt); - }else{ - err += stringPrintf("No specify argument to '-%c'\n", - optopt); - } - opt = optopt; - return false; - } - if(options[opt].setValue(optarg == NULL ? "" : optarg) == false){ - err += stringPrintf( - "Option argument '%s' to '-%c' is not allowed\n" - , optarg, opt); - return false; - } - } - for(it = options.begin(); it != options.end(); it++){ - if(it->second.chkSetup() == false){ - err += stringPrintf("No specify argument to '-%c'\n", - it->first); - return false; - } - } - for(int i = optind; i < argc; i++){ - proc_arguments.push_back(Usage::String(argv[i])); - } - return true; - } - // - inline Usage::Value::Value(){ } - inline Usage::Value::Value(Usage::String const& v){ - value = v; - description = ""; - } - inline Usage::Value::Value(Usage::String const& v, Usage::String const& d){ - value = v; - description = stringReplace(d, "", v); - } - inline Usage::String Usage::Value::getUsage() const { - return stringPrintf("%8s%s : %s\n", - " ", value.c_str(), description.c_str()); - } - inline Usage::String Usage::Value::getValue() const { - return value; - } - inline bool Usage::Value::operator==(Value const& b) const { - return (value == b.value); - } - // - inline Usage::Option::Option(){ } - inline Usage::Option::Option(Usage::String const& des){ - has_setup = false; - has_value = false; - description = des; - must_setup = false; - } - inline Usage::Option::Option(Usage::String const& des, - Usage::String const& typ, - Usage::String const& def, - bool must){ - has_setup = false; - has_value = true; - description = des; - value_type = typ; - value_default = def; - must_setup = must; - } - inline bool Usage::Option::setValue(Usage::String const& str){ - if(has_value){ - if(values_accept.size() > 0 && - std::find(values_accept.begin(), values_accept.end(), - Value(str, "")) == values_accept.end()){ - return false; - } - values.push_back(str); - } - has_setup = true; - return true; - } - inline size_t Usage::Option::getValuesCount()const{return values.size();} - inline Usage::String Usage::Option::getValue(size_t index) const{ - if(!has_value){ - return ""; - } - if(!has_setup || index >= values.size()){ - return value_default; - } - return values[index]; - } - inline bool Usage::Option::addValueAccept(Usage::String const& val, - Usage::String const& des){ - if(!has_value){ - return false; - } - if(std::find(values_accept.begin(), values_accept.end(), Value(val)) - == values_accept.end()){ - values_accept.push_back(Value(val, des)); - } - return true; - } - inline bool Usage::Option::hasSetup() const { return has_setup; } - inline bool Usage::Option::hasValue() const { return has_value; } - inline bool Usage::Option::chkSetup() const { - return !(must_setup && !has_setup); - } - inline Usage::String Usage::Option::getUsage(unsigned char opt, - bool detail) const { - Usage::String ret; - if(!detail){ - if(!has_value){ - ret = stringPrintf("-%c", opt); - }else{ - ret = stringPrintf("-%c %s", opt, value_type.c_str()); - } - if(!must_setup){ - ret = stringPrintf("[%s]", ret.c_str()); - } - }else{ - Usage::String tmp; - if(has_value){ - Usage::String tmp2; - if(value_default != ""){ - tmp2=stringPrintf("defuault='%s'",value_default.c_str()); - } - Usage::String tmp3 = must_setup ? "" : "optional"; - if(tmp2.length() + tmp3.length() > 0){ - if(tmp2.length() > 0 && tmp3.length() > 0){ - tmp = "(" + tmp3 + ", " + tmp2 + ")"; - }else{ - tmp = "(" + tmp3 + tmp2 + ")"; - } - } - tmp = value_type + " " + tmp; - } - ret = stringPrintf(" -%c %s\n", opt, tmp.c_str()); - tmp = stringReplace(description, "", value_type); - Usage::String vs; - for(size_t i = 0; i < values_accept.size(); i++){ - if(i > 0){ - vs += (i + 1 < values_accept.size() ? ", " : " or "); - } - vs += "'" + values_accept[i].getValue() + "'"; - } - if(vs.length() == 0){ - vs = "... (anything)"; - } - tmp = stringReplace(tmp, "", vs); - ret += " " + tmp + "\n"; - for(size_t i = 0; i < values_accept.size(); i++){ - ret += values_accept[i].getUsage(); - } - ret += "\n"; - } - return ret; - } -} - diff --git a/meowpp/colors/HSL.hpp b/meowpp/colors/HSL.hpp deleted file mode 100644 index bd9f469..0000000 --- a/meowpp/colors/HSL.hpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "HSL.h" - -#include "RGB.h" -#include "YUV.h" - -#include "../math/utility.h" - -#include - -#include - -namespace meow{ - template - inline HSL::HSL(){ } - template - inline HSL::HSL(T const& h, T const& s, T const& l){ - hsl_[0] = h; hsl_[1] = s; hsl_[2] = l; - } - template - inline HSL::HSL(T const* hsl){ - for(int i = 0; i < 3; i++) hsl_[i] = hsl[i]; - } - - template - inline T HSL::h() const { return hsl_[0]; } - template - inline T HSL::s() const { return hsl_[1]; } - template - inline T HSL::l() const { return hsl_[2]; } - template - inline T HSL::hsl(size_t i) const { - return hsl_[std::min((size_t)3 - 1, i)]; - } - template - inline T HSL::lsh(size_t i)const{return hsl(2-i);} - template - inline T HSL::h(T const& val){return (hsl_[0]=val);} - template - inline T HSL::s(T const& val){return (hsl_[1]=val);} - template - inline T HSL::l(T const& val){return (hsl_[2]=val);} - template - inline T HSL::hsl(size_t i, T const& val){ - return (hsl_[std::min((size_t)3 - 1, i)] = val); - } - template - inline T HSL::lsh(size_t i, T const& val){ - return hsl(2 - i, val); - } - - - - - - inline HSLf:: HSLf(): HSL(){ } - inline HSLf::~HSLf(){ } - inline HSLf::HSLf(double const&h,double const&s,double const&l):HSL(h,s,l){} - inline HSLf::HSLf(double const* hsl):HSL(hsl){} - inline double HSLf::hMin() const { return 0.0; } - inline double HSLf::hMax() const { return 2.0 * PI; } - inline double HSLf::sMin() const { return 0.0; } - inline double HSLf::sMax() const { return 1.0; } - inline double HSLf::lMin() const { return 0.0; } - inline double HSLf::lMax() const { return 1.0; } - - - - - template - inline void HSL_to_HSL(HSL const& a, HSL* b){ - double h = normalize(a.hMin(), a.hMax(), a.h()); - double s = normalize(a.sMin(), a.sMax(), a.s()); - double l = normalize(a.lMin(), a.lMax(), a.l()); - b->h(denormalize(b->hMin(), b->hMax(), h)); - b->s(denormalize(b->sMin(), b->sMax(), s)); - b->l(denormalize(b->lMin(), b->lMax(), l)); - } - template - inline void RGB_to_HSL(RGB const& rgb, HSL* hsl){ - double r = normalize(rgb.rMin(), rgb.rMax(), rgb.r()); - double g = normalize(rgb.gMin(), rgb.gMax(), rgb.g()); - double b = normalize(rgb.bMin(), rgb.bMax(), rgb.b()); - double mx = std::max(std::max(r, g), b); - double mn = std::min(std::min(r, g), b); - double h, s, l; - if (mx == mn ) h = 0; - else if(mx == r && g >= b) h = PI/3.0 * (g-b) / (mx-mn); - else if(mx == r && g < b) h = PI/3.0 * (g-b) / (mx-mn) + PI * 2.0; - else if(mx == g ) h = PI/3.0 * (b-r) / (mx-mn) + PI/3.0*2.0; - else h = PI/3.0 * (r-g) / (mx-mn) + PI/3.0*4.0; - l = 0.5 * (mx + mn); - if (l == 0 || mx == mn) s = 0; - else if(l < 0.5 ) s = (mx - mn) / (2.0 * l); - else s = (mx - mn) / (2 - 2.0 * l); - hsl->h(h); - hsl->s(s); - hsl->l(l); - } - template - inline void HSL_to_RGB(HSL const& hsl, RGB* rgb){ - double h = normalize(hsl.hMin(), hsl.hMax(), hsl.h()); - double s = normalize(hsl.sMin(), hsl.sMax(), hsl.s()); - double l = normalize(hsl.lMin(), hsl.lMax(), hsl.l()); - if(s == 0){ - rgb->r(denormalize(rgb->rMin(), rgb->rMax(), l)); - rgb->g(denormalize(rgb->gMin(), rgb->gMax(), l)); - rgb->b(denormalize(rgb->bMin(), rgb->bMax(), l)); - return ; - } - double q = (l < 0.5 ? (l * (1 + s)) : (l + s - (l * s))); - double p = 2 * l - q; - double t_r = h + 1.0 / 3.0; - double t_g = h; - double t_b = h - 1.0 / 3.0; - if(t_r < 0) t_r = t_r + 1.0; - if(t_r > 1) t_r = t_r - 1.0; - if(t_g < 0) t_g = t_g + 1.0; - if(t_g > 1) t_g = t_g - 1.0; - if(t_b < 0) t_b = t_b + 1.0; - if(t_b > 1) t_b = t_b - 1.0; - double r, g, b; - if (t_r < 1.0 / 6.0) r = p + (q - p) * 6 * t_r; - else if(t_r < 0.5 ) r = q; - else if(t_r < 2.0 / 3.0) r = p + (q - p) * 6 * (2.0 / 3.0 - t_r); - else r = p; - if (t_g < 1.0 / 6.0) g = p + (q - p) * 6 * t_g; - else if(t_g < 0.5 ) g = q; - else if(t_g < 2.0 / 3.0) g = p + (q - p) * 6 * (2.0 / 3.0 - t_g); - else g = p; - if (t_b < 1.0 / 6.0) b = p + (q - p) * 6 * t_b; - else if(t_b < 0.5 ) b = q; - else if(t_b < 2.0 / 3.0) b = p + (q - p) * 6 * (2.0 / 3.0 - t_b); - else b = p; - rgb->r(denormalize(rgb->rMin(), rgb->rMax(), r)); - rgb->g(denormalize(rgb->gMin(), rgb->gMax(), g)); - rgb->b(denormalize(rgb->bMin(), rgb->bMax(), b)); - } - template - inline void YUV_to_HSL(YUV const& yuv, HSL* hsl){ - RGBf tmp; - YUV_to_RGB(yuv, &tmp); - RGB_to_HSL(tmp, hsl); - } - template - inline void HSL_to_YUV(HSL const& hsl, YUV* yuv){ - RGBf tmp; - HSL_to_RGB(hsl, &tmp); - RGB_to_YUV(tmp, yuv); - } -} diff --git a/meowpp/colors/HSV.hpp b/meowpp/colors/HSV.hpp deleted file mode 100644 index 1838d0d..0000000 --- a/meowpp/colors/HSV.hpp +++ /dev/null @@ -1,144 +0,0 @@ -#include "HSV.h" - -#include "RGB.h" -#include "YUV.h" -#include "HSL.h" - -#include "../math/utility.h" - -#include - -#include - -namespace meow{ - template - inline HSV::HSV(){ } - template - inline HSV::HSV(T const& h, T const& s, T const& v){ - hsv_[0] = h; hsv_[1] = s; hsv_[2] = v; - } - template - inline HSV::HSV(T const* hsv){ - for(int i = 0; i < 3; i++) hsv_[i] = hsv[i]; - } - - template - inline T HSV::h() const { return hsv_[0]; } - template - inline T HSV::s() const { return hsv_[1]; } - template - inline T HSV::v() const { return hsv_[2]; } - template - inline T HSV::hsv(size_t i) const { - return hsv_[std::min((size_t)3 - 1, i)]; - } - template - inline T HSV::vsh(size_t i)const{return hsv(2-i);} - template - inline T HSV::h(T const& val){return (hsv_[0]=val);} - template - inline T HSV::s(T const& val){return (hsv_[1]=val);} - template - inline T HSV::v(T const& val){return (hsv_[2]=val);} - template - inline T HSV::hsv(size_t i, T const& val){ - return (hsv_[std::min((size_t)3 - 1, i)] = val); - } - template - inline T HSV::vsh(size_t i, T const& val){ - return hsv(2 - i, val); - } - - - - - - inline HSVf:: HSVf(): HSV(){ } - inline HSVf::~HSVf(){ } - inline HSVf::HSVf(double const&h,double const&s,double const&v):HSV(h,s,v){} - inline HSVf::HSVf(double const* hsv):HSV(hsv){} - inline double HSVf::hMin() const { return 0.0; } - inline double HSVf::hMax() const { return 2.0 * PI; } - inline double HSVf::sMin() const { return 0.0; } - inline double HSVf::sMax() const { return 1.0; } - inline double HSVf::vMin() const { return 0.0; } - inline double HSVf::vMax() const { return 1.0; } - - - - - template - inline void HSV_to_HSV(HSV const& a, HSV* b){ - double h = normalize(a.hMin(), a.hMax(), a.h()); - double s = normalize(a.sMin(), a.sMax(), a.s()); - double v = normalize(a.vMin(), a.vMax(), a.v()); - b->h(denormalize(b->hMin(), b->hMax(), h)); - b->s(denormalize(b->sMin(), b->sMax(), s)); - b->v(denormalize(b->vMin(), b->vMax(), v)); - } - template - inline void RGB_to_HSV(RGB const& rgb, HSV* hsv){ - double r = normalize(rgb.rMin(), rgb.rMax(), rgb.r()); - double g = normalize(rgb.gMin(), rgb.gMax(), rgb.g()); - double b = normalize(rgb.bMin(), rgb.bMax(), rgb.b()); - double mx = std::max(std::max(r, g), b); - double mn = std::min(std::min(r, g), b); - double h, s, v; - if (mx == mn ) h = 0; - else if(mx == r && g >= b) h = PI/3.0 * (g-b) / (mx-mn); - else if(mx == r && g < b) h = PI/3.0 * (g-b) / (mx-mn) + PI * 2.0; - else if(mx == g ) h = PI/3.0 * (b-r) / (mx-mn) + PI/3.0*2.0; - else h = PI/3.0 * (r-g) / (mx-mn) + PI/3.0*4.0; - if(mx == 0) s = 0; - else s = 1 - mn / mx; - v = mx; - hsv->h(h); - hsv->s(s); - hsv->v(v); - } - template - inline void HSV_to_RGB(HSV const& hsv, RGB* rgb){ - double h = normalize(hsv.hMin(), hsv.hMax(), hsv.h()) * 360; - double s = normalize(hsv.sMin(), hsv.sMax(), hsv.s()); - double v = normalize(hsv.vMin(), hsv.vMax(), hsv.v()); - int hi = (int)h / 60 % 6; - double f = h / 60.0 - hi; - double p = v * (1 - s); - double q = v * (1 - f * s); - double t = v * (1 - (1 - f) * s); - double r, g, b; - if (hi == 0){ r = v; g = t; b = p; } - else if(hi == 1){ r = q; g = v; b = p; } - else if(hi == 2){ r = p; g = v; b = t; } - else if(hi == 3){ r = p; g = q; b = v; } - else if(hi == 4){ r = t; g = p; b = v; } - else { r = v; g = p; b = q; } - rgb->r(denormalize(rgb->rMin(), rgb->rMax(), r)); - rgb->g(denormalize(rgb->gMin(), rgb->gMax(), g)); - rgb->b(denormalize(rgb->bMin(), rgb->bMax(), b)); - } - template - inline void YUV_to_HSV(YUV const& yuv, HSV* hsv){ - RGBf tmp; - YUV_to_RGB(yuv, &tmp); - RGB_to_HSV(tmp, hsv); - } - template - inline void HSV_to_YUV(HSV const& hsv, YUV* yuv){ - RGBf tmp; - HSV_to_RGB(hsv, &tmp); - RGB_to_YUV(tmp, yuv); - } - template - inline void HSL_to_HSV(HSL const& hsl, HSV* hsv){ - RGBf tmp; - HSL_to_RGB(hsl, &tmp); - RGB_to_HSV(tmp, hsv); - } - template - inline void HSV_to_HSL(HSV const& hsv, HSL* hsl){ - RGBf tmp; - HSV_to_RGB(hsv, &tmp); - RGB_to_HSL(tmp, hsl); - } -} diff --git a/meowpp/colors/RGB.hpp b/meowpp/colors/RGB.hpp deleted file mode 100644 index 0e0381d..0000000 --- a/meowpp/colors/RGB.hpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "RGB.h" - -#include - -#include - -#include "../math/utility.h" - -#include "../geo/Vector3D.h" -#include "../math/Matrix.h" - -namespace meow{ - template - inline RGB::RGB(){ } - template - inline RGB::RGB(T const& r, T const& g, T const& b){ - rgb_[0] = r; rgb_[1] = g; rgb_[2] = b; - } - template - inline RGB::RGB(T const* rgb){ - for(int i = 0; i < 3; i++){ - rgb_[i] = rgb[i]; - } - } - template - inline T RGB::r() const { return rgb_[0]; } - template - inline T RGB::g() const { return rgb_[1]; } - template - inline T RGB::b() const { return rgb_[2]; } - template - inline T RGB::rgb(size_t i) const { - return rgb_[std::min((size_t)3 - 1, i)]; - } - template - inline T RGB::bgr(size_t i) const { return rgb(2 - i); } - /////////////////// **# setting #** //////////////// - template - inline T RGB::r(T const& val){ return (rgb_[0] = val); } - template - inline T RGB::g(T const& val){ return (rgb_[1] = val); } - template - inline T RGB::b(T const& val){ return (rgb_[2] = val); } - template - inline T RGB::rgb(size_t i, T const& val){ - i = std::min((size_t)3 - 1, i); - return (rgb_[i] = val); - } - template - inline T RGB::bgr(size_t i, T const& val){ - return rgb(2 - i, val); - } - template - inline T RGB::rgb(T const& __r, T const& __g, T const& __b){ - r(__r); - g(__g); - b(__b); - } - template - inline T RGB::bgr(T const& __b, T const& __g, T const& __r){ - r(__r); - g(__g); - b(__b); - } - template - inline Matrix RGB::matrix() const{ - static Matrix ret(3, 1, T(0)); - ret(0, 0) = r(); - ret(1, 0) = g(); - ret(2, 0) = b(); - return ret; - } - template - inline Vector3D RGB::vector() const{ - static Vector3D ret; - ret(0) = r(); - ret(1) = g(); - ret(2) = b(); - return ret; - } - - - inline RGBf::RGBf(): RGB(0.0, 0.0, 0.0){ } - inline RGBf::~RGBf(){ } - inline RGBf::RGBf(double const&r,double const&g,double const&b):RGB(r,g,b){} - inline RGBf::RGBf(double const* rgb): RGB(rgb){ } - inline double RGBf::rMin() const { return 0.0; } - inline double RGBf::rMax() const { return 1.0; } - inline double RGBf::gMin() const { return 0.0; } - inline double RGBf::gMax() const { return 1.0; } - inline double RGBf::bMin() const { return 0.0; } - inline double RGBf::bMax() const { return 1.0; } - - - - - inline RGBi::RGBi (): RGB(0.0, 0.0, 0.0){ } - inline RGBi::~RGBi(){ } - inline RGBi::RGBi(int32_t const&r,int32_t const&g,int32_t const&b):RGB(r,g,b) - {} - inline RGBi::RGBi(int32_t const* rgb): RGB(rgb){ } - inline int32_t RGBi::rMin() const { return 0; } - inline int32_t RGBi::rMax() const { return 255; } - inline int32_t RGBi::gMin() const { return 0; } - inline int32_t RGBi::gMax() const { return 255; } - inline int32_t RGBi::bMin() const { return 0; } - inline int32_t RGBi::bMax() const { return 255; } - - - template - inline void RGB_to_RGB(RGB const& a, RGB* b){ - double r = normalize(a.rMin(), a.rMax(), a.r()); - double g = normalize(a.gMin(), a.gMax(), a.g()); - double x = normalize(a.bMin(), a.bMax(), a.b()); - b->r(denormalize(b->rMin(), b->rMax(), r)); - b->g(denormalize(b->gMin(), b->gMax(), g)); - b->b(denormalize(b->bMin(), b->bMax(), x)); - } -} diff --git a/meowpp/colors/YUV.hpp b/meowpp/colors/YUV.hpp deleted file mode 100644 index 9763d2c..0000000 --- a/meowpp/colors/YUV.hpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "YUV.h" - -#include "RGB.h" - -#include "../math/utility.h" - -#include - -#include - -namespace meow{ - template - inline YUV::YUV(){ } - template - inline YUV::YUV(T const& y, T const& u, T const& v){ - yuv_[0] = y; yuv_[1] = u; yuv_[2] = v; - } - template - inline YUV::YUV(T const* yuv){ - for(int i = 0; i < 3; i++){ - yuv_[i] = yuv[i]; - } - } - /////////////////// **# access #** ///////////////// - template - inline T YUV::y() const { return yuv_[0]; } - template - inline T YUV::u() const { return yuv_[1]; } - template - inline T YUV::v() const { return yuv_[2]; } - template - inline T YUV::yuv(size_t i) const { - return yuv_[std::min((size_t)3 - 1, i)]; - } - template - inline T YUV::vuy(size_t i) const {return yuv(2-i);} - /////////////////// **# setting #** //////////////// - template - inline T YUV::y(T const& val){return (yuv_[0]=val);} - template - inline T YUV::u(T const& val){return (yuv_[1]=val);} - template - inline T YUV::v(T const& val){return (yuv_[2]=val);} - template - inline T YUV::yuv(size_t i, T const& val){ - i = std::min((size_t)3 - 1, i); - return (yuv_[i] = val); - } - template - inline T YUV::vuy(size_t i, T const& val){ - return yuv(2 - i, val); - } - - inline YUVf:: YUVf(): YUV(0.0, 0.0, 0.0){ } - inline YUVf::~YUVf(){ } - inline YUVf::YUVf(double const& y, double const& u, double const& v): YUV(y, u, v){ } - inline YUVf::YUVf(double const* yuv): YUV(yuv){ } - inline double YUVf::yMin() const { return 0.0; } - inline double YUVf::yMax() const { return 1.0; } - inline double YUVf::uMin() const { return 0.0; } - inline double YUVf::uMax() const { return 1.0; } - inline double YUVf::vMin() const { return 0.0; } - inline double YUVf::vMax() const { return 1.0; } - - - template - inline void YUV_to_YUV(YUV const& a, YUV* b){ - double y = normalize(a.yMin(), a.yMax(), a.y()); - double u = normalize(a.uMin(), a.uMax(), a.u()); - double v = normalize(a.vMin(), a.vMax(), a.v()); - b->y(denormalize(b->yMin(), b->yMax(), y)); - b->u(denormalize(b->uMin(), b->uMax(), u)); - b->v(denormalize(b->vMin(), b->vMax(), v)); - } - template - inline void RGB_to_YUV(RGB const& rgb, YUV* yuv){ - double r = normalize(rgb.rMin(), rgb.rMax(), rgb.r()); - double g = normalize(rgb.gMin(), rgb.gMax(), rgb.g()); - double b = normalize(rgb.bMin(), rgb.bMax(), rgb.b()); - double y = 0.299 * r + 0.587 * g + 0.114 * b; - double u = -0.169 * r - 0.331 * g + 0.500 * b + 0.5; - double v = 0.500 * r - 0.419 * g - 0.081 * b + 0.5; - yuv->y(denormalize(yuv->yMin(), yuv->yMax(), y)); - yuv->u(denormalize(yuv->uMin(), yuv->uMax(), u)); - yuv->v(denormalize(yuv->vMin(), yuv->vMax(), v)); - } - template - inline void YUV_to_RGB(YUV const& yuv, RGB* rgb){ - double y = normalize(yuv.yMin(), yuv.yMax(), yuv.y()); - double u = normalize(yuv.uMin(), yuv.uMax(), yuv.u()); - double v = normalize(yuv.vMin(), yuv.vMax(), yuv.v()); - double r = y - 0.00093 * (u - 0.5) + 1.401687 * (v - 0.5); - double g = y - 0.34370 * (u - 0.5) - 0.714170 * (v - 0.5); - double b = y + 1.77216 * (u - 0.5) - 0.000990 * (v - 0.5); - rgb->r(denormalize(rgb->rMin(), rgb->rMax(), r)); - rgb->g(denormalize(rgb->gMin(), rgb->gMax(), g)); - rgb->b(denormalize(rgb->bMin(), rgb->bMax(), b)); - } -} - diff --git a/meowpp/dsa/BinaryIndexTree.hpp b/meowpp/dsa/BinaryIndexTree.hpp deleted file mode 100644 index f84a931..0000000 --- a/meowpp/dsa/BinaryIndexTree.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "BinaryIndexTree.h" - -#include - -#include -#include - - -namespace meow{ - template - inline - BinaryIndexTree::BinaryIndexTree(): - _array(0){ - } - template - inline - BinaryIndexTree::BinaryIndexTree(size_t __size, Value const& __value): - _array(__size, __value){ - } - template - inline - BinaryIndexTree::BinaryIndexTree(BinaryIndexTree const& __tree2): - _array(__tree2._array){ - } - // - template - inline void - BinaryIndexTree::reset(size_t __size, Value const& __init){ - _array.clear(); - _array.resize(__size, __init); - } - // - template - inline void - BinaryIndexTree::update(size_t __index, Value const& __value){ - __index++; - for( ; __index <= _array.size(); __index += (__index & -__index)){ - _array[__index - 1] = _array[__index - 1] + __value; - } - } - template - inline Value - BinaryIndexTree::query(ssize_t __index) const{ - __index = std::min(__index + 1, (ssize_t)_array.size()); - Value ret(0); - for( ; 0 < __index; __index -= (__index & -__index)){ - ret = ret + _array[__index - 1]; - } - return ret; - } -} diff --git a/meowpp/dsa/DisjointSet.hpp b/meowpp/dsa/DisjointSet.hpp deleted file mode 100644 index 98b2b98..0000000 --- a/meowpp/dsa/DisjointSet.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "DisjointSet.h" - - -#include -#include - -namespace meow{ - inline size_t DisjointSet::_root(size_t now){ - if(father[now] == now) return now; - return (father[now] = _root(father[now])); - } - inline size_t DisjointSet::_merge(size_t a, size_t b){ - a = _root(a); - b = _root(b); - if(a == b) return a; - if(depth[a] > depth[b]){ - father[b] = a; - return a; - }else{ - father[a] = b; - if(depth[a] == depth[b]){ - depth[b]++; - } - return b; - } - } - // - inline DisjointSet::DisjointSet(): n(0){ } - inline DisjointSet::DisjointSet(size_t _n): n(0){ - reset(_n); - } - inline DisjointSet::DisjointSet(DisjointSet const& dsj){ - n = dsj.n; - father = dsj.father; - depth = dsj.depth; - } - // - inline size_t DisjointSet::root(size_t a) const{ - return ((DisjointSet*)this)->_root(a); - } - inline size_t DisjointSet::size() const{ return n; } - // - inline void DisjointSet::reset(size_t _n){ - n = _n; - father.resize(n); - depth .resize(n); - for(size_t i = 0; i < n; i++){ - father[i] = i; - depth [i] = 1; - } - } - inline size_t DisjointSet::merge(size_t a, size_t b){ - return _merge(a, b); - } -} diff --git a/meowpp/dsa/KD_Tree.hpp b/meowpp/dsa/KD_Tree.hpp deleted file mode 100644 index 824b917..0000000 --- a/meowpp/dsa/KD_Tree.hpp +++ /dev/null @@ -1,272 +0,0 @@ -#include "KD_Tree.h" - - -#include "../utility.h" -#include "../math/utility.h" - -#include - -#include -#include -#include - -namespace meow{ - //////////////////////////////////////////////////////////////////// - // **# Node #** // - //////////////////////////////////////////////////////////////////// - template - inline - KD_Tree::Node::Node(Vector __vector, - ssize_t __lChild, ssize_t __rChild): - _vector(__vector), _lChild(__lChild), _rChild(__rChild){ - } - //////////////////////////////////////////////////////////////////// - // **# Sorter #** // - //////////////////////////////////////////////////////////////////// - template - inline - KD_Tree::Sorter::Sorter(Nodes const* __nodes, size_t __cmp): - _nodes(__nodes), _cmp(__cmp){ - } - template - inline bool - KD_Tree::Sorter::operator()(size_t const& __a, - size_t const& __b) const{ - if((*_nodes)[__a]._vector[_cmp] != (*_nodes)[__b]._vector[_cmp]){ - return ((*_nodes)[__a]._vector[_cmp] < (*_nodes)[__b]._vector[_cmp]); - } - return ((*_nodes)[__a]._vector < (*_nodes)[__b]._vector); - } - //////////////////////////////////////////////////////////////////// - // **# Answer / Answer's Compare class #** // - //////////////////////////////////////////////////////////////////// - template - inline - KD_Tree::Answer::Answer(ssize_t __index, Scalar __dist2): - _index(__index), _dist2(__dist2){ - } - template - inline - KD_Tree::Answer::Answer(Answer const& __answer2): - _index(__answer2._index), _dist2(__answer2._dist2){ - } - // - template - inline - KD_Tree::AnswerCompare::AnswerCompare(Nodes const* __nodes, - bool __cmpValue): - _nodes(__nodes), _cmpValue(__cmpValue){ - } - template - inline bool - KD_Tree::AnswerCompare::operator()(Answer const& __a, - Answer const& __b) const{ - if(_cmpValue == true && __a._dist2 == __b._dist2){ - return ((*_nodes)[__a._index]._vector < (*_nodes)[__b._index]._vector); - } - return (__a._dist2 < __b._dist2); - } - //////////////////////////////////////////////////////////////////// - // **# distance2() #** // - //////////////////////////////////////////////////////////////////// - template - inline Scalar - KD_Tree::distance2(Vector const& __v1, - Vector const& __v2) const{ - Scalar ret(0); - for(size_t i = 0; i < _dimension; i++){ - ret += squ(__v1[i] - __v2[i]); - } - return ret; - } - //////////////////////////////////////////////////////////////////// - // **# query() #** // - //////////////////////////////////////////////////////////////////// - template - inline void - KD_Tree::query(Vector const& __vector, - size_t __nearestNumber, - AnswerCompare const& __answerCompare, - ssize_t __index, - int __depth, - std::vector& __dist2Vector, - Scalar __dist2Minimum, - Answers* __out) const{ - if(__index == _NIL) return ; - size_t cmp = __depth % _dimension; - ssize_t this_side, that_side; - if(!(_nodes[__index]._vector[cmp] < __vector[cmp])){ - this_side = _nodes[__index]._lChild; - that_side = _nodes[__index]._rChild; - }else{ - this_side = _nodes[__index]._rChild; - that_side = _nodes[__index]._lChild; - } - query(__vector, __nearestNumber, __answerCompare, - this_side, __depth + 1, - __dist2Vector, __dist2Minimum, - __out); - Answer my_ans(__index, distance2(_nodes[__index]._vector, __vector)); - if(__out->size() < __nearestNumber || - __answerCompare(my_ans, __out->top())){ - __out->push(my_ans); - if(__out->size() > __nearestNumber) __out->pop(); - } - Scalar dist2_old = __dist2Vector[cmp]; - __dist2Vector[cmp] = squ(_nodes[__index]._vector[cmp] - __vector[cmp]); - Scalar dist2Minimum = __dist2Minimum + __dist2Vector[cmp] - dist2_old; - if(__out->size() < __nearestNumber || - !(__out->top()._dist2 < dist2Minimum)){ - query(__vector, __nearestNumber, __answerCompare, - that_side, __depth + 1, - __dist2Vector, dist2Minimum, - __out); - } - __dist2Vector[cmp] = dist2_old; - } - //////////////////////////////////////////////////////////////////// - // **# build() #** // - //////////////////////////////////////////////////////////////////// - template - inline ssize_t - KD_Tree::build(ssize_t __beg, - ssize_t __end, - std::vector* __orders, - int __depth){ - if(__beg > __end) return _NIL; - size_t tmp_order = _dimension; - size_t which_side = _dimension + 1; - ssize_t mid = (__beg + __end) / 2; - size_t cmp = __depth % _dimension; - for(ssize_t i = __beg; i <= mid; i++){ - __orders[which_side][__orders[cmp][i]] = 0; - } - for(ssize_t i = mid + 1; i <= __end; i++){ - __orders[which_side][__orders[cmp][i]] = 1; - } - for(size_t i = 0; i < _dimension; i++){ - if(i == cmp) continue; - size_t left = __beg, right = mid + 1; - for(int j = __beg; j <= __end; j++){ - size_t ask = __orders[i][j]; - if(ask == __orders[cmp][mid]){ - __orders[tmp_order][mid] = ask; - }else if(__orders[which_side][ask] == 1){ - __orders[tmp_order][right++] = ask; - }else{ - __orders[tmp_order][left++] = ask; - } - } - for(int j = __beg; j <= __end; j++){ - __orders[i][j] = __orders[tmp_order][j]; - } - } - _nodes[__orders[cmp][mid]]._lChild=build(__beg,mid-1,__orders,__depth+1); - _nodes[__orders[cmp][mid]]._rChild=build(mid+1,__end,__orders,__depth+1); - return __orders[cmp][mid]; - } - //////////////////////////////////////////////////////////////////// - // **# constructures/destructures #** // - //////////////////////////////////////////////////////////////////// - template - inline - KD_Tree::KD_Tree(): - _NIL(-1), _root(_NIL), _needRebuild(false), _dimension(1){ - } - template - inline - KD_Tree::KD_Tree(size_t __dimension): - _NIL(-1), _root(_NIL), _needRebuild(false), _dimension(__dimension){ - } - template - inline - KD_Tree::~KD_Tree(){ - } - //////////////////////////////////////////////////////////////////// - // **# insert, build #** // - //////////////////////////////////////////////////////////////////// - template - inline void - KD_Tree::insert(Vector const& __vector){ - _nodes.push_back(Node(__vector, _NIL, _NIL)); - _needRebuild = true; - } - template - inline bool - KD_Tree::erase(Vector const& __vector){ - for(size_t i = 0, I = _nodes.size(); i < I; i++){ - if(_nodes[i] == __vector){ - if(i != I - 1){ - std::swap(_nodes[i], _nodes[I - 1]); - } - _needRebuild = true; - return true; - } - } - return false; - } - template - inline void - KD_Tree::build(){ - if(_needRebuild){ - forceBuild(); - } - } - template - inline void - KD_Tree::forceBuild(){ - std::vector *orders = new std::vector[_dimension + 2]; - for(size_t j = 0; j < _dimension + 2; j++){ - orders[j].resize(_nodes.size()); - } - for(size_t j = 0; j < _dimension; j++){ - for(size_t i = 0, I = _nodes.size(); i < I; i++){ - orders[j][i] = i; - } - std::sort(orders[j].begin(), orders[j].end(), Sorter(&_nodes, j)); - } - _root = build(0, (ssize_t)_nodes.size() - 1, orders, 0); - delete [] orders; - _needRebuild = false; - } - //////////////////////////////////////////////////////////////////// - // **# query #** // - //////////////////////////////////////////////////////////////////// - template - inline typename KD_Tree::Vectors - KD_Tree::query(Vector const& __vector, - size_t __nearestNumber, - bool __compareWholeVector) const{ - ((KD_Tree*)this)->build(); - AnswerCompare answer_compare(&_nodes, __compareWholeVector); - Answers answer_set(answer_compare); - std::vector tmp(_dimension, 0); - query(__vector, __nearestNumber, - answer_compare, - _root, 0, - tmp, Scalar(0), - &answer_set); - Vectors ret(answer_set.size()); - for(int i = (ssize_t)answer_set.size() - 1; i >= 0; i--){ - ret[i] = _nodes[answer_set.top()._index]._vector; - answer_set.pop(); - } - return ret; - } - //////////////////////////////////////////////////////////////////// - // **# clear, reset #** // - //////////////////////////////////////////////////////////////////// - template - inline void - KD_Tree::clear(){ - _root = _NIL; - _nodes.clear(); - _needRebuild = false; - } - template - inline void - KD_Tree::reset(size_t __dimension){ - clear(); - _dimension = __dimension; - } -} diff --git a/meowpp/dsa/MergeableHeap.hpp b/meowpp/dsa/MergeableHeap.hpp deleted file mode 100644 index 1470ac3..0000000 --- a/meowpp/dsa/MergeableHeap.hpp +++ /dev/null @@ -1,127 +0,0 @@ -#include "MergeableHeap.h" - -#include - -#include - -namespace meow{ - ////////////////////////////////////////////////////////// - // **# MergeableHeap--Node-- constructor #** // - ////////////////////////////////////////////////////////// - template - inline MergeableHeap::Node::Node(Element const& _value): // Node - value(_value), l_child(NULL), r_child(NULL), weight(1){ } - - ////////////////////////////////////////////////////////// - // **# MergeableHeap -- clear, duplicate #** // - ////////////////////////////////////////////////////////// - template - inline void MergeableHeap::clear(Node* _node){ //clear - if(_node != NULL){ - clear(_node->l_child); - clear(_node->r_child); - delete _node; - } - } - template - inline typename MergeableHeap::Node* - MergeableHeap::dup(Node* _node2){ // dup - if(_node2 == NULL) return NULL; - Node* ret = new Node(_node2->value); - ret->l_child = dup(_node2->l_child); - ret->r_child = dup(_node2->r_child); - ret->weight = 1; - ret->weight += (ret->l_child == NULL ? 0 : ret->l_child->weight); - ret->weight += (ret->r_child == NULL ? 0 : ret->r_child->weight); - return ret; - } - - ////////////////////////////////////////////////////////// - // **# MergeableHeap -- merge #** // - ////////////////////////////////////////////////////////// - template - inline typename MergeableHeap::Node* - MergeableHeap::merge(Node* _left, Node* _right){ //merge - if(_left == NULL) return _right; - if(_right == NULL) return _left; - if(_left->value < _right->value){ - std::swap(_left, _right); - } - _left->r_child = merge(_left->r_child, _right); - size_t lw = (_left->l_child == NULL ? 0 : _left->l_child->weight); - size_t rw = (_left->r_child == NULL ? 0 : _left->r_child->weight); - if(lw < rw){ - std::swap(_left->l_child, _left->r_child); - } - _left->weight = 1 + lw + rw; - return _left; - } - - ////////////////////////////////////////////////////////// - // **# MergeableHeap -- constrctors/destructors #** // - ////////////////////////////////////////////////////////// - template - inline MergeableHeap::MergeableHeap(): //MergeableHeap - root(NULL){ } - template - inline MergeableHeap::MergeableHeap(MergeableHeap const& _heap2): - root(NULL){ root = dup(_heap2.root); } - template - inline MergeableHeap::~MergeableHeap(){ //~MergeableHeap - clear(root); - } - - ////////////////////////////////////////////////////////// - //**# MergeableHeap -- copy operation/data transform #**// - ////////////////////////////////////////////////////////// - template - inline MergeableHeap& - MergeableHeap::operator=(MergeableHeap const& _heap2){ // = - root = dup(_heap2.root); - return *this; - } - template - inline void MergeableHeap::moveTo(MergeableHeap* _heap2){ // moveTo - _heap2->clear(); - _heap2->root = root; - root = NULL; - } - ////////////////////////////////////////////////////////// - // **# MergeableHeap -- access: top, size, emtpy #** // - ////////////////////////////////////////////////////////// - template // top - inline Element const& MergeableHeap::top()const{return root->value;} - template // size - inline size_t MergeableHeap::size() const{ - return (root == NULL ? 0 : root->weight); - } - template // empty - inline bool MergeableHeap::empty() const{ return (size() == 0); } - ////////////////////////////////////////////////////////// - // **# MergeableHeap -- update: push, pop, merge #** // - ////////////////////////////////////////////////////////// - template - inline void MergeableHeap::push(Element const& _value){ // push - root = merge(root, new Node(_value)); - } - template - inline void MergeableHeap::pop(){ // pop - Node* l = root->l_child; - Node* r = root->r_child; - delete root; - root = merge(l, r); - } - template - inline void MergeableHeap::merge(MergeableHeap* _heap2){ // merge - root = merge(root, _heap2->root); - _heap2->root = NULL; - } - ////////////////////////////////////////////////////////// - // **# MergeableHeap -- refresh: clear #** // - ////////////////////////////////////////////////////////// - template - inline void MergeableHeap::clear(){ // clear - clear(root); - root = NULL; - } -} diff --git a/meowpp/dsa/SegmentTree.hpp b/meowpp/dsa/SegmentTree.hpp deleted file mode 100644 index 15ac0ef..0000000 --- a/meowpp/dsa/SegmentTree.hpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "SegmentTree.h" - - -#include "../math/utility.h" - -#include - -#include -#include - -namespace meow{ - - template - inline void - SegmentTree::update(size_t __i, size_t __size, Value const& __value, - bool __over){ - if(__over){ - _nodes[__i]._value = __value * __size; - _nodes[__i]._offset = __value; - _nodes[__i]._sameFlag = true; - }else{ - _nodes[__i]._value = _nodes[__i]._value + __value * __size; - _nodes[__i]._offset = _nodes[__i]._offset + __value; - } - } - template - inline void - SegmentTree::update(size_t __l, size_t __r, size_t __L, size_t __R, - size_t __i, Value const& __value, - bool __over){ - if(__l == __L && __r == __R){ - update(__i, __R - __L + 1, __value, __over); - return ; - } - size_t mid = (__L + __R) / 2; - if(__L < __R){ - update(__i*2+1, mid-__L+1, _nodes[__i]._offset, _nodes[__i]._sameFlag); - update(__i*2+2, __R - mid, _nodes[__i]._offset, _nodes[__i]._sameFlag); - _nodes[__i]._offset = Value(0); - _nodes[__i]._sameFlag = false; - } - if (__r <= mid) update(__l,__r, __L ,mid, __i*2+1, __value, __over); - else if(mid+1 <= __l) update(__l,__r, mid+1,__R, __i*2+2, __value, __over); - else{ - update(__l,mid , __L,mid , __i*2+1, __value, __over); - update( mid+1, __r, mid+1, __R, __i*2+2, __value, __over); - } - _nodes[__i]._value = ( - (_nodes[__i * 2 + 1]._value | _nodes[__i * 2 + 2]._value) - + _nodes[__i]._offset - ); - } - template - inline Value - SegmentTree::query(size_t __l, size_t __r, size_t __L, size_t __R, - size_t __i){ - if(__l == __L && __r == __R) return _nodes[__i]._value; - Value off = _nodes[__i]._offset * (__r - __l + 1); - if(_nodes[__i]._sameFlag) return off; - size_t mid = (__L + __R) / 2; - if (__r <= mid) return query(__l,__r, __L , mid, __i*2+1) + off; - else if(mid+1 <= __l) return query(__l,__r, mid+1, __R, __i*2+2) + off; - else{ - return ( query(__l, mid , __L, mid, __i*2+1) - | query( mid+1, __r, mid+1, __R, __i*2+2) - ) + off; - } - } - // - template - inline bool - SegmentTree::rangeCorrect(ssize_t* __first, ssize_t* __last) const{ - if(*__last<*__first || *__last<0 || (ssize_t)_size-1<*__first) return false; - *__first = inRange((ssize_t)0, (ssize_t)_size - 1, *__first); - *__last = inRange((ssize_t)0, (ssize_t)_size - 1, *__last ); - return true; - } - // - template - inline SegmentTree::SegmentTree(){ reset(1); } - template - inline SegmentTree::SegmentTree(size_t __size){ reset(__size); } - template - inline SegmentTree::SegmentTree(SegmentTree const& __tree2): - _size(__tree2._size), _nodes(__tree2._nodes){ } - // - template - inline void - SegmentTree::reset(size_t __size){ - _size = std::max(__size, (size_t)1); - _nodes.resize(__size * 4); - _nodes[0]._sameFlag = true; - _nodes[0]._value = Value(0); - _nodes[0]._offset = Value(0); - } - template - inline Value - SegmentTree::query(ssize_t __first, ssize_t __last) const{ - if(rangeCorrect(&__first, &__last) == false) return Value(); - return ((SegmentTree*)this)->query(__first, __last, 0, _size - 1, 0); - } - template - inline void - SegmentTree::override(ssize_t __first, ssize_t __last, - Value const& __value){ - if(rangeCorrect(&__first, &__last) == false) return ; - update(__first, __last, 0, _size - 1, 0, __value, true); - } - template - inline void - SegmentTree::offset(ssize_t __first, ssize_t __last, - Value const& __delta){ - if(rangeCorrect(&__first, &__last) == false) return ; - update(__first, __last, 0, _size - 1, 0, __delta, false); - } -} - diff --git a/meowpp/dsa/SplayTree.hpp b/meowpp/dsa/SplayTree.hpp deleted file mode 100644 index 3b08c14..0000000 --- a/meowpp/dsa/SplayTree.hpp +++ /dev/null @@ -1,437 +0,0 @@ -#include "SplayTree.h" - - -#include - -#include - -namespace meow{ - ///////////////////////////// **# Node #** ///////////////////////// - //////////////////// **# Node -- Constructure #** ////////////////// - template - inline - SplayTree::Node::Node(Key const& __key, Value const& __value): - _key(__key), _keyOffset(0), _value(__value){ - _size = 1; - _parent = NULL; - _child[0] = NULL; - _child[1] = NULL; - } - //////////////////////// **# Node -- Offset #** //////////////////// - template - inline void - SplayTree::Node::keyOffset(Key const& __delta){ - _key = _key + __delta; - _keyOffset = _keyOffset + __delta; - } - //////////////////////// **# Node -- sync #** ////////////////////// - template - inline void - SplayTree::Node::syncDown() const{ - for(size_t i = 0; i < 2; i++){ - if(_child[i] == NULL) continue; - _child[i]->keyOffset(_keyOffset); - } - ((Node*)this)->_keyOffset = Key(0); - } - template - inline void - SplayTree::Node::syncUp() const{ - ((Node*)this)->_size = 1; - for(size_t i = 0; i < 2; i++){ - if(_child[i] == NULL) continue; - ((Node*)this)->_size += _child[i]->_size; - } - } - ////////////////////////// **# SplayTree #** /////////////////////// - ///////////////////// **# connection, splay #** //////////////////// - template - inline void - SplayTree::connect(Node const* __parent, size_t __left_right, - Node const* __child) const{ - Node* parent = (Node*)__parent; - Node* child = (Node*)__child; - if(parent != NULL) parent->_child[__left_right] = child; - if(child != NULL) child ->_parent = parent; - } - template - inline typename SplayTree::Node const* - SplayTree::splay(Node const* __node) const{ - if(__node != NULL && __node->_parent != NULL){ - for(const Node *g_grand, *grand, *parent, *child = __node; ; ){ - g_grand = (grand = parent = child->_parent)->_parent; - size_t pc = (parent->_child[0] == child ? 0 : 1); - connect(parent, pc, child->_child[!pc]); - connect(child , !pc, parent); - if(g_grand != NULL){ - g_grand = (grand = g_grand)->_parent; - size_t gp = (grand->_child[0] == parent ? 0 : 1); - Node const* who = (pc == gp ? parent : child); - connect(grand, gp, who->_child[!gp]); - connect(who , !gp, grand); - grand->syncUp(); - } - parent->syncUp(); - child ->syncUp(); - if(g_grand == NULL){ - connect(NULL, 0, child); - break; - } - connect(g_grand, (g_grand->_child[0] == grand ? 0 : 1), child); - } - } - return (((SplayTree*)this)->_root = (Node*)__node); - } - ///////////////////////// **# clear, dup #** /////////////////////// - template - inline void - SplayTree::clear(Node* __node){ - if(__node == NULL) return ; - clear(__node->_child[0]); - clear(__node->_child[1]); - delete __node; - } - template - inline typename SplayTree::Node* - SplayTree::dup(Node* __node){ - if(__node == NULL) return NULL; - __node->syncDown(); - Node* node = new Node(__node->_key, __node->_value); - connect(node, 0, dup(__node->_child[0])); - connect(node, 1, dup(__node->_child[1])); - node->syncUp(); - return node; - } - /////////////////////////// **# find #** /////////////////////////// - template - inline typename SplayTree::Node const* - SplayTree::findKey(Node const* __node, Key const& __key) const{ - Node const* ret = __node; - while(__node != NULL){ - __node->syncDown(); - ret = __node; - if(!(__key < __node->_key)){ - if(!(__node->_key< __key)) break; - __node = __node->_child[1]; - }else{ - __node = __node->_child[0]; - } - } - return ret; - } - template - inline typename SplayTree::Node const* - SplayTree::findMinMax(Node const* __node, bool __minimum) const{ - Node const* ret = __node; - for(int i = __minimum ? 0 : 1; __node != NULL; __node = __node->_child[i]){ - __node->syncDown(); - ret = __node; - } - return ret; - } - template - inline typename SplayTree::Node const* - SplayTree::findOrder(Node const* __node, size_t __order) const{ - Node const* ret = __node; - while(__node != NULL){ - __node->syncDown(); - ret = __node; - size_t ord = 1 + (__node->_child[0]==NULL ? 0:__node->_child[0]->_size); - if (ord == __order) return ret; - else if(ord < __order){ __node = __node->_child[1]; __order -= ord; } - else { __node = __node->_child[0]; } - } - return ret; - } - /////////////////////// **# split, merge #** /////////////////////// - template - inline void - SplayTree::split(Node* __root, Node** __left, Node** __right){ - if(__root == NULL){ *__left = NULL; *__right = NULL; return ; } - __root->syncDown(); - *__left = __root; - *__right = __root->_child[1]; - if(*__right != NULL){ - (*__left )->_child[1] = NULL; - (*__right)->_parent = NULL; - (*__left )->syncUp(); - } - } - template - inline typename SplayTree::Node* - SplayTree::merge(Node* __left, Node* __right){ - if(__left == NULL) return __right; - if(__right == NULL) return __left ; - __left->syncDown(); - connect(__left, 1, __right); - __left->syncUp(); - return __left; - } - ///////////////////////// **# Element ##* ////////////////////////// - template - inline void SplayTree::Element::reset(Node* __node){ - _node = __node; - delete _entry; - if(__node == NULL) _entry = NULL; - else _entry = new Entry(__node->_key, __node->_value); - } - // - template - inline - SplayTree::Element::Element(): - _entry(NULL), _node(NULL){ - } - template - inline - SplayTree::Element::Element(Node* __node): - _entry(NULL), _node(NULL){ - reset(__node); - } - template - inline - SplayTree::Element::Element(Element const& __element2): - _entry(NULL), _node(NULL){ - reset(__element2._node); - } - template - inline - SplayTree::Element::~Element(){ - delete _entry; - } - template - inline typename SplayTree::Element& - SplayTree::Element::operator=(Element const& __e2){ - reset(__e2._node); - return *this; - } - //////////////////// **# Element operations #** //////////////////// - template - inline typename SplayTree::Element::Entry* - SplayTree::Element::operator->(){ return _entry; } - template - inline typename SplayTree::Element::Entry& - SplayTree::Element::operator*(){ return *_entry; } - // - template - inline bool - SplayTree::Element::operator==(Element const& __e2) const{ - return (_node == __e2._node); - } - template - inline bool - SplayTree::Element::operator!=(Element const& __e2) const{ - return (_node != __e2._node); - } - /////// **# Splay tree constructure/destructure/copy oper #** ////// - template - inline - SplayTree::SplayTree(): _root(NULL){ - } - template - inline - SplayTree::SplayTree(SplayTree const& __tree2): _root(NULL){ - _root = dup((Node*)(__tree2._root)); - } - template - inline - SplayTree::~SplayTree(){ - clear(_root); - } - template - inline SplayTree& - SplayTree::operator=(SplayTree const& __tree2){ - clear(_root); - _root = dup((Node*)(__tree2._root)); - return *this; - } - template - inline void - SplayTree::moveTo(SplayTree* __tree2){ - __tree2->clear(); - __tree2->_root = _root; - _root = NULL; - } - //////////////////////// **# Bounding #** ////////////////////////// - template - inline typename SplayTree::Element - SplayTree::lowerBound(Key const& __key) const{ - splay(findKey(_root, __key)); - if(_root == NULL || !(_root->_key < __key)) return Element(_root); - if(_root->_child[1] == NULL) return Element(NULL); - splay(findMinMax(_root->_child[1], true)); - return Element(_root); - } - template - inline typename SplayTree::Element - SplayTree::upperBound(Key const& __key) const{ - splay(findKey(_root, __key)); - if(_root == NULL || __key < _root->_key) return Element(_root); - if(_root->_child[1] == NULL) return Element(NULL); - splay(findMinMax(_root->_child[1], true)); - return Element(_root); - } - template - inline typename SplayTree::Element - SplayTree::rLowerBound(Key const& __key) const{ - splay(findKey(_root, __key)); - if(_root == NULL || !(__key < _root->_key)) return Element(_root); - if(_root->_child[0] == NULL) return Element(NULL); - splay(findMinMax(_root->_child[0], false)); - return Element(_root); - } - template - inline typename SplayTree::Element - SplayTree::rUpperBound(Key const& __key) const{ - splay(findKey(_root, __key)); - if(_root == NULL || _root->_key < __key) return Element(_root); - if(_root->_child[0] == NULL) return Element(NULL); - splay(findMinMax(_root->_child[0], false)); - return Element(_root); - } - ////////////// **# find / order / first / last / end #** //////////// - template - inline typename SplayTree::Element - SplayTree::find(Key const& __key) const{ - splay(findKey(_root, __key)); - if(_root != NULL && !(__key < _root->_key) && !(_root->_key < __key)){ - return Element(_root); - } - return Element(NULL); - } - template - inline typename SplayTree::Element - SplayTree::order(size_t __order) const{ - if(_root == NULL || __order >= _root->_size) return Element(NULL); - splay(findOrder(_root, __order + 1)); - return Element(_root); - } - template - inline typename SplayTree::Element - SplayTree::first() const{ - splay(findMinMax(_root, true)); - return Element(_root); - } - template - inline typename SplayTree::Element - SplayTree::last() const{ - splay(findMinMax(_root, false)); - return Element(_root); - } - template - inline typename SplayTree::Element - SplayTree::end() const{ return Element(NULL); } - //////////////////// **# size, empty, clear #** //////////////////// - template - inline size_t SplayTree::size() const{ - return (_root == NULL ? 0 : _root->_size); - } - template - inline bool SplayTree::empty() const{ - return (size() == 0); - } - // - template - inline void SplayTree::clear(){ - clear(_root); - _root = NULL; - } - ////////////// **# insert, erase, keyOffset, oper[] #** //////////// - template - inline bool SplayTree::insert(Key const& __key, - Value const& __value){ - if(_root == NULL){ - _root = new Node(__key, __value); - }else{ - Node* parent = (Node*)findKey(_root, __key); - if(!(parent->_key < __key) && !(__key < parent->_key)){ - splay(parent); - return false; - } - Node* new_node = new Node(__key, __value); - connect(parent, (parent->_key < __key ? 1 : 0), new_node); - parent->syncUp(); - splay(new_node); - } - return true; - } - template - inline bool SplayTree::erase(Key const& __key){ - if(_root == NULL) return false; - Node* body = (Node*)findKey(_root, __key); - if(body->_key < __key || __key < body->_key){ - splay(body); - return false; - } - Node* ghost; - if(body->_child[1] == NULL){ - ghost = body->_child[0]; - if(ghost != NULL) ghost->syncDown(); - }else{ - ghost = (Node*)findMinMax(body->_child[1], true); - connect(ghost, 0, body->_child[0]); - if(ghost != body->_child[1]){ - connect(ghost->_parent, 0, ghost->_child[1]); - connect(ghost, 1, body->_child[1]); - for(Node* a = ghost->_parent; a != ghost; a = a->_parent) - a->syncUp(); - } - ghost->syncUp(); - } - Node* parent = body->_parent; - connect(parent, parent != NULL && parent->_child[0] == body ? 0 : 1, - ghost); - delete body; - splay(ghost != NULL ? ghost : parent); - return true; - } - template - inline void SplayTree::keyOffset(Key const& __delta){ - if(_root != NULL){ - _root->keyOffset(__delta); - } - } - template - inline Value& - SplayTree::operator[](Key const& __key){ - if(find(__key) == end()) insert(__key, Value()); - return _root->_value; - } - /////////////////////// **# split, merge #** /////////////////////// - template - inline void - SplayTree::splitOut(Key const& __upper_bound, SplayTree* __right){ - __right->clear(); - if(rLowerBound(__upper_bound) != end()){ - split(_root, &_root, &(__right->_root)); - }else{ - __right->_root = _root; - _root = NULL; - } - } - template - inline bool - SplayTree::mergeAfter(SplayTree* __tree2){ - if(_root == NULL || __tree2->_root == NULL || - last()->first < __tree2->first()->first){ - _root = merge(_root, __tree2->_root); - __tree2->_root = NULL; - return true; - } - return false; - } - template - inline bool - SplayTree::merge(SplayTree* __tree2){ - if(_root == NULL || __tree2->_root == NULL || - last()->first < __tree2->first()->first){ - _root = merge(_root, __tree2->_root); - }else if(__tree2->last()->first < first()->first){ - _root = merge(__tree2->_root, _root); - }else{ - return false; - } - __tree2->_root = NULL; - return true; - } -} - diff --git a/meowpp/dsa/SplayTree_Range.hpp b/meowpp/dsa/SplayTree_Range.hpp deleted file mode 100644 index def7ef7..0000000 --- a/meowpp/dsa/SplayTree_Range.hpp +++ /dev/null @@ -1,506 +0,0 @@ -#include "SplayTree_Range.h" - - -#include - -#include - -#include "../math/utility.h" - -namespace meow{ - ///////////////////////////// **# Node #** ///////////////////////// - //////////////////// **# Node -- Constructure #** ////////////////// - template - inline - SplayTree_Range::Node::Node(Key const& __key, - Value const& __value): - _key(__key), _keyOffset(0), _value(__value), _valueOffset(0), _range(__value){ - _same = false; - _size = 1; - _parent = NULL; - _child[0] = NULL; - _child[1] = NULL; - } - ///////////////// **# Node -- Offset / Override #** //////////////// - template - inline void - SplayTree_Range::Node::keyOffset(Key const& __delta){ - _key = _key + __delta; - _keyOffset = _keyOffset + __delta; - } - template - inline void - SplayTree_Range::Node::valueUpdate(Value const& __delta, - bool __over){ - if(__over){ - _value = __delta * _size; - _valueOffset = __delta; - _range = __delta * _size; - _same = true; - }else{ - _value = _value + __delta * _size; - _valueOffset = _valueOffset + __delta; - _range = _range + __delta * _size; - } - } - //////////////////////// **# Node -- sync #** ////////////////////// - template - inline void - SplayTree_Range::Node::syncDown() const{ - for(size_t i = 0; i < 2; i++){ - if(_child[i] == NULL) continue; - _child[i]->keyOffset (_keyOffset); - _child[i]->valueUpdate(_valueOffset, _same); - } - ((Node*)this)->_keyOffset = Key(0); - ((Node*)this)->_valueOffset = Value(0); - ((Node*)this)->_same = false; - } - template - inline void - SplayTree_Range::Node::syncUp() const{ - ((Node*)this)->_size = 1; - Value* v[3] = {&(((Node*)this)->_value), NULL, NULL}; - size_t vct = 1; - for(size_t i = 0; i < 2; i++){ - if(_child[i] == NULL) continue; - ((Node*)this)->_size += _child[i]->_size; - v[vct++] = &(_child[i]->_range); - } - if (vct == 1) ((Node*)this)->_range = (*v[0]); - else if(vct == 2) ((Node*)this)->_range = (*v[0]) | (*v[1]); - else ((Node*)this)->_range = (*v[0]) | (*v[1]) | (*v[2]); - } - ////////////////////////// **# SplayTree_Range #** /////////////////////// - ///////////////////// **# connection, splay #** //////////////////// - template - inline void - SplayTree_Range::connect(Node const* __parent, - size_t __left_right, - Node const* __child) const{ - Node* parent = (Node*)__parent; - Node* child = (Node*)__child; - if(parent != NULL) parent->_child[__left_right] = child; - if(child != NULL) child ->_parent = parent; - } - template - inline typename SplayTree_Range::Node const* - SplayTree_Range::splay(Node const* __node) const{ - if(__node != NULL && __node->_parent != NULL){ - for(const Node *g_grand, *grand, *parent, *child = __node; ; ){ - g_grand = (grand = parent = child->_parent)->_parent; - size_t pc = (parent->_child[0] == child ? 0 : 1); - connect(parent, pc, child->_child[!pc]); - connect(child , !pc, parent); - if(g_grand != NULL){ - g_grand = (grand = g_grand)->_parent; - size_t gp = (grand->_child[0] == parent ? 0 : 1); - Node const* who = (pc == gp ? parent : child); - connect(grand, gp, who->_child[!gp]); - connect(who , !gp, grand); - grand->syncUp(); - } - parent->syncUp(); - child ->syncUp(); - if(g_grand == NULL){ - connect(NULL, 0, child); - break; - } - connect(g_grand, (g_grand->_child[0] == grand ? 0 : 1), child); - } - } - return (((SplayTree_Range*)this)->_root = (Node*)__node); - } - ///////////////////////// **# clear, dup #** /////////////////////// - template - inline void - SplayTree_Range::clear(Node* __node){ - if(__node == NULL) return ; - clear(__node->_child[0]); - clear(__node->_child[1]); - delete __node; - } - template - inline typename SplayTree_Range::Node* - SplayTree_Range::dup(Node* __node){ - if(__node == NULL) return NULL; - __node->syncDown(); - Node* node = new Node(__node->_key, __node->_value); - connect(node, 0, dup(__node->_child[0])); - connect(node, 1, dup(__node->_child[1])); - node->syncUp(); - return node; - } - /////////////////////////// **# find #** /////////////////////////// - template - inline typename SplayTree_Range::Node const* - SplayTree_Range::findKey(Node const* __node, - Key const& __key) const{ - Node const* ret = __node; - while(__node != NULL){ - __node->syncDown(); - ret = __node; - if(!(__key < __node->_key)){ - if(!(__node->_key< __key)) break; - __node = __node->_child[1]; - }else{ - __node = __node->_child[0]; - } - } - return ret; - } - template - inline typename SplayTree_Range::Node const* - SplayTree_Range::findMinMax(Node const* __node, - bool __minimum) const{ - Node const* ret = __node; - for(int i = __minimum ? 0 : 1; __node != NULL; __node = __node->_child[i]){ - __node->syncDown(); - ret = __node; - } - return ret; - } - template - inline typename SplayTree_Range::Node const* - SplayTree_Range::findOrder(Node const* __node, - size_t __order) const{ - Node const* ret = __node; - while(__node != NULL){ - __node->syncDown(); - ret = __node; - size_t ord = 1 + (__node->_child[0]==NULL ? 0:__node->_child[0]->_size); - if (ord == __order) return ret; - else if(ord < __order){ __node = __node->_child[1]; __order -= ord; } - else { __node = __node->_child[0]; } - } - return ret; - } - /////////////////////// **# split, merge #** /////////////////////// - template - inline void - SplayTree_Range::split(Node* __root, Node** __left, - Node** __right){ - if(__root == NULL){ *__left = NULL; *__right = NULL; return ; } - __root->syncDown(); - *__left = __root; - *__right = __root->_child[1]; - if(*__right != NULL){ - (*__left )->_child[1] = NULL; - (*__right)->_parent = NULL; - (*__left )->syncUp(); - } - } - template - inline typename SplayTree_Range::Node* - SplayTree_Range::merge(Node* __left, Node* __right){ - if(__left == NULL) return __right; - if(__right == NULL) return __left ; - __left->syncDown(); - connect(__left, 1, __right); - __left->syncUp(); - return __left; - } - ///////////////////////// **# Element ##* ////////////////////////// - template - inline void SplayTree_Range::Element::reset(Node* __node){ - _node = __node; - delete _entry; - if(__node == NULL) _entry = NULL; - else _entry = new Entry(__node->_key, __node->_value); - } - // - template - inline - SplayTree_Range::Element::Element(): - _entry(NULL), _node(NULL){ - } - template - inline - SplayTree_Range::Element::Element(Node* __node): - _entry(NULL), _node(NULL){ - reset(__node); - } - template - inline - SplayTree_Range::Element::Element(Element const& __element2): - _entry(NULL), _node(NULL){ - reset(__element2._node); - } - template - inline - SplayTree_Range::Element::~Element(){ - delete _entry; - } - template - inline typename SplayTree_Range::Element& - SplayTree_Range::Element::operator=(Element const& __e2){ - reset(__e2._node); - return *this; - } - //////////////////// **# Element operations #** //////////////////// - template - inline typename SplayTree_Range::Element::Entry* - SplayTree_Range::Element::operator->(){ return _entry; } - template - inline typename SplayTree_Range::Element::Entry& - SplayTree_Range::Element::operator*(){ return *_entry; } - // - template - inline bool - SplayTree_Range::Element::operator==(Element const& __e2) const{ - return (_node == __e2._node); - } - template - inline bool - SplayTree_Range::Element::operator!=(Element const& __e2) const{ - return (_node != __e2._node); - } - /////// **# Splay tree constructure/destructure/copy oper #** ////// - template - inline - SplayTree_Range::SplayTree_Range(): _root(NULL){ - } - template - inline - SplayTree_Range::SplayTree_Range(SplayTree_Range const& __tree2): - _root(NULL){ - _root = dup((Node*)(__tree2._root)); - } - template - inline - SplayTree_Range::~SplayTree_Range(){ - clear(_root); - } - template - inline SplayTree_Range& - SplayTree_Range::operator=(SplayTree_Range const& __tree2){ - clear(_root); - _root = dup((Node*)(__tree2._root)); - return *this; - } - template - inline void - SplayTree_Range::moveTo(SplayTree_Range* __tree2){ - __tree2->clear(); - __tree2->_root = _root; - _root = NULL; - } - //////////////////////// **# Bounding #** ////////////////////////// - template - inline typename SplayTree_Range::Element - SplayTree_Range::lowerBound(Key const& __key) const{ - splay(findKey(_root, __key)); - if(_root == NULL || !(_root->_key < __key)) return Element(_root); - if(_root->_child[1] == NULL) return Element(NULL); - splay(findMinMax(_root->_child[1], true)); - return Element(_root); - } - template - inline typename SplayTree_Range::Element - SplayTree_Range::upperBound(Key const& __key) const{ - splay(findKey(_root, __key)); - if(_root == NULL || __key < _root->_key) return Element(_root); - if(_root->_child[1] == NULL) return Element(NULL); - splay(findMinMax(_root->_child[1], true)); - return Element(_root); - } - template - inline typename SplayTree_Range::Element - SplayTree_Range::rLowerBound(Key const& __key) const{ - splay(findKey(_root, __key)); - if(_root == NULL || !(__key < _root->_key)) return Element(_root); - if(_root->_child[0] == NULL) return Element(NULL); - splay(findMinMax(_root->_child[0], false)); - return Element(_root); - } - template - inline typename SplayTree_Range::Element - SplayTree_Range::rUpperBound(Key const& __key) const{ - splay(findKey(_root, __key)); - if(_root == NULL || _root->_key < __key) return Element(_root); - if(_root->_child[0] == NULL) return Element(NULL); - splay(findMinMax(_root->_child[0], false)); - return Element(_root); - } - ////////////// **# find / order / first / last / end #** //////////// - template - inline typename SplayTree_Range::Element - SplayTree_Range::find(Key const& __key) const{ - splay(findKey(_root, __key)); - if(_root != NULL && !(__key < _root->_key) && !(_root->_key < __key)){ - return Element(_root); - } - return Element(NULL); - } - template - inline typename SplayTree_Range::Element - SplayTree_Range::order(size_t __order) const{ - if(_root == NULL || __order >= _root->_size) return Element(NULL); - splay(findOrder(_root, __order + 1)); - return Element(_root); - } - template - inline typename SplayTree_Range::Element - SplayTree_Range::first() const{ - splay(findMinMax(_root, true)); - return Element(_root); - } - template - inline typename SplayTree_Range::Element - SplayTree_Range::last() const{ - splay(findMinMax(_root, false)); - return Element(_root); - } - template - inline typename SplayTree_Range::Element - SplayTree_Range::end() const{ return Element(NULL); } - //////////////////// **# query, range query #** //////////////////// - template - inline Value - SplayTree_Range::query() const{ - if(_root == NULL) return Value(0); - return _root->_range; - } - template - inline Value - SplayTree_Range::query(Key const& __first, - Key const& __last) const{ - SplayTree_Range* self = (SplayTree_Range*)this; - Node* tmp; - rUpperBound(__first); - self->split(self->_root, &tmp, &(self->_root)); - upperBound(__last); - Value ret(0); - if(_root != NULL && _root->_child[0] != NULL){ - ret = _root->_child[0]->_range; - } - self->_root = self->merge(tmp, self->_root); - return ret; - } - //////////////////// **# size, empty, clear #** //////////////////// - template - inline size_t SplayTree_Range::size() const{ - return (_root == NULL ? 0 : _root->_size); - } - template - inline bool SplayTree_Range::empty() const{ - return (size() == 0); - } - // - template - inline void SplayTree_Range::clear(){ - clear(_root); - _root = NULL; - } - ////////////// **# insert, erase, keyOffset, oper[] #** //////////// - template - inline bool SplayTree_Range::insert(Key const& __key, - Value const& __value){ - if(_root == NULL){ - _root = new Node(__key, __value); - }else{ - Node* parent = (Node*)findKey(_root, __key); - if(!(parent->_key < __key) && !(__key < parent->_key)){ - splay(parent); - return false; - } - Node* new_node = new Node(__key, __value); - connect(parent, (parent->_key < __key ? 1 : 0), new_node); - parent->syncUp(); - splay(new_node); - } - return true; - } - template - inline bool SplayTree_Range::erase(Key const& __key){ - if(_root == NULL) return false; - Node* body = (Node*)findKey(_root, __key); - if(body->_key < __key || __key < body->_key){ - splay(body); - return false; - } - Node* ghost; - if(body->_child[1] == NULL){ - ghost = body->_child[0]; - if(ghost != NULL) ghost->syncDown(); - }else{ - ghost = (Node*)findMinMax(body->_child[1], true); - connect(ghost, 0, body->_child[0]); - if(ghost != body->_child[1]){ - connect(ghost->_parent, 0, ghost->_child[1]); - connect(ghost, 1, body->_child[1]); - for(Node* a = ghost->_parent; a != ghost; a = a->_parent) - a->syncUp(); - } - ghost->syncUp(); - } - Node* parent = body->_parent; - connect(parent, parent != NULL && parent->_child[0] == body ? 0 : 1, - ghost); - delete body; - splay(ghost != NULL ? ghost : parent); - return true; - } - template - inline void SplayTree_Range::keyOffset(Key const& __delta){ - if(_root != NULL){ - _root->keyOffset(__delta); - } - } - template - inline void SplayTree_Range::valueOffset(Value const& __delta){ - if(_root != NULL){ - _root->valueUpdate(__delta, false); - } - } - template - inline void SplayTree_Range::valueOverride(Value const& __value){ - if(_root != NULL){ - _root->valueUpdate(__value, true); - } - } - template - inline Value& - SplayTree_Range::operator[](Key const& __key){ - if(find(__key) == end()) insert(__key, Value()); - return _root->_value; - } - /////////////////////// **# split, merge #** /////////////////////// - template - inline void - SplayTree_Range::splitOut(Key const& __upper_bound, SplayTree_Range* __right){ - __right->clear(); - if(rLowerBound(__upper_bound) != end()){ - split(_root, &_root, &(__right->_root)); - }else{ - __right->_root = _root; - _root = NULL; - } - } - template - inline bool - SplayTree_Range::mergeAfter(SplayTree_Range* __tree2){ - if(_root == NULL || __tree2->_root == NULL || - last()->first < __tree2->first()->first){ - _root = merge(_root, __tree2->_root); - __tree2->_root = NULL; - return true; - } - return false; - } - template - inline bool - SplayTree_Range::merge(SplayTree_Range* __tree2){ - if(_root == NULL || __tree2->_root == NULL || - last()->first < __tree2->first()->first){ - _root = merge(_root, __tree2->_root); - }else if(__tree2->last()->first < first()->first){ - _root = merge(__tree2->_root, _root); - }else{ - return false; - } - __tree2->_root = NULL; - return true; - } -} - diff --git a/meowpp/dsa/VP_Tree.hpp b/meowpp/dsa/VP_Tree.hpp deleted file mode 100644 index bb6b5f1..0000000 --- a/meowpp/dsa/VP_Tree.hpp +++ /dev/null @@ -1,276 +0,0 @@ -#include "VP_Tree.h" - -#include - -#include -#include -#include "../math/utility.h" - -namespace meow{ - ///////////////////// **# Node #** /////////////////////// - template - inline - VP_Tree::Node::Node(size_t __index): - _index(__index), _nearChild(NULL), _farChild(NULL){ - } - ///////////////////// **# Answer #** ///////////////////// - template - inline - VP_Tree::Answer::Answer(size_t __index, - Scalar const& __dist2): - _index(__index), _dist2(__dist2){ - } - template - inline - VP_Tree::Answer::Answer(Answer const& __answer2): - _index(__answer2._index), _dist2(__answer2._dist2){ - } - template - inline - VP_Tree::AnswerCompare::AnswerCompare - (Vectors const* __vectors, bool __cmpValue): - _vectors(__vectors), _cmpValue(__cmpValue){ - } - template - inline bool - VP_Tree::AnswerCompare::operator()(Answer const& __a, - Answer const& __b) const{ - if(__a._dist2 < __b._dist2) return true; - if(__b._dist2 < __a._dist2) return false; - return (_cmpValue && ((*_vectors)[__a._index] < (*_vectors)[__b._index])); - } - //////// **# distance2, distanceCompare, split #** /////// - template - inline Scalar - VP_Tree::distance2(Vector const& __v1, - Vector const& __v2) const{ - Scalar ret(0); - for(size_t i = 0; i < _dimension; i++) ret += squ(__v1[i] - __v2[i]); - return ret; - } - template - inline int - VP_Tree::distanceCompare(Scalar const& __a2, - Scalar const& __b2, - Scalar const& __c2) const{ - // test if sqrt(__a2) +- sqrt(|__b2|) <= sqrt(__c2) - if(__b2 < 0){ - return -distanceCompare(__c2, -__b2, __a2); - } - Scalar cab(__c2 - __a2 - __b2); - if(cab < Scalar(0)) return 1; - Scalar ab2(Scalar(4) * __a2 * __b2), cab2(squ(cab)); - if ( ab2 < cab2) return -1; - else if(cab2 < ab2) return 1; - else return 0; - } - template - inline Scalar - VP_Tree::split(ssize_t __first, ssize_t __last, - size_t __order, Vector const& __center){ - ssize_t first0 = __first; - std::vector dist2(__last - __first + 1); - for(ssize_t i = __first; i <= __last; i++){ - dist2[i - first0] = distance2(_vectors[i], __center); - } - while(__first < __last){ - size_t threshold_index = __first + rand() % (__last - __first + 1); - Scalar threshold(dist2[threshold_index - first0]); - size_t large_first = __last + 1; - for(ssize_t i=__first; __first<=(ssize_t)large_first-1; large_first--){ - if(threshold < dist2[large_first - 1 - first0]) continue; - while(i < (ssize_t)large_first-1&&!(threshold < dist2[i-first0])) i++; - if(i < (ssize_t)large_first - 1){ - std::swap(dist2 [large_first - 1 - first0], dist2 [i - first0]); - std::swap(_vectors[large_first - 1 ], _vectors[i ]); - i++; - }else{ - break; - } - } - if(large_first == (size_t)__last + 1){ - std::swap(dist2 [threshold_index-first0], dist2 [__last-first0]); - std::swap(_vectors[threshold_index ], _vectors[__last ]); - if((ssize_t)__order == __last - __first){ - __first = __last; - break; - } - __last--; - }else{ - if(__order < large_first - __first){ - __last = large_first - 1; - }else{ - __order -= large_first - __first; - __first = large_first; - } - } - } - return dist2[__first - first0]; - } - ////////////////////// **# build() #** /////////////////// - template - inline typename VP_Tree::Node* - VP_Tree::build(ssize_t __first, ssize_t __last){ - if(__first > __last) return NULL; - Node* ret = new Node(__first); - if(__first < __last){ - std::swap(_vectors[__first], - _vectors[__first + rand() % (__last - __first + 1)]); - ssize_t mid = (__first + 1 + __last + 1) / 2; - ret->_threshold = split(__first + 1, __last, mid - (__first + 1), - _vectors[__first]); - ret->_nearChild = build(__first + 1, mid - 1 ); - ret->_farChild = build( mid , __last); - } - return ret; - } - ////////////////////// **# query() #** /////////////////// - template - inline void - VP_Tree::query(Vector const& __vector, - size_t __k, - AnswerCompare const& __cmp, - Node const* __node, - Answers* __out) const{ - if(__node == NULL) return ; - Scalar dist2 = distance2(__vector, _vectors[__node->_index]); - Answer my_ans(__node->_index, dist2); - if(__out->size() < __k || __cmp(my_ans, __out->top())){ - __out->push(my_ans); - if(__out->size() > __k){ - __out->pop(); - } - } - if(__node->_nearChild == NULL && __node->_farChild == NULL) return ; - if(__out->size() < __k || distanceCompare(dist2, -__out->top()._dist2, - __node->_threshold) <= 0){ - query(__vector, __k, __cmp, __node->_nearChild, __out); - } - if(__out->size() < __k || distanceCompare(dist2, __out->top()._dist2, - __node->_threshold) >= 0){ - query(__vector, __k, __cmp, __node->_farChild, __out); - } - } - ///////////////// **# clear(), dup() #** ///////////////// - template - inline void - VP_Tree::clear(Node* __root){ - if(__root == NULL) return ; - clear(__root->_nearChild); - clear(__root->_farChild); - delete __root; - } - template - inline typename VP_Tree::Node* - VP_Tree::dup(Node* __root){ - if(__root == NULL) return ; - Node* ret = new Node(__root->_index); - ret->_threshold = __root->_threshold; - ret->_nearChild = dup(__root->_nearChild); - ret->_farChild = dup(__root->_farChild ); - return ret; - } - ///////// **# construre/destructure/copy oper #** //////// - template - inline - VP_Tree::VP_Tree(): - _root(NULL), _vectors(0), _dimension(0), _needRebuild(false){ - reset(0); - } - template - inline - VP_Tree::VP_Tree(VP_Tree const& __tree2): - _vectors(__tree2._vectors), - _root(dup(__tree2._root)), - _dimension(__tree2._dimension), - _needRebuild(__tree2._needRebuild){ - } - template - inline - VP_Tree::VP_Tree(size_t __dimension): - _vectors(0), - _root(NULL), - _dimension(0), - _needRebuild(false){ - reset(__dimension); - } - template - inline - VP_Tree::~VP_Tree(){ - clear(_root); - } - template - inline VP_Tree& - VP_Tree::operator=(VP_Tree const& __tree2){ - reset(__tree2._dimension); - _vectors = __tree2._vectors; - _root = dup(__tree2._root); - _needRebuild = __tree2._needRebuild; - } - ////////////////// **# insert, erase #** ///////////////// - template - inline void - VP_Tree::insert(Vector const& __vector){ - _vectors.push_back(__vector); - _needRebuild = true; - } - template - inline bool - VP_Tree::erase(Vector const& __vector){ - for(ssize_t i = 0, I = _vectors.size(); i < I; i++){ - if(_vectors[i] == __vector){ - if(i != I - 1) std::swap(_vectors[i], _vectors[I - 1]); - _needRebuild = true; - _vectors.pop_back(); - return true; - } - } - return false; - } - ////////////////// **# build, forceBuild #** ///////////// - template - inline void - VP_Tree::build(){ - if(_needRebuild){ - forceBuild(); - } - } - template - inline void - VP_Tree::forceBuild(){ - _root = build(0, (size_t)_vectors.size() - 1); - _needRebuild = false; - } - ////////////////////// **# query #** ///////////////////// - template - inline typename VP_Tree::Vectors - VP_Tree::query(Vector const& __vector, - size_t __nearestNumber, - bool __compareWholeVector) const{ - ((VP_Tree*)this)->build(); - AnswerCompare cmp(&_vectors, __compareWholeVector); - Answers answers(cmp); - query(__vector, __nearestNumber, cmp, _root, &answers); - std::stack rev; - for( ; !answers.empty(); answers.pop()) rev.push(answers.top()); - Vectors ret; - for( ; !rev.empty(); rev.pop()) ret.push_back(_vectors[rev.top()._index]); - return ret; - } - /////////////////// **# clear, reset #** ///////////////// - template - void - VP_Tree::clear(){ - clear(_root); - _vectors.clear(); - _root = NULL; - _needRebuild = false; - } - template - size_t - VP_Tree::reset(size_t __dimension){ - clear(); - _dimension = std::max((size_t)1, __dimension); - return _dimension; - } -}; diff --git a/meowpp/geo/Vector2D.hpp b/meowpp/geo/Vector2D.hpp deleted file mode 100644 index e1d0f41..0000000 --- a/meowpp/geo/Vector2D.hpp +++ /dev/null @@ -1,327 +0,0 @@ -#include "Vector2D.h" - -#include "../math/utility.h" -#include "../math/Matrix.h" - -#include - -namespace meow{ - template - inline - Vector2D::Vector2D(): - _x(0), - _y(0){ - } - - - template - inline - Vector2D::Vector2D(Vector2D const& __v): - _x(__v._x), - _y(__v._y){ - } - - - template - inline - Vector2D::Vector2D(Scalar const& __x, Scalar const& __y): - _x(__x), - _y(__y){ - } - - - template - inline - Vector2D::~Vector2D(){ - } - - - template - inline Vector2D& - Vector2D::copy(Vector2D const& __v){ - _x = __v.x(); - _y = __v.y(); - return *this; - } - - template - inline Scalar const& - Vector2D::x() const{ - return _x; - } - - - template - inline Scalar const& - Vector2D::y() const{ - return _y; - } - - - template - inline Scalar const& - Vector2D::x(Scalar const& __s){ - _x = __s; - return x(); - } - - - template - inline Scalar const& - Vector2D::y(Scalar const& __s){ - _y = __s; - return y(); - } - - - template - inline Vector2D& - Vector2D::xy(Scalar const& __x, Scalar const& __y){ - _x = __x; - _y = __y; - return *this; - } - - - template - inline Vector2D - Vector2D::positive() const{ - return *this; - } - - - template - inline Vector2D - Vector2D::negative() const{ - return Vector2D(-x(), -y()); - } - - - template - inline Vector2D - Vector2D::right() const{ - return Vector2D(-y(), x()); - } - - - template - inline Vector2D - Vector2D::add(Vector2D const& __v) const{ - return Vector2D(x() + __v.x(), y() + __v.y()); - } - - - template - inline Vector2D - Vector2D::sub(Vector2D const& __v) const{ - return Vector2D(x() - __v.x(), y() - __v.y()); - } - - - template - inline Vector2D - Vector2D::mul(Scalar const& __s) const{ - return Vector2D(x() * __s, y() * __s); - } - - - template - inline Vector2D - Vector2D::div(Scalar const& __s) const{ - return Vector2D(x() / __s, y() / __s); - } - - - template - inline Scalar - Vector2D::dot(Vector2D const& __v) const{ - return (x() * __v.x() + y() * __v.y()); - } - - - template - inline Scalar - Vector2D::cross(Vector2D const& __v) const{ - return (x() * __v.y() - y() * __v.x()); - } - - - template - inline Scalar - Vector2D::length() const{ - return Scalar(sqrt(double(length2()))); - } - - - template - inline Scalar - Vector2D::length2() const{ - return squ(x()) + squ(y()); - } - - - template - inline Vector2D& - Vector2D::normalize(){ - return copy(normalized()); - } - - - template - inline Vector2D - Vector2D::normalized() const{ - return div(length()); - } - - template - inline Vector2D& - Vector2D::rotate(Scalar const& __theta){ - return copy(rotated(__theta)); - } - - - template - inline Vector2D - Vector2D::rotated(Scalar const& __theta) const{ - Scalar cs(cos(-double(__theta))); - Scalar sn(sin(-double(__theta))); - Vector2D new_x(cs, sn); - return Vector2D(new_x.dot(*this), new_x.cross(*this)); - } - - - template - inline Vector2D& - Vector2D::reflect(Vector2D const& __v){ - return copy(reflected(__v)); - } - - - template - inline Vector2D - Vector2D::reflected(Vector2D const& __v) const{ - return __v.mul(__v.dot(*this) * 2 / __v.length2()).sub(*this); - } - - - template - inline Matrix - Vector2D::matrix() const{ - Matrix ret(2, 0, Scalar(0)); - ret(0, 0) = x(); - ret(1, 0) = y(); - return ret; - } - - - template - inline Matrix - Vector2D::matrix(Scalar const& __homo) const{ - Matrix ret(3, 0, Scalar(0)); - ret(0, 0) = x(); - ret(1, 0) = y(); - ret(2, 0) = __homo; - return ret; - } - - - template - inline Scalar const& - Vector2D::operator()(size_t n) const{ - return (n == 0 ? x() : y()); - } - - - template - inline Scalar& - Vector2D::operator()(size_t n){ - return (n == 0 ? _x : _y); - } - - - template - inline Vector2D& - Vector2D::operator()(Scalar const& __x, Scalar const& __y){ - x(__x); - y(__y); - return *this; - } - - - template - inline Vector2D - Vector2D::operator+() const{ - return positive(); - } - - - template - inline Vector2D - Vector2D::operator-() const{ - return negative(); - } - - - template - inline Vector2D - Vector2D::operator~() const{ - return right(); - } - - - template - inline Vector2D - Vector2D::operator+(Vector2D const& __v) const{ - return add(__v); - } - - - template - inline Vector2D - Vector2D::operator-(Vector2D const& __v) const{ - return sub(__v); - } - - - template - inline Vector2D - Vector2D::operator*(Scalar const& __s) const{ - return mul(__s); - } - - - template - inline Vector2D - Vector2D::operator/(Scalar const& __s) const{ - return div(__s); - } - - - template - inline Vector2D& - Vector2D::operator+=(Vector2D const& __v){ - return copy(add(__v)); - } - - - template - inline Vector2D& - Vector2D::operator-=(Vector2D const& __v){ - return copy(sub(__v)); - } - - - template - inline Vector2D& - Vector2D::operator*=(Scalar const& __s){ - return copy(mul(__s)); - } - - - template - inline Vector2D& - Vector2D::operator/=(Scalar const& __s){ - return copy(div(__s)); - } -} - diff --git a/meowpp/geo/Vector3D.hpp b/meowpp/geo/Vector3D.hpp deleted file mode 100644 index e46b1f2..0000000 --- a/meowpp/geo/Vector3D.hpp +++ /dev/null @@ -1,359 +0,0 @@ -#include "Vector3D.h" - -#include "../math/utility.h" -#include "../math/Matrix.h" - -#include - -namespace meow{ - template - inline - Vector3D::Vector3D(): - _x(0), - _y(0), - _z(0){ - } - - - template - inline - Vector3D::Vector3D(Vector3D const& __v): - _x(__v._x), - _y(__v._y), - _z(__v._z){ - } - - - template - inline - Vector3D::Vector3D(Scalar const& __x, - Scalar const& __y, - Scalar const& __z): - _x(__x), - _y(__y), - _z(__z){ - } - - - template - inline - Vector3D::~Vector3D(){ - } - - - template - inline Vector3D& - Vector3D::copy(Vector3D const& __v){ - _x = __v.x(); - _y = __v.y(); - _z = __v.z(); - return *this; - } - - template - inline Scalar const& - Vector3D::x() const{ - return _x; - } - - - template - inline Scalar const& - Vector3D::y() const{ - return _y; - } - - - template - inline Scalar const& - Vector3D::z() const{ - return _z; - } - - - template - inline Scalar const& - Vector3D::x(Scalar const& __s){ - _x = __s; - return x(); - } - - - template - inline Scalar const& - Vector3D::y(Scalar const& __s){ - _y = __s; - return y(); - } - - - template - inline Scalar const& - Vector3D::z(Scalar const& __s){ - _z = __s; - return z(); - } - - - template - inline Vector3D& - Vector3D::xyz(Scalar const& __x, - Scalar const& __y, - Scalar const& __z){ - _x = __x; - _y = __y; - _z = __z; - return *this; - } - - - template - inline Vector3D - Vector3D::positive() const{ - return *this; - } - - - template - inline Vector3D - Vector3D::negative() const{ - return Vector3D(-x(), -y(), -z()); - } - - - template - inline Vector3D - Vector3D::right() const{ - return Vector3D(-y(), x()); - } - - - template - inline Vector3D - Vector3D::add(Vector3D const& __v) const{ - return Vector3D(x() + __v.x(), y() + __v.y(), z() + __v.z()); - } - - - template - inline Vector3D - Vector3D::sub(Vector3D const& __v) const{ - return Vector3D(x() - __v.x(), y() - __v.y(), z() - __v.z()); - } - - - template - inline Vector3D - Vector3D::mul(Scalar const& __s) const{ - return Vector3D(x() * __s, y() * __s, z() * __s); - } - - - template - inline Vector3D - Vector3D::div(Scalar const& __s) const{ - return Vector3D(x() / __s, y() / __s, z() / __s); - } - - - template - inline Scalar - Vector3D::dot(Vector3D const& __v) const{ - return (x() * __v.x() + y() * __v.y() + z() * __v.z()); - } - - - template - inline Vector3D - Vector3D::cross(Vector3D const& __v) const{ - return Vector3D(y() * __v.z() - z() * __v.y(), - z() * __v.x() - x() * __v.z(), - x() * __v.y() - y() * __v.x()); - } - - - template - inline Scalar - Vector3D::length() const{ - return Scalar(sqrt(double(length2()))); - } - - - template - inline Scalar - Vector3D::length2() const{ - return squ(x()) + squ(y()) + squ(z()); - } - - - template - inline Vector3D& - Vector3D::normalize(){ - return copy(normalized()); - } - - - template - inline Vector3D - Vector3D::normalized() const{ - return div(length()); - } - - template - inline Vector3D& - Vector3D::rotate(Vector3D const& __axis, Scalar const& __theta){ - return copy(rotated(__axis, __theta)); - } - - - template - inline Vector3D - Vector3D::rotated(Vector3D const& __axis, - Scalar const& __theta) const{ - Vector3D axis(__axis.normalized()); - Vector3D h(axis.mul(axis.dot(*this))); - Vector3D xx(sub(axis) .mul(cos(double(__theta)))); - Vector3D yy(axis.cross(*this).mul(sin(double(__theta)))); - return h.add(xx).add(yy); - } - - - template - inline Vector3D& - Vector3D::reflect(Vector3D const& __v){ - return copy(reflected(__v)); - } - - - template - inline Vector3D - Vector3D::reflected(Vector3D const& __v) const{ - return __v.mul(__v.dot(*this) * 3 / __v.length2()).sub(*this); - } - - - template - inline Matrix - Vector3D::matrix() const{ - Matrix ret(3, 0, Scalar(0)); - ret(0, 0) = x(); - ret(1, 0) = y(); - ret(2, 0) = z(); - return ret; - } - - - template - inline Matrix - Vector3D::matrix(Scalar const& __homo) const{ - Matrix ret(4, 0, Scalar(0)); - ret(0, 0) = x(); - ret(1, 0) = y(); - ret(2, 0) = z(); - ret(3, 0) = __homo; - return ret; - } - - - template - inline Scalar const& - Vector3D::operator()(size_t n) const{ - return (n == 0 ? x() : (n == 1 ? y() : z())); - } - - - template - inline Scalar& - Vector3D::operator()(size_t n){ - return (n == 0 ? _x : (n == 1 ? _y : _z)); - } - - - template - inline Vector3D& - Vector3D::operator()(Scalar const& __x, - Scalar const& __y, - Scalar const& __z){ - x(__x); - y(__y); - z(__z); - return *this; - } - - - template - inline Vector3D - Vector3D::operator+() const{ - return positive(); - } - - - template - inline Vector3D - Vector3D::operator-() const{ - return negative(); - } - - - template - inline Vector3D - Vector3D::operator~() const{ - return right(); - } - - - template - inline Vector3D - Vector3D::operator+(Vector3D const& __v) const{ - return add(__v); - } - - - template - inline Vector3D - Vector3D::operator-(Vector3D const& __v) const{ - return sub(__v); - } - - - template - inline Vector3D - Vector3D::operator*(Scalar const& __s) const{ - return mul(__s); - } - - - template - inline Vector3D - Vector3D::operator/(Scalar const& __s) const{ - return div(__s); - } - - - template - inline Vector3D& - Vector3D::operator+=(Vector3D const& __v){ - return copy(add(__v)); - } - - - template - inline Vector3D& - Vector3D::operator-=(Vector3D const& __v){ - return copy(sub(__v)); - } - - - template - inline Vector3D& - Vector3D::operator*=(Scalar const& __s){ - return copy(mul(__s)); - } - - - template - inline Vector3D& - Vector3D::operator/=(Scalar const& __s){ - return copy(div(__s)); - } -} diff --git a/meowpp/math/LinearTransformations.hpp b/meowpp/math/LinearTransformations.hpp deleted file mode 100644 index fcb5b8a..0000000 --- a/meowpp/math/LinearTransformations.hpp +++ /dev/null @@ -1,148 +0,0 @@ -#include "LinearTransformations.h" - - -#include "utility.h" - -#include -#include - -namespace meow{ - template - inline void - Rotation3D::calcMatrix(){ - Scalar sum(0.0); - for(size_t i = 0; i < 3u; i++){ - sum = sum + squ(_theta(i, 0)); - } - Scalar t(sqrt(double(sum))); - std::vector u(3); - for(size_t i = 0; i < 3u; i++){ - u[i] = _theta[i] / t; - } - Scalar cs(cos(double(t))); - Scalar sn(sin(double(t))); - - _matrix.entry(0, 0, cs + squ(u[0]) * ((1 - cs))); - _matrix.entry(1, 1, cs + squ(u[1]) * ((1 - cs))); - _matrix.entry(2, 2, cs + squ(u[2]) * ((1 - cs))); - _matrix.entry(0, 1, u[0] * u[1] * (1 - cs) - u[2] * sn); - _matrix.entry(1, 0, u[1] * u[0] * (1 - cs) + u[2] * sn); - _matrix.entry(0, 2, u[0] * u[2] * (1 - cs) + u[1] * sn); - _matrix.entry(2, 0, u[2] * u[0] * (1 - cs) - u[1] * sn); - _matrix.entry(1, 2, u[1] * u[2] * (1 - cs) - u[0] * sn); - _matrix.entry(2, 1, u[2] * u[1] * (1 - cs) + u[0] * sn); - } - - - template - inline - Rotation3D::Rotation3D(): - LinearTransformation(3u, 3u, 3u){ - _theta[0] = _theta[1] = _theta[2] = Scalar(0); - _matrix.identitied(); - } - - - template - inline void - Rotation3D::axisTheta(Matrix const& __axis, - Scalar const& __theta){ - Scalar sum(0.0); - for(size_t i = 0; i < 3u; i++) - sum = sum + squ(__axis(i, 0)); - Scalar t(sqrt(double(sum))); - for(size_t i = 0; i < 3u; i++) - _theta[i] = __axis(i, 0) * __theta / t; - calcMatrix(); - } - - - template - inline Scalar - Rotation3D::parameter(size_t __i) const{ - return _theta[__i]; - } - - - template - inline Scalar - Rotation3D::parameter(size_t __i, Scalar const& __s) const{ - _theta[__i] = __s; - calcMatrix(); - return _theta[__i]; - } - - - template - inline Matrix - Rotation3D::transformate(Matrix const& __x) const{ - return _matrix * __x; - } - - - template - inline Matrix - Rotation3D::jacobian(Matrix const& __x) const{ - return _matrix; - } - - - template - inline Matrix - Rotation3D::jacobian(Matrix const& __x, - size_t __i) const{ - Matrix mid(3u, 3u, Scalar(0.0)); - if(__i == 0){ - mid.entry(1, 2, Scalar(-1.0)); - mid.entry(2, 1, Scalar( 1.0)); - }else if(__i == 1){ - mid.entry(0, 2, Scalar( 1.0)); - mid.entry(2, 0, Scalar(-1.0)); - }else{ - mid.entry(0, 1, Scalar(-1.0)); - mid.entry(1, 0, Scalar( 1.0)); - } - return _matrix * mid * __x; - } - - - template - inline Matrix - Rotation3D::invTransformate(Matrix const& __x) const{ - return _matrix.transpose() * __x; - } - - - template - inline Matrix - Rotation3D::invJacobian(Matrix const& __x) const{ - return _matrix.transpose(); - } - - - template - inline Matrix - Rotation3D::invJacobian(Matrix const& __x, - size_t __i) const{ - Matrix mid(3u, 3u, Scalar(0.0)); - if(__i == 0){ - mid.entry(1, 2, Scalar(-1.0)); - mid.entry(2, 1, Scalar( 1.0)); - }else if(__i == 1){ - mid.entry(0, 2, Scalar( 1.0)); - mid.entry(2, 0, Scalar(-1.0)); - }else{ - mid.entry(0, 1, Scalar(-1.0)); - mid.entry(1, 0, Scalar( 1.0)); - } - return _matrix.transpose() * mid.transpose() * __x; - } - - - template - inline Matrix - Rotation3D::invMatrix() const{ - return _matrix.transpose(); - } -} - diff --git a/meowpp/math/Matrix.hpp b/meowpp/math/Matrix.hpp deleted file mode 100644 index 8de3057..0000000 --- a/meowpp/math/Matrix.hpp +++ /dev/null @@ -1,329 +0,0 @@ -#include "Matrix.h" - -#include - -namespace meow{ - template - inline size_t - Matrix::index(size_t __r, size_t __c) const{ - return __r * _cols + __c; - } - - - template - inline - Matrix::Matrix(): - _rows(0), - _cols(0), - _entries(0){ - } - - - template - inline - Matrix::Matrix(Matrix const& __m): - _rows(__m._rows), - _cols(__m._cols), - _entries(__m._entries){ - } - - - template - inline - Matrix::Matrix(size_t __rows, size_t __cols, Entry const& __entry): - _rows(__rows), - _cols(__cols), - _entries(__rows * __cols, __entry){ - } - - - template - inline - Matrix::~Matrix(){ - } - - template - inline Matrix& - Matrix::copy(Matrix const& __m){ - _rows = __m._rows; - _cols = __m._cols; - _entries = __m._entries; - } - - - template - inline bool - Matrix::valid() const{ - return (rows() > 0 && cols() > 0); - } - - template - inline size_t - Matrix::rows() const{ - return _rows; - } - template - inline size_t - Matrix::cols() const{ - return _cols; - } - - - template - inline size_t - Matrix::size(size_t __rows, size_t __cols){ - if(__rows != rows() || __cols != cols()){ - if(__cols == cols()){ - _entries.resize(_rows * (_cols = __cols)); - }else{ - Matrix new_matrix(*this); - size_t R = std::min(rows(), __rows); - size_t C = std::min(cols(), __cols); - for(size_t r = 0; r < R; r++) - for(size_t c = 0; c < C; c++) - new_matrix.entry(r, c, entry(r, c)); - copy(new_matrix); - } - } - return rows() * cols(); - } - - - template - inline Entry const& - Matrix::entry(size_t __i, size_t __j) const{ - return _entries[index(__i, __j)]; - } - - - template - inline Entry const& - Matrix::entry(size_t __i, size_t __j, Entry const& __entry){ - _entries[index(__i, __j)] = __entry; - return entry(__i, __j); - } - - - template - inline void - Matrix::entries(size_t __rFirst, size_t __rLast, - size_t __cFirst, size_t __cLast, - Entry const& __entry){ - for(size_t r = __rFirst; r <= __rLast; r++) - for(size_t c = __cFirst; c <= __cLast; c++) - entry(r, c, __entry); - } - template - inline Matrix - Matrix::subMatrix(size_t __rFirst, size_t __rLast, - size_t __cFirst, size_t __cLast) const{ - if(__rFirst > __rLast || __cFirst > __cLast) - return Matrix(); - Matrix ret(__rLast - __rFirst + 1, __cLast - __cFirst + 1); - for(size_t r = __rFirst; r <= __rLast; r++) - for(size_t c = __cFirst; c <= __cLast; c++) - ret.entry(r - __rFirst, c - __cFirst, entry(r, c)); - return ret; - } - - - template - inline Matrix - Matrix::row(size_t __row) const{ - return subMatrix(__row, __row, 0, cols() - 1); - } - - - template - inline Matrix - Matrix::col(size_t __col) const{ - return subMatrix(0, rows() - 1, __col, __col); - } - - - template - inline Matrix - Matrix::positive() const{ - return *this; - } - - - template - inline Matrix - Matrix::negative() const{ - Matrix ret(*this); - for(size_t r = 0, R = rows(); r < R; r++) - for(size_t c = 0, C = cols(); c < C; c++) - ret.entry(r, c, -ret.entry(r, c)); - return ret; - } - - - template - inline Matrix - Matrix::add(Matrix const& __m) const{ - if(rows() != __m.rows() || _cols != __m.cols()) - return Matrix(); - Matrix ret(*this); - for(size_t r = 0, R = rows(); r < R; r++) - for(size_t c = 0, C = cols(); c < C; c++) - ret.entry(r, c, ret.entry(r, c) + __m.entry(r, c)); - return ret; - } - - - template - inline Matrix - Matrix::sub(Matrix const& __m) const{ - if(rows() != __m.rows() || _cols != __m.cols()) - return Matrix(); - Matrix ret(*this); - for(size_t r = 0, R = rows(); r < R; r++) - for(size_t c = 0, C = cols(); c < C; c++) - ret.entry(r, c, ret.entry(r, c) - __m.entry(r, c)); - return ret; - } - - - template - inline Matrix - Matrix::mul(Matrix const& __m) const{ - if(cols() != __m.rows()) - return Matrix(); - Matrix ret(rows(), __m.cols(), Entry(0)); - for(size_t r = 0, R = rows(); r < R; r++) - for(size_t c = 0, C = __m.cols(); c < C; c++) - for(size_t k = 0, K = cols(); k < K; k++) - ret.entry(r, c, ret.entry(r, c) + entry(r, k) * __m.entry(k, c)); - return ret; - } - - - template - inline Matrix - Matrix::mul(Entry const& __s) const{ - Matrix ret(*this); - for(size_t r = 0, R = rows(); r < R; r++) - for(size_t c = 0, C = cols(); c < C; c++) - ret.entry(r, c, ret.entry(r, c) * __s); - return ret; - } - - - template - inline Matrix - Matrix::div(Entry const& __s) const{ - Matrix ret(*this); - for(size_t r = 0, R = rows(); r < R; r++) - for(size_t c = 0, C = cols(); c < C; c++) - ret.entry(r, c, ret.entry(r, c) / __s); - return ret; - } - - - template - inline Matrix - Matrix::identity() const{ - Matrix ret(rows(), cols(), Entry(0)); - for(size_t rc = 0, RC = std::min(rows(), cols()); rc < RC; rc++) - ret.entry(rc, rc, Entry(1)); - return ret; - } - - - template - inline Matrix& - Matrix::identitied(){ - copy(identity()); - return (*this); - } - - - template - inline Matrix - Matrix::transpose() const{ - Matrix ret(cols(), rows(), Entry(0)); - for(size_t r = 0, R = cols(); r < R; r++) - for(size_t c = 0, C = rows(); c < C; c++) - ret.entry(r, c, entry(c, r)); - return ret; - } - - - template - inline Matrix& - Matrix::transposed(){ - copy(transpose()); - return (*this); - } - - - template - inline Matrix& - Matrix::operator=(Matrix const& __m){ - return copy(__m); - } - - - template - inline Entry const& - Matrix::operator()(size_t __i, size_t __j) const{ - return entry(__i, __j); - } - - - template - inline Entry& - Matrix::operator()(size_t __i, size_t __j){ - return _entries[index(__i, __j)]; - } - - - template - inline Matrix - Matrix::operator+() const{ - return positive(); - } - - - template - inline Matrix - Matrix::operator-() const{ - return negative(); - } - - - template - inline Matrix - Matrix::operator+(Matrix const& __m) const{ - return add(__m); - } - - - template - inline Matrix - Matrix::operator-(Matrix const& __m) const{ - return sub(__m); - } - - - template - inline Matrix - Matrix::operator*(Matrix const& __m) const{ - return mul(__m); - } - - - template - inline Matrix - Matrix::operator*(Entry const& __s) const{ - return mul(__s); - } - - - template - inline Matrix - Matrix::operator/(Entry const& __s) const{ - return div(__s); - } -} diff --git a/meowpp/math/Transformations.hpp b/meowpp/math/Transformations.hpp deleted file mode 100644 index 645b1a8..0000000 --- a/meowpp/math/Transformations.hpp +++ /dev/null @@ -1,193 +0,0 @@ -#include "Transformations.h" -#include "utility.h" - -#include - -namespace meow{ - template - inline - BallProjection::BallProjection(size_t __dimension): - Transformation(__dimension, 1, __dimension, 1, 1), - _dimension(__dimension), - _radius(1){ - } - - - template - inline - BallProjection::BallProjection(size_t __dimension, - Scalar const& __radius): - Transformation(__dimension, 1, __dimension, 1, 1), - _dimension(__dimension), - _radius(1){ - radius(__radius); - } - - - template - inline Scalar - BallProjection::parameter(size_t __i) const{ - return radius(); - } - - - template - inline Scalar - BallProjection::parameter(size_t __i, Scalar const& __s){ - return radius(__s); - } - - - template - inline Scalar - BallProjection::radius() const{ - return _radius; - } - - - template - inline Scalar - BallProjection::radius(Scalar const& __radius){ - _radius = __radius; - return radius(); - } - - - template - inline Matrix - BallProjection::transformate(Matrix const& __x) const{ - Matrix ret(__x); - for(size_t c = 0, C = ret.cols(); c < C; c++){ - Scalar sum(0); - for(size_t i = 0; i < _dimension; i++){ - sum = sum + squ(ret(i, c)); - } - Scalar len(sqrt(double(sum))); - for(size_t i = 0; i < _dimension; i++){ - ret(i, c) = ret(i, c) * radius() / len; - } - } - return ret; - } - - - template - inline Matrix - BallProjection::jacobian(Matrix const& __x) const{ - Scalar sum(0); - for(size_t i = 0; i < _dimension; i++) - sum = sum + squ(__x(i, 0)); - Scalar len(sqrt(double(sum))); - Matrix ret(_dimension, _dimension, Scalar(0.0)); - for(size_t i = 0; i < _dimension; i++) - for(size_t j = 0; j < _dimension; j++) - ret(i, j) = ((i == j) - ? 1.0 / len - squ(__x(i, 0)) / cub(len) * radius() - : - __x(i, 0) * __x(j, 0) / cub(len) * radius() - ); - return ret; - } - - - template - inline Matrix - BallProjection::jacobian(Matrix const& __x, - size_t __i) const{ - Matrix ret(_dimension, 1, Scalar(0.0)); - Scalar sum(0); - for(size_t i = 0; i < _dimension; i++){ - sum = sum + squ(__x(i, 0)); - } - Scalar len(sqrt(double(sum))); - for(size_t i = 0; i < _dimension; i++){ - ret(i, 0) = ret(i, 0) / len; - } - return ret; - } - - - template - inline - PhotoProjection::PhotoProjection(size_t __dimension): - Transformation(__dimension, 1, __dimension, 1, 0), - _dimension(__dimension), - _focal(1){ - } - - - template - inline - PhotoProjection::PhotoProjection(size_t __dimension, - Scalar const& __focal): - Transformation(__dimension, 1, __dimension, 1, 0), - _dimension(__dimension), - _focal(1){ - focal(__focal); - } - - - template - inline Scalar - PhotoProjection::parameter(size_t __i) const{ - return focal(); - } - - - template - inline Scalar - PhotoProjection::parameter(size_t __i, Scalar const& __s){ - return focal(__s); - } - - - template - inline Scalar - PhotoProjection::focal() const{ - return _focal; - } - - - template - inline Scalar - PhotoProjection::focal(Scalar const& __focal){ - _focal = __focal; - return focal(); - } - - - template - inline Matrix - PhotoProjection::transformate(Matrix const& __x) const{ - Matrix ret(__x); - for(size_t c = 0, C = ret.cols(); c < C; c++){ - for(size_t i = 0; i < _dimension; i++){ - ret(i, c) = ret(i, c) * _focal / ret(_dimension - 1, c); - } - } - return ret; - } - - - template - inline Matrix - PhotoProjection::jacobian(Matrix const& __x) const{ - Matrix ret(_dimension, _dimension, Scalar(0.0)); - for(ssize_t i = 0, I = (ssize_t)_dimension - 1; i < I; i++){ - ret(i, i) = _focal / __x(_dimension - 1, 0) ; - ret(i, _dimension - 1) = -_focal / squ(__x(_dimension - 1, 0)); - } - return ret; - } - - - template - inline Matrix - PhotoProjection::jacobian(Matrix const& __x, - size_t __i) const{ - Matrix ret(__dimension, 1, Scalar(0.0)); - for(size_t i = 0; i < _dimension; i++){ - ret(i, 0) = ret(i, 0) / ret(_dimension - 1, 0); - } - return ret; - } -} diff --git a/meowpp/math/utility.hpp b/meowpp/math/utility.hpp deleted file mode 100644 index 90cbdce..0000000 --- a/meowpp/math/utility.hpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "utility.h" - -#include - -#include - -namespace meow{ - - template - inline T noEPS(T value, T eps){ - T epsp((eps < T(0)) ? -eps : eps); - return ((value < -epsp || value > epsp) - ? value - : T(0)); - } - - template - inline T normalize(T lower, T upper, T value){ - return (value - lower) / (upper - lower); - } - - template - inline T denormalize(T lower, T upper, T _ratio){ - return lower + _ratio * (upper - lower); - } - - template - inline T ratioMapping(T l1, T u1, T m1, T l2, T u2){ - return denormalize(l2, u2, normalize(l1, u1, m1)); - } - - template - inline T inRange(T const& mn, T const& mx, T const& v){ - return std::min(mx, std::max(mn, v)); - } - - - template - inline T squ(T const& x){ - return x * x; - } - - - template - inline T cub(T const& x){ - return x * x * x; - } - - - template - 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 - 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; - } -} diff --git a/meowpp/oo/ObjPort.hpp b/meowpp/oo/ObjPort.hpp deleted file mode 100644 index d458adf..0000000 --- a/meowpp/oo/ObjPort.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "ObjPort.h" - -#include "ObjSelector.h" -#include "ObjBase.h" - -#include - -namespace meow{ - template - inline ObjPort::ObjBase* read(FILE* __f, bool __binary){ - char name[1024]; - unsigned int fg; - if(__binary){ - size_t len; - if(fread(&len, sizeof(size_t), 1, __f) < 1) return NULL; - if(fread(name, sizeof(char), len, __f) < len) return NULL; - if(fread(&fg, sizeof(unsigned int), 1, __f) < 1) return NULL; - name[len] = '\0'; - }else{ - fscanf(__f, "%s %u", name, &fg); - } - ObjBase* ret = Selector(name); - if(ret->read(__f, __binary, fg) == false){ - delete ret; - ret = NULL; - } - return ret; - } - - - template - inline ObjPort::bool write(FILE* __f, bool __binary, - ObjBase* __obj, unsigned int __fg){ - std::string name = Selector::find(__obj); - if(__binary){ - size_t len = name.size(); - if(fwrite(&len, sizeof(size_t), 1, __f) < 1) return false; - if(fwrite(name.c_str(), sizeof(char), len, __f) < len) return false; - if(fwrite(&__fg, sizeof(unsigned int), 1, __f) < len) return false; - }else{ - if(fprintf(__f, "%s %u\n", name.c_str(), __fg) < 2) return false; - } - return __obj->write(__f, __binary, __fg); - } -} - -#endif // oo_ObjPort_H__ diff --git a/meowpp/oo/Properties.hpp b/meowpp/oo/Properties.hpp deleted file mode 100644 index 58be1b4..0000000 --- a/meowpp/oo/Properties.hpp +++ /dev/null @@ -1,175 +0,0 @@ -#include "Properties.h" - -#include "ObjBase.h" - -#include -#include - - -namespace meow{ - inline Properties::Property::Property(ObjBase* __pointer, bool __autoRemove): - _pointer(__pointer), - _counter(__autoRemove ? -1 : 1){ - } - inline Properties::Property::Property(Property const& __property): - _pointer(__property._pointer), - _counter(__property._counter){ - } - inline Properties::Property::~Property(){ - } - inline bool Properties::Property::attach(){ - if(_pointer == NULL || _counter <= 0) return false; - _counter++; - return true; - } - inline bool Properties::Property::detach(){ - if(_pointer == NULL || _counter <= 0) return false; - _counter--; - if(_counter <= 0){ - delete _pointer; - _pointer = NULL; - } - return true; - } - //////////////////////////////////////////////////////////////////// - inline size_t Properties::newIndex(std::string const& __name){ - size_t i; - if(_freeIndex.size() > 0){ - i = _freeIndex.front(); - _freeIndex.pop(); - }else{ - i = size(); - } - _index[__name] = i; - return i; - } - inline void Properties::delIndex(size_t __index){ - _properties.erase(__index); - for(std::map::iterator it = _index.begin(); - it != _index.end(); - it++){ - if(it->second == __index){ - _index.erase(it); - break; - } - } - _freeIndex.push(__index); - } - inline void Properties::detach(size_t __index){ - _properties[__index]->detach(); - if(_properties[__index]->_counter == 0){ - delete _properties[__index]; - } - _properties[__index] = NULL; - } - inline Properties::Properties(){ - } - inline Properties::Properties(Properties const& __p){ - copy(__p); - } - inline Properties::~Properties(){ - clear(); - } - inline void Properties::clear(){ - for(std::map::iterator it = _properties.begin(); - it != _properties.end(); - it++){ - it->second->detach(); - } - _properties.clear(); - _index .clear(); - while(!_freeIndex.empty()) - _freeIndex.pop(); - } - inline Properties& Properties::copy(Properties const& __p){ - clear(); - _properties = ((Properties&)__p)._properties; - _index = ((Properties&)__p)._index; - _freeIndex = ((Properties&)__p)._freeIndex; - for(std::map::iterator it = _properties.begin(); - it != _properties.end(); - it++){ - it->second->attach(); - } - return *this; - } - inline size_t Properties::size() const{ - return (_properties.size()); - } - inline bool Properties::empty() const{ - return (size() == 0u); - } - inline bool Properties::chg(size_t __index, - ObjBase* __pointer, - bool __autoRemove){ - if(get(__index) == NULL) - return false; - detach(__index); - _properties[__index] = new Property(__pointer, __autoRemove); - return true; - } - inline bool Properties::add(std::string __name , - ObjBase* __pointer, - bool __autoRemove){ - if(get(__name) != NULL) - del(__name); - _properties[newIndex(__name)] = new Property(__pointer, __autoRemove); - return true; - } - inline bool Properties::del(size_t __index){ - if(get(__index) == NULL){ - return false; - } - detach(__index); - delIndex(__index); - return true; - } - inline bool Properties::del(std::string __name){ - if(get(__name) == NULL){ - return false; - } - return del(_index[__name]); - } - inline ObjBase* Properties::get(size_t __index) const{ - std::map::const_iterator i = _properties.find(__index); - if(i == _properties.end()) return NULL; - return (ObjBase*)(i->second->_pointer); - } - inline ObjBase* Properties::get(std::string __name) const{ - std::map::const_iterator i = _index.find(__name); - if(i == _index.end()) return NULL; - return get(i->second); - } - inline ssize_t Properties::getIndex(ObjBase* __pointer) const{ - for(std::map::const_iterator it = _properties.begin(); - it != _properties.end(); - it++){ - if(it->second->_pointer == __pointer){ - return it->first; - } - } - return -1; - } - inline std::string Properties::getName(ObjBase* __pointer) const{ - ssize_t t = getIndex(__pointer); - if(t < 0) return std::string(); - for(std::map::const_iterator it = _index.begin(); - it != _index.end(); - it++){ - if(it->second == (size_t)t){ - if(it == _index.end()) return std::string(); - return it->first; - } - } - return std::string(); - } - inline Properties& Properties::operator=(Properties const& __p){ - return copy(__p); - } - inline ObjBase* Properties::operator()(size_t __index) const{ - return get(__index); - } - inline ObjBase* Properties::operator()(std::string __name) const{ - return get(__name); - } -}; diff --git a/meowpp/utility.hpp b/meowpp/utility.hpp deleted file mode 100644 index 141de41..0000000 --- a/meowpp/utility.hpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "utility.h" - - -#include -#include -#include -#include - -#include -#include - -namespace meow{ - - inline std::string stringPrintf(char const * fmt, ...){ - char str[8192]; - va_list args; - va_start(args, fmt); - vsnprintf(str, 8192, fmt, args); - va_end(args); - return std::string(str); - } - - - inline std::string stringReplace(std::string str, - std::string const& from, - std::string const& to){ - std::string out = str; - int len = from.length(); - for(size_t pos; (pos = out.find(from)) != std::string::npos; ){ - out.replace(pos, len, to); - } - return out; - } - - - inline bool cstringEndWith(char const* str, int n, ...){ - int len = strlen(str); - va_list args; - va_start(args, n); - for(int i = 0; i < n; i++){ - char const* arg = va_arg(args, char const*); - int arglen = strlen(arg); - if(arglen <= len && strcmp(str + len - arglen, arg) == 0){ - return true; - } - } - va_end(args); - return false; - } - - - inline void debugPrintf_(char const* file, - char const* func, - size_t line, - char const* msg){ -#ifdef DEBUG - fprintf(stderr, "%s[%d] %s >> %s", file, line, func, msg); -#endif // DEBUG - } - - - inline void messagePrintf(int level_change, char const* fmt, ...){ - static int level = 0; - static int last_level = -5; - char str[8192]; - va_list args; - va_start(args, fmt); - vsnprintf(str, 8192, fmt, args); - va_end(args); - if(last_level == 1 && level_change == -1){ - printf(" ...%s\n", str); - }else{ - if(last_level == 1) printf("\n"); - int level2 = level + (level_change == -1 ? -1 : 0); - for(int i = 0; i < level2; i++) printf("| "); - printf("%s%s", (level_change == -1 ? "..." : ""), str); - if(level_change != 1) printf("\n"); - } - level += level_change; - last_level = level_change; - fflush(stdout); - } - - inline bool filenameCompare(std::string const& f1, std::string const& f2){ - char const* s1 = f1.c_str(); - char const* s2 = f2.c_str(); - int l1 = f1.length(); - int l2 = f2.length(); - int i1, i2; - for(i1 = i2 = 0; i1 < l1 || i2 < l2; i1++, i2++){ - if(isdigit(s1[i1]) && isdigit(s2[i2])){ - int n1 = atoi(s1 + i1); - int n2 = atoi(s2 + i2); - if(n1 != n2){ - return (n1 < n2); - } - while(i1 + 1 < l1 && isdigit(s1[i1 + 1])) i1++; - while(i2 + 1 < l2 && isdigit(s2[i2 + 1])) i2++; - }else{ - if(s1[i1] != s2[i2]){ - return s1[i1] < s2[i2]; - } - } - } - return false; - } -} -- cgit v1.2.3