aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcathook <b01902109@csie.ntu.edu.tw>2014-06-01 14:05:05 +0800
committercathook <b01902109@csie.ntu.edu.tw>2014-06-01 14:05:05 +0800
commit9ec5d78f273d306fb8793e73bbb658097439dbe2 (patch)
tree77c3e3d30f1010168252c70eed31afda5943b988
parent0b0382ba2908791a3d372406da49cf681a35e2f8 (diff)
downloadmeow-9ec5d78f273d306fb8793e73bbb658097439dbe2.tar
meow-9ec5d78f273d306fb8793e73bbb658097439dbe2.tar.gz
meow-9ec5d78f273d306fb8793e73bbb658097439dbe2.tar.bz2
meow-9ec5d78f273d306fb8793e73bbb658097439dbe2.tar.lz
meow-9ec5d78f273d306fb8793e73bbb658097439dbe2.tar.xz
meow-9ec5d78f273d306fb8793e73bbb658097439dbe2.tar.zst
meow-9ec5d78f273d306fb8793e73bbb658097439dbe2.zip
remove hpp
-rw-r--r--meowpp/Usage.hpp298
-rw-r--r--meowpp/colors/HSL.hpp150
-rw-r--r--meowpp/colors/HSV.hpp144
-rw-r--r--meowpp/colors/RGB.hpp119
-rw-r--r--meowpp/colors/YUV.hpp100
-rw-r--r--meowpp/dsa/BinaryIndexTree.hpp51
-rw-r--r--meowpp/dsa/DisjointSet.hpp55
-rw-r--r--meowpp/dsa/KD_Tree.hpp272
-rw-r--r--meowpp/dsa/MergeableHeap.hpp127
-rw-r--r--meowpp/dsa/SegmentTree.hpp117
-rw-r--r--meowpp/dsa/SplayTree.hpp437
-rw-r--r--meowpp/dsa/SplayTree_Range.hpp506
-rw-r--r--meowpp/dsa/VP_Tree.hpp276
-rw-r--r--meowpp/geo/Vector2D.hpp327
-rw-r--r--meowpp/geo/Vector3D.hpp359
-rw-r--r--meowpp/math/LinearTransformations.hpp148
-rw-r--r--meowpp/math/Matrix.hpp329
-rw-r--r--meowpp/math/Transformations.hpp193
-rw-r--r--meowpp/math/utility.hpp102
-rw-r--r--meowpp/oo/ObjPort.hpp47
-rw-r--r--meowpp/oo/Properties.hpp175
-rw-r--r--meowpp/utility.hpp107
22 files changed, 0 insertions, 4439 deletions
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 <cstdlib>
-
-#include <algorithm>
-#include <string>
-#include <vector>
-#include <map>
-
-extern "C"{
-#include <unistd.h>
-}
-
-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>", name));
- }
- inline void Usage::addUsageEnd(Usage::String const& des){
- usage_end.push_back(stringReplace(des, "<name>", 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, "<value>", 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, "<type>", 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, "<values>", 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 <cstdlib>
-
-#include <algorithm>
-
-namespace meow{
- template<class T>
- inline HSL<T>::HSL(){ }
- template<class T>
- inline HSL<T>::HSL(T const& h, T const& s, T const& l){
- hsl_[0] = h; hsl_[1] = s; hsl_[2] = l;
- }
- template<class T>
- inline HSL<T>::HSL(T const* hsl){
- for(int i = 0; i < 3; i++) hsl_[i] = hsl[i];
- }
-
- template<class T>
- inline T HSL<T>::h() const { return hsl_[0]; }
- template<class T>
- inline T HSL<T>::s() const { return hsl_[1]; }
- template<class T>
- inline T HSL<T>::l() const { return hsl_[2]; }
- template<class T>
- inline T HSL<T>::hsl(size_t i) const {
- return hsl_[std::min((size_t)3 - 1, i)];
- }
- template<class T>
- inline T HSL<T>::lsh(size_t i)const{return hsl(2-i);}
- template<class T>
- inline T HSL<T>::h(T const& val){return (hsl_[0]=val);}
- template<class T>
- inline T HSL<T>::s(T const& val){return (hsl_[1]=val);}
- template<class T>
- inline T HSL<T>::l(T const& val){return (hsl_[2]=val);}
- template<class T>
- inline T HSL<T>::hsl(size_t i, T const& val){
- return (hsl_[std::min((size_t)3 - 1, i)] = val);
- }
- template<class T>
- inline T HSL<T>::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<class HSL_T1, class HSL_T2>
- inline void HSL_to_HSL(HSL<HSL_T1> const& a, HSL<HSL_T2>* 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<class RGB_T, class HSL_T>
- inline void RGB_to_HSL(RGB<RGB_T> const& rgb, HSL<HSL_T>* 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<class HSL_T, class RGB_T>
- inline void HSL_to_RGB(HSL<HSL_T> const& hsl, RGB<RGB_T>* 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<class YUV_T, class HSL_T>
- inline void YUV_to_HSL(YUV<YUV_T> const& yuv, HSL<HSL_T>* hsl){
- RGBf tmp;
- YUV_to_RGB(yuv, &tmp);
- RGB_to_HSL(tmp, hsl);
- }
- template<class HSL_T, class YUV_T>
- inline void HSL_to_YUV(HSL<HSL_T> const& hsl, YUV<YUV_T>* 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 <cstdlib>
-
-#include <algorithm>
-
-namespace meow{
- template<class T>
- inline HSV<T>::HSV(){ }
- template<class T>
- inline HSV<T>::HSV(T const& h, T const& s, T const& v){
- hsv_[0] = h; hsv_[1] = s; hsv_[2] = v;
- }
- template<class T>
- inline HSV<T>::HSV(T const* hsv){
- for(int i = 0; i < 3; i++) hsv_[i] = hsv[i];
- }
-
- template<class T>
- inline T HSV<T>::h() const { return hsv_[0]; }
- template<class T>
- inline T HSV<T>::s() const { return hsv_[1]; }
- template<class T>
- inline T HSV<T>::v() const { return hsv_[2]; }
- template<class T>
- inline T HSV<T>::hsv(size_t i) const {
- return hsv_[std::min((size_t)3 - 1, i)];
- }
- template<class T>
- inline T HSV<T>::vsh(size_t i)const{return hsv(2-i);}
- template<class T>
- inline T HSV<T>::h(T const& val){return (hsv_[0]=val);}
- template<class T>
- inline T HSV<T>::s(T const& val){return (hsv_[1]=val);}
- template<class T>
- inline T HSV<T>::v(T const& val){return (hsv_[2]=val);}
- template<class T>
- inline T HSV<T>::hsv(size_t i, T const& val){
- return (hsv_[std::min((size_t)3 - 1, i)] = val);
- }
- template<class T>
- inline T HSV<T>::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<class HSV_T1, class HSV_T2>
- inline void HSV_to_HSV(HSV<HSV_T1> const& a, HSV<HSV_T2>* 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<class RGB_T, class HSV_T>
- inline void RGB_to_HSV(RGB<RGB_T> const& rgb, HSV<HSV_T>* 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<class HSV_T, class RGB_T>
- inline void HSV_to_RGB(HSV<HSV_T> const& hsv, RGB<RGB_T>* 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<class YUV_T, class HSV_T>
- inline void YUV_to_HSV(YUV<YUV_T> const& yuv, HSV<HSV_T>* hsv){
- RGBf tmp;
- YUV_to_RGB(yuv, &tmp);
- RGB_to_HSV(tmp, hsv);
- }
- template<class HSV_T, class YUV_T>
- inline void HSV_to_YUV(HSV<HSV_T> const& hsv, YUV<YUV_T>* yuv){
- RGBf tmp;
- HSV_to_RGB(hsv, &tmp);
- RGB_to_YUV(tmp, yuv);
- }
- template<class HSL_T, class HSV_T>
- inline void HSL_to_HSV(HSL<HSL_T> const& hsl, HSV<HSV_T>* hsv){
- RGBf tmp;
- HSL_to_RGB(hsl, &tmp);
- RGB_to_HSV(tmp, hsv);
- }
- template<class HSV_T, class HSL_T>
- inline void HSV_to_HSL(HSV<HSV_T> const& hsv, HSL<HSL_T>* 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 <cstdlib>
-
-#include <algorithm>
-
-#include "../math/utility.h"
-
-#include "../geo/Vector3D.h"
-#include "../math/Matrix.h"
-
-namespace meow{
- template<class T>
- inline RGB<T>::RGB(){ }
- template<class T>
- inline RGB<T>::RGB(T const& r, T const& g, T const& b){
- rgb_[0] = r; rgb_[1] = g; rgb_[2] = b;
- }
- template<class T>
- inline RGB<T>::RGB(T const* rgb){
- for(int i = 0; i < 3; i++){
- rgb_[i] = rgb[i];
- }
- }
- template<class T>
- inline T RGB<T>::r() const { return rgb_[0]; }
- template<class T>
- inline T RGB<T>::g() const { return rgb_[1]; }
- template<class T>
- inline T RGB<T>::b() const { return rgb_[2]; }
- template<class T>
- inline T RGB<T>::rgb(size_t i) const {
- return rgb_[std::min((size_t)3 - 1, i)];
- }
- template<class T>
- inline T RGB<T>::bgr(size_t i) const { return rgb(2 - i); }
- /////////////////// **# setting #** ////////////////
- template<class T>
- inline T RGB<T>::r(T const& val){ return (rgb_[0] = val); }
- template<class T>
- inline T RGB<T>::g(T const& val){ return (rgb_[1] = val); }
- template<class T>
- inline T RGB<T>::b(T const& val){ return (rgb_[2] = val); }
- template<class T>
- inline T RGB<T>::rgb(size_t i, T const& val){
- i = std::min((size_t)3 - 1, i);
- return (rgb_[i] = val);
- }
- template<class T>
- inline T RGB<T>::bgr(size_t i, T const& val){
- return rgb(2 - i, val);
- }
- template<class T>
- inline T RGB<T>::rgb(T const& __r, T const& __g, T const& __b){
- r(__r);
- g(__g);
- b(__b);
- }
- template<class T>
- inline T RGB<T>::bgr(T const& __b, T const& __g, T const& __r){
- r(__r);
- g(__g);
- b(__b);
- }
- template<class T>
- inline Matrix<T> RGB<T>::matrix() const{
- static Matrix<T> ret(3, 1, T(0));
- ret(0, 0) = r();
- ret(1, 0) = g();
- ret(2, 0) = b();
- return ret;
- }
- template<class T>
- inline Vector3D<T> RGB<T>::vector() const{
- static Vector3D<T> 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<class RGB_T1, class RGB_T2>
- inline void RGB_to_RGB(RGB<RGB_T1> const& a, RGB<RGB_T2>* 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 <cstdlib>
-
-#include <algorithm>
-
-namespace meow{
- template<class T>
- inline YUV<T>::YUV(){ }
- template<class T>
- inline YUV<T>::YUV(T const& y, T const& u, T const& v){
- yuv_[0] = y; yuv_[1] = u; yuv_[2] = v;
- }
- template<class T>
- inline YUV<T>::YUV(T const* yuv){
- for(int i = 0; i < 3; i++){
- yuv_[i] = yuv[i];
- }
- }
- /////////////////// **# access #** /////////////////
- template<class T>
- inline T YUV<T>::y() const { return yuv_[0]; }
- template<class T>
- inline T YUV<T>::u() const { return yuv_[1]; }
- template<class T>
- inline T YUV<T>::v() const { return yuv_[2]; }
- template<class T>
- inline T YUV<T>::yuv(size_t i) const {
- return yuv_[std::min((size_t)3 - 1, i)];
- }
- template<class T>
- inline T YUV<T>::vuy(size_t i) const {return yuv(2-i);}
- /////////////////// **# setting #** ////////////////
- template<class T>
- inline T YUV<T>::y(T const& val){return (yuv_[0]=val);}
- template<class T>
- inline T YUV<T>::u(T const& val){return (yuv_[1]=val);}
- template<class T>
- inline T YUV<T>::v(T const& val){return (yuv_[2]=val);}
- template<class T>
- inline T YUV<T>::yuv(size_t i, T const& val){
- i = std::min((size_t)3 - 1, i);
- return (yuv_[i] = val);
- }
- template<class T>
- inline T YUV<T>::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<class YUV_T1, class YUV_T2>
- inline void YUV_to_YUV(YUV<YUV_T1> const& a, YUV<YUV_T2>* 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<class RGB_T, class YUV_T>
- inline void RGB_to_YUV(RGB<RGB_T> const& rgb, YUV<YUV_T>* 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<class YUV_T, class RGB_T>
- inline void YUV_to_RGB(YUV<YUV_T> const& yuv, RGB<RGB_T>* 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 <cstdlib>
-
-#include <vector>
-#include <algorithm>
-
-
-namespace meow{
- template<class Value>
- inline
- BinaryIndexTree<Value>::BinaryIndexTree():
- _array(0){
- }
- template<class Value>
- inline
- BinaryIndexTree<Value>::BinaryIndexTree(size_t __size, Value const& __value):
- _array(__size, __value){
- }
- template<class Value>
- inline
- BinaryIndexTree<Value>::BinaryIndexTree(BinaryIndexTree const& __tree2):
- _array(__tree2._array){
- }
- //
- template<class Value>
- inline void
- BinaryIndexTree<Value>::reset(size_t __size, Value const& __init){
- _array.clear();
- _array.resize(__size, __init);
- }
- //
- template<class Value>
- inline void
- BinaryIndexTree<Value>::update(size_t __index, Value const& __value){
- __index++;
- for( ; __index <= _array.size(); __index += (__index & -__index)){
- _array[__index - 1] = _array[__index - 1] + __value;
- }
- }
- template<class Value>
- inline Value
- BinaryIndexTree<Value>::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 <vector>
-#include <cstdlib>
-
-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 <cstdlib>
-
-#include <vector>
-#include <algorithm>
-#include <queue>
-
-namespace meow{
- ////////////////////////////////////////////////////////////////////
- // **# Node #** //
- ////////////////////////////////////////////////////////////////////
- template<class Vector, class Scalar>
- inline
- KD_Tree<Vector, Scalar>::Node::Node(Vector __vector,
- ssize_t __lChild, ssize_t __rChild):
- _vector(__vector), _lChild(__lChild), _rChild(__rChild){
- }
- ////////////////////////////////////////////////////////////////////
- // **# Sorter #** //
- ////////////////////////////////////////////////////////////////////
- template<class Vector, class Scalar>
- inline
- KD_Tree<Vector, Scalar>::Sorter::Sorter(Nodes const* __nodes, size_t __cmp):
- _nodes(__nodes), _cmp(__cmp){
- }
- template<class Vector, class Scalar>
- inline bool
- KD_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline
- KD_Tree<Vector, Scalar>::Answer::Answer(ssize_t __index, Scalar __dist2):
- _index(__index), _dist2(__dist2){
- }
- template<class Vector, class Scalar>
- inline
- KD_Tree<Vector, Scalar>::Answer::Answer(Answer const& __answer2):
- _index(__answer2._index), _dist2(__answer2._dist2){
- }
- //
- template<class Vector, class Scalar>
- inline
- KD_Tree<Vector, Scalar>::AnswerCompare::AnswerCompare(Nodes const* __nodes,
- bool __cmpValue):
- _nodes(__nodes), _cmpValue(__cmpValue){
- }
- template<class Vector, class Scalar>
- inline bool
- KD_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline Scalar
- KD_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline void
- KD_Tree<Vector, Scalar>::query(Vector const& __vector,
- size_t __nearestNumber,
- AnswerCompare const& __answerCompare,
- ssize_t __index,
- int __depth,
- std::vector<Scalar>& __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<class Vector, class Scalar>
- inline ssize_t
- KD_Tree<Vector, Scalar>::build(ssize_t __beg,
- ssize_t __end,
- std::vector<size_t>* __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<class Vector, class Scalar>
- inline
- KD_Tree<Vector, Scalar>::KD_Tree():
- _NIL(-1), _root(_NIL), _needRebuild(false), _dimension(1){
- }
- template<class Vector, class Scalar>
- inline
- KD_Tree<Vector, Scalar>::KD_Tree(size_t __dimension):
- _NIL(-1), _root(_NIL), _needRebuild(false), _dimension(__dimension){
- }
- template<class Vector, class Scalar>
- inline
- KD_Tree<Vector, Scalar>::~KD_Tree(){
- }
- ////////////////////////////////////////////////////////////////////
- // **# insert, build #** //
- ////////////////////////////////////////////////////////////////////
- template<class Vector, class Scalar>
- inline void
- KD_Tree<Vector, Scalar>::insert(Vector const& __vector){
- _nodes.push_back(Node(__vector, _NIL, _NIL));
- _needRebuild = true;
- }
- template<class Vector, class Scalar>
- inline bool
- KD_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline void
- KD_Tree<Vector, Scalar>::build(){
- if(_needRebuild){
- forceBuild();
- }
- }
- template<class Vector, class Scalar>
- inline void
- KD_Tree<Vector, Scalar>::forceBuild(){
- std::vector<size_t> *orders = new std::vector<size_t>[_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<class Vector, class Scalar>
- inline typename KD_Tree<Vector, Scalar>::Vectors
- KD_Tree<Vector, Scalar>::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<Scalar> 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<class Vector, class Scalar>
- inline void
- KD_Tree<Vector, Scalar>::clear(){
- _root = _NIL;
- _nodes.clear();
- _needRebuild = false;
- }
- template<class Vector, class Scalar>
- inline void
- KD_Tree<Vector, Scalar>::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 <cstdlib>
-
-#include <algorithm>
-
-namespace meow{
- //////////////////////////////////////////////////////////
- // **# MergeableHeap--Node-- constructor #** //
- //////////////////////////////////////////////////////////
- template<class Element>
- inline MergeableHeap<Element>::Node::Node(Element const& _value): // Node
- value(_value), l_child(NULL), r_child(NULL), weight(1){ }
-
- //////////////////////////////////////////////////////////
- // **# MergeableHeap -- clear, duplicate #** //
- //////////////////////////////////////////////////////////
- template<class Element>
- inline void MergeableHeap<Element>::clear(Node* _node){ //clear
- if(_node != NULL){
- clear(_node->l_child);
- clear(_node->r_child);
- delete _node;
- }
- }
- template<class Element>
- inline typename MergeableHeap<Element>::Node*
- MergeableHeap<Element>::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<class Element>
- inline typename MergeableHeap<Element>::Node*
- MergeableHeap<Element>::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<class Element>
- inline MergeableHeap<Element>::MergeableHeap(): //MergeableHeap
- root(NULL){ }
- template<class Element>
- inline MergeableHeap<Element>::MergeableHeap(MergeableHeap const& _heap2):
- root(NULL){ root = dup(_heap2.root); }
- template<class Element>
- inline MergeableHeap<Element>::~MergeableHeap(){ //~MergeableHeap
- clear(root);
- }
-
- //////////////////////////////////////////////////////////
- //**# MergeableHeap -- copy operation/data transform #**//
- //////////////////////////////////////////////////////////
- template<class Element>
- inline MergeableHeap<Element>&
- MergeableHeap<Element>::operator=(MergeableHeap const& _heap2){ // =
- root = dup(_heap2.root);
- return *this;
- }
- template<class Element>
- inline void MergeableHeap<Element>::moveTo(MergeableHeap* _heap2){ // moveTo
- _heap2->clear();
- _heap2->root = root;
- root = NULL;
- }
- //////////////////////////////////////////////////////////
- // **# MergeableHeap -- access: top, size, emtpy #** //
- //////////////////////////////////////////////////////////
- template<class Element> // top
- inline Element const& MergeableHeap<Element>::top()const{return root->value;}
- template<class Element> // size
- inline size_t MergeableHeap<Element>::size() const{
- return (root == NULL ? 0 : root->weight);
- }
- template<class Element> // empty
- inline bool MergeableHeap<Element>::empty() const{ return (size() == 0); }
- //////////////////////////////////////////////////////////
- // **# MergeableHeap -- update: push, pop, merge #** //
- //////////////////////////////////////////////////////////
- template<class Element>
- inline void MergeableHeap<Element>::push(Element const& _value){ // push
- root = merge(root, new Node(_value));
- }
- template<class Element>
- inline void MergeableHeap<Element>::pop(){ // pop
- Node* l = root->l_child;
- Node* r = root->r_child;
- delete root;
- root = merge(l, r);
- }
- template<class Element>
- inline void MergeableHeap<Element>::merge(MergeableHeap* _heap2){ // merge
- root = merge(root, _heap2->root);
- _heap2->root = NULL;
- }
- //////////////////////////////////////////////////////////
- // **# MergeableHeap -- refresh: clear #** //
- //////////////////////////////////////////////////////////
- template<class Element>
- inline void MergeableHeap<Element>::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 <cstdlib>
-
-#include <vector>
-#include <algorithm>
-
-namespace meow{
-
- template<class Value>
- inline void
- SegmentTree<Value>::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<class Value>
- inline void
- SegmentTree<Value>::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<class Value>
- inline Value
- SegmentTree<Value>::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<class Value>
- inline bool
- SegmentTree<Value>::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<class Value>
- inline SegmentTree<Value>::SegmentTree(){ reset(1); }
- template<class Value>
- inline SegmentTree<Value>::SegmentTree(size_t __size){ reset(__size); }
- template<class Value>
- inline SegmentTree<Value>::SegmentTree(SegmentTree const& __tree2):
- _size(__tree2._size), _nodes(__tree2._nodes){ }
- //
- template<class Value>
- inline void
- SegmentTree<Value>::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<class Value>
- inline Value
- SegmentTree<Value>::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<class Value>
- inline void
- SegmentTree<Value>::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<class Value>
- inline void
- SegmentTree<Value>::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 <cstdlib>
-
-#include <utility>
-
-namespace meow{
- ///////////////////////////// **# Node #** /////////////////////////
- //////////////////// **# Node -- Constructure #** //////////////////
- template<class Key, class Value>
- inline
- SplayTree<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree<Key, Value>::Node::keyOffset(Key const& __delta){
- _key = _key + __delta;
- _keyOffset = _keyOffset + __delta;
- }
- //////////////////////// **# Node -- sync #** //////////////////////
- template<class Key, class Value>
- inline void
- SplayTree<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree<Key, Value>::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<class Key, class Value>
- inline typename SplayTree<Key, Value>::Node const*
- SplayTree<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree<Key, Value>::clear(Node* __node){
- if(__node == NULL) return ;
- clear(__node->_child[0]);
- clear(__node->_child[1]);
- delete __node;
- }
- template<class Key, class Value>
- inline typename SplayTree<Key, Value>::Node*
- SplayTree<Key, Value>::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<class Key, class Value>
- inline typename SplayTree<Key, Value>::Node const*
- SplayTree<Key, Value>::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<class Key, class Value>
- inline typename SplayTree<Key, Value>::Node const*
- SplayTree<Key, Value>::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<class Key, class Value>
- inline typename SplayTree<Key, Value>::Node const*
- SplayTree<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree<Key, Value>::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<class Key, class Value>
- inline typename SplayTree<Key, Value>::Node*
- SplayTree<Key, Value>::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<class Key, class Value>
- inline void SplayTree<Key, Value>::Element::reset(Node* __node){
- _node = __node;
- delete _entry;
- if(__node == NULL) _entry = NULL;
- else _entry = new Entry(__node->_key, __node->_value);
- }
- //
- template<class Key, class Value>
- inline
- SplayTree<Key, Value>::Element::Element():
- _entry(NULL), _node(NULL){
- }
- template<class Key, class Value>
- inline
- SplayTree<Key, Value>::Element::Element(Node* __node):
- _entry(NULL), _node(NULL){
- reset(__node);
- }
- template<class Key, class Value>
- inline
- SplayTree<Key, Value>::Element::Element(Element const& __element2):
- _entry(NULL), _node(NULL){
- reset(__element2._node);
- }
- template<class Key, class Value>
- inline
- SplayTree<Key, Value>::Element::~Element(){
- delete _entry;
- }
- template<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element&
- SplayTree<Key, Value>::Element::operator=(Element const& __e2){
- reset(__e2._node);
- return *this;
- }
- //////////////////// **# Element operations #** ////////////////////
- template<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element::Entry*
- SplayTree<Key, Value>::Element::operator->(){ return _entry; }
- template<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element::Entry&
- SplayTree<Key, Value>::Element::operator*(){ return *_entry; }
- //
- template<class Key, class Value>
- inline bool
- SplayTree<Key, Value>::Element::operator==(Element const& __e2) const{
- return (_node == __e2._node);
- }
- template<class Key, class Value>
- inline bool
- SplayTree<Key, Value>::Element::operator!=(Element const& __e2) const{
- return (_node != __e2._node);
- }
- /////// **# Splay tree constructure/destructure/copy oper #** //////
- template<class Key, class Value>
- inline
- SplayTree<Key, Value>::SplayTree(): _root(NULL){
- }
- template<class Key, class Value>
- inline
- SplayTree<Key, Value>::SplayTree(SplayTree const& __tree2): _root(NULL){
- _root = dup((Node*)(__tree2._root));
- }
- template<class Key, class Value>
- inline
- SplayTree<Key, Value>::~SplayTree(){
- clear(_root);
- }
- template<class Key, class Value>
- inline SplayTree<Key, Value>&
- SplayTree<Key, Value>::operator=(SplayTree const& __tree2){
- clear(_root);
- _root = dup((Node*)(__tree2._root));
- return *this;
- }
- template<class Key, class Value>
- inline void
- SplayTree<Key, Value>::moveTo(SplayTree* __tree2){
- __tree2->clear();
- __tree2->_root = _root;
- _root = NULL;
- }
- //////////////////////// **# Bounding #** //////////////////////////
- template<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element
- SplayTree<Key, Value>::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<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element
- SplayTree<Key, Value>::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<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element
- SplayTree<Key, Value>::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<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element
- SplayTree<Key, Value>::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<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element
- SplayTree<Key, Value>::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<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element
- SplayTree<Key, Value>::order(size_t __order) const{
- if(_root == NULL || __order >= _root->_size) return Element(NULL);
- splay(findOrder(_root, __order + 1));
- return Element(_root);
- }
- template<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element
- SplayTree<Key, Value>::first() const{
- splay(findMinMax(_root, true));
- return Element(_root);
- }
- template<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element
- SplayTree<Key, Value>::last() const{
- splay(findMinMax(_root, false));
- return Element(_root);
- }
- template<class Key, class Value>
- inline typename SplayTree<Key, Value>::Element
- SplayTree<Key, Value>::end() const{ return Element(NULL); }
- //////////////////// **# size, empty, clear #** ////////////////////
- template<class Key, class Value>
- inline size_t SplayTree<Key, Value>::size() const{
- return (_root == NULL ? 0 : _root->_size);
- }
- template<class Key, class Value>
- inline bool SplayTree<Key, Value>::empty() const{
- return (size() == 0);
- }
- //
- template<class Key, class Value>
- inline void SplayTree<Key, Value>::clear(){
- clear(_root);
- _root = NULL;
- }
- ////////////// **# insert, erase, keyOffset, oper[] #** ////////////
- template<class Key, class Value>
- inline bool SplayTree<Key, Value>::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<class Key, class Value>
- inline bool SplayTree<Key, Value>::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<class Key, class Value>
- inline void SplayTree<Key, Value>::keyOffset(Key const& __delta){
- if(_root != NULL){
- _root->keyOffset(__delta);
- }
- }
- template<class Key, class Value>
- inline Value&
- SplayTree<Key, Value>::operator[](Key const& __key){
- if(find(__key) == end()) insert(__key, Value());
- return _root->_value;
- }
- /////////////////////// **# split, merge #** ///////////////////////
- template<class Key, class Value>
- inline void
- SplayTree<Key, Value>::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<class Key, class Value>
- inline bool
- SplayTree<Key, Value>::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<class Key, class Value>
- inline bool
- SplayTree<Key, Value>::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 <cstdlib>
-
-#include <utility>
-
-#include "../math/utility.h"
-
-namespace meow{
- ///////////////////////////// **# Node #** /////////////////////////
- //////////////////// **# Node -- Constructure #** //////////////////
- template<class Key, class Value>
- inline
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree_Range<Key, Value>::Node::keyOffset(Key const& __delta){
- _key = _key + __delta;
- _keyOffset = _keyOffset + __delta;
- }
- template<class Key, class Value>
- inline void
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Node const*
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree_Range<Key, Value>::clear(Node* __node){
- if(__node == NULL) return ;
- clear(__node->_child[0]);
- clear(__node->_child[1]);
- delete __node;
- }
- template<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Node*
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Node const*
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Node const*
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Node const*
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline void
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Node*
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline void SplayTree_Range<Key, Value>::Element::reset(Node* __node){
- _node = __node;
- delete _entry;
- if(__node == NULL) _entry = NULL;
- else _entry = new Entry(__node->_key, __node->_value);
- }
- //
- template<class Key, class Value>
- inline
- SplayTree_Range<Key, Value>::Element::Element():
- _entry(NULL), _node(NULL){
- }
- template<class Key, class Value>
- inline
- SplayTree_Range<Key, Value>::Element::Element(Node* __node):
- _entry(NULL), _node(NULL){
- reset(__node);
- }
- template<class Key, class Value>
- inline
- SplayTree_Range<Key, Value>::Element::Element(Element const& __element2):
- _entry(NULL), _node(NULL){
- reset(__element2._node);
- }
- template<class Key, class Value>
- inline
- SplayTree_Range<Key, Value>::Element::~Element(){
- delete _entry;
- }
- template<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element&
- SplayTree_Range<Key, Value>::Element::operator=(Element const& __e2){
- reset(__e2._node);
- return *this;
- }
- //////////////////// **# Element operations #** ////////////////////
- template<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element::Entry*
- SplayTree_Range<Key, Value>::Element::operator->(){ return _entry; }
- template<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element::Entry&
- SplayTree_Range<Key, Value>::Element::operator*(){ return *_entry; }
- //
- template<class Key, class Value>
- inline bool
- SplayTree_Range<Key, Value>::Element::operator==(Element const& __e2) const{
- return (_node == __e2._node);
- }
- template<class Key, class Value>
- inline bool
- SplayTree_Range<Key, Value>::Element::operator!=(Element const& __e2) const{
- return (_node != __e2._node);
- }
- /////// **# Splay tree constructure/destructure/copy oper #** //////
- template<class Key, class Value>
- inline
- SplayTree_Range<Key, Value>::SplayTree_Range(): _root(NULL){
- }
- template<class Key, class Value>
- inline
- SplayTree_Range<Key, Value>::SplayTree_Range(SplayTree_Range const& __tree2):
- _root(NULL){
- _root = dup((Node*)(__tree2._root));
- }
- template<class Key, class Value>
- inline
- SplayTree_Range<Key, Value>::~SplayTree_Range(){
- clear(_root);
- }
- template<class Key, class Value>
- inline SplayTree_Range<Key, Value>&
- SplayTree_Range<Key, Value>::operator=(SplayTree_Range const& __tree2){
- clear(_root);
- _root = dup((Node*)(__tree2._root));
- return *this;
- }
- template<class Key, class Value>
- inline void
- SplayTree_Range<Key, Value>::moveTo(SplayTree_Range* __tree2){
- __tree2->clear();
- __tree2->_root = _root;
- _root = NULL;
- }
- //////////////////////// **# Bounding #** //////////////////////////
- template<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element
- SplayTree_Range<Key, Value>::order(size_t __order) const{
- if(_root == NULL || __order >= _root->_size) return Element(NULL);
- splay(findOrder(_root, __order + 1));
- return Element(_root);
- }
- template<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element
- SplayTree_Range<Key, Value>::first() const{
- splay(findMinMax(_root, true));
- return Element(_root);
- }
- template<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element
- SplayTree_Range<Key, Value>::last() const{
- splay(findMinMax(_root, false));
- return Element(_root);
- }
- template<class Key, class Value>
- inline typename SplayTree_Range<Key, Value>::Element
- SplayTree_Range<Key, Value>::end() const{ return Element(NULL); }
- //////////////////// **# query, range query #** ////////////////////
- template<class Key, class Value>
- inline Value
- SplayTree_Range<Key, Value>::query() const{
- if(_root == NULL) return Value(0);
- return _root->_range;
- }
- template<class Key, class Value>
- inline Value
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline size_t SplayTree_Range<Key, Value>::size() const{
- return (_root == NULL ? 0 : _root->_size);
- }
- template<class Key, class Value>
- inline bool SplayTree_Range<Key, Value>::empty() const{
- return (size() == 0);
- }
- //
- template<class Key, class Value>
- inline void SplayTree_Range<Key, Value>::clear(){
- clear(_root);
- _root = NULL;
- }
- ////////////// **# insert, erase, keyOffset, oper[] #** ////////////
- template<class Key, class Value>
- inline bool SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline bool SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline void SplayTree_Range<Key, Value>::keyOffset(Key const& __delta){
- if(_root != NULL){
- _root->keyOffset(__delta);
- }
- }
- template<class Key, class Value>
- inline void SplayTree_Range<Key, Value>::valueOffset(Value const& __delta){
- if(_root != NULL){
- _root->valueUpdate(__delta, false);
- }
- }
- template<class Key, class Value>
- inline void SplayTree_Range<Key, Value>::valueOverride(Value const& __value){
- if(_root != NULL){
- _root->valueUpdate(__value, true);
- }
- }
- template<class Key, class Value>
- inline Value&
- SplayTree_Range<Key, Value>::operator[](Key const& __key){
- if(find(__key) == end()) insert(__key, Value());
- return _root->_value;
- }
- /////////////////////// **# split, merge #** ///////////////////////
- template<class Key, class Value>
- inline void
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline bool
- SplayTree_Range<Key, Value>::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<class Key, class Value>
- inline bool
- SplayTree_Range<Key, Value>::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 <cstdlib>
-
-#include <algorithm>
-#include <stack>
-#include "../math/utility.h"
-
-namespace meow{
- ///////////////////// **# Node #** ///////////////////////
- template<class Vector, class Scalar>
- inline
- VP_Tree<Vector, Scalar>::Node::Node(size_t __index):
- _index(__index), _nearChild(NULL), _farChild(NULL){
- }
- ///////////////////// **# Answer #** /////////////////////
- template<class Vector, class Scalar>
- inline
- VP_Tree<Vector, Scalar>::Answer::Answer(size_t __index,
- Scalar const& __dist2):
- _index(__index), _dist2(__dist2){
- }
- template<class Vector, class Scalar>
- inline
- VP_Tree<Vector, Scalar>::Answer::Answer(Answer const& __answer2):
- _index(__answer2._index), _dist2(__answer2._dist2){
- }
- template<class Vector, class Scalar>
- inline
- VP_Tree<Vector, Scalar>::AnswerCompare::AnswerCompare
- (Vectors const* __vectors, bool __cmpValue):
- _vectors(__vectors), _cmpValue(__cmpValue){
- }
- template<class Vector, class Scalar>
- inline bool
- VP_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline Scalar
- VP_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline int
- VP_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline Scalar
- VP_Tree<Vector, Scalar>::split(ssize_t __first, ssize_t __last,
- size_t __order, Vector const& __center){
- ssize_t first0 = __first;
- std::vector<Scalar> 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<class Vector, class Scalar>
- inline typename VP_Tree<Vector, Scalar>::Node*
- VP_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline void
- VP_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline void
- VP_Tree<Vector, Scalar>::clear(Node* __root){
- if(__root == NULL) return ;
- clear(__root->_nearChild);
- clear(__root->_farChild);
- delete __root;
- }
- template<class Vector, class Scalar>
- inline typename VP_Tree<Vector, Scalar>::Node*
- VP_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline
- VP_Tree<Vector, Scalar>::VP_Tree():
- _root(NULL), _vectors(0), _dimension(0), _needRebuild(false){
- reset(0);
- }
- template<class Vector, class Scalar>
- inline
- VP_Tree<Vector, Scalar>::VP_Tree(VP_Tree<Vector, Scalar> const& __tree2):
- _vectors(__tree2._vectors),
- _root(dup(__tree2._root)),
- _dimension(__tree2._dimension),
- _needRebuild(__tree2._needRebuild){
- }
- template<class Vector, class Scalar>
- inline
- VP_Tree<Vector, Scalar>::VP_Tree(size_t __dimension):
- _vectors(0),
- _root(NULL),
- _dimension(0),
- _needRebuild(false){
- reset(__dimension);
- }
- template<class Vector, class Scalar>
- inline
- VP_Tree<Vector, Scalar>::~VP_Tree(){
- clear(_root);
- }
- template<class Vector, class Scalar>
- inline VP_Tree<Vector, Scalar>&
- VP_Tree<Vector, Scalar>::operator=(VP_Tree const& __tree2){
- reset(__tree2._dimension);
- _vectors = __tree2._vectors;
- _root = dup(__tree2._root);
- _needRebuild = __tree2._needRebuild;
- }
- ////////////////// **# insert, erase #** /////////////////
- template<class Vector, class Scalar>
- inline void
- VP_Tree<Vector, Scalar>::insert(Vector const& __vector){
- _vectors.push_back(__vector);
- _needRebuild = true;
- }
- template<class Vector, class Scalar>
- inline bool
- VP_Tree<Vector, Scalar>::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<class Vector, class Scalar>
- inline void
- VP_Tree<Vector, Scalar>::build(){
- if(_needRebuild){
- forceBuild();
- }
- }
- template<class Vector, class Scalar>
- inline void
- VP_Tree<Vector, Scalar>::forceBuild(){
- _root = build(0, (size_t)_vectors.size() - 1);
- _needRebuild = false;
- }
- ////////////////////// **# query #** /////////////////////
- template<class Vector, class Scalar>
- inline typename VP_Tree<Vector, Scalar>::Vectors
- VP_Tree<Vector, Scalar>::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<Answer> 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<class Vector, class Scalar>
- void
- VP_Tree<Vector, Scalar>::clear(){
- clear(_root);
- _vectors.clear();
- _root = NULL;
- _needRebuild = false;
- }
- template<class Vector, class Scalar>
- size_t
- VP_Tree<Vector, Scalar>::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 <cmath>
-
-namespace meow{
- template<class Scalar>
- inline
- Vector2D<Scalar>::Vector2D():
- _x(0),
- _y(0){
- }
-
-
- template<class Scalar>
- inline
- Vector2D<Scalar>::Vector2D(Vector2D const& __v):
- _x(__v._x),
- _y(__v._y){
- }
-
-
- template<class Scalar>
- inline
- Vector2D<Scalar>::Vector2D(Scalar const& __x, Scalar const& __y):
- _x(__x),
- _y(__y){
- }
-
-
- template<class Scalar>
- inline
- Vector2D<Scalar>::~Vector2D(){
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>&
- Vector2D<Scalar>::copy(Vector2D const& __v){
- _x = __v.x();
- _y = __v.y();
- return *this;
- }
-
- template<class Scalar>
- inline Scalar const&
- Vector2D<Scalar>::x() const{
- return _x;
- }
-
-
- template<class Scalar>
- inline Scalar const&
- Vector2D<Scalar>::y() const{
- return _y;
- }
-
-
- template<class Scalar>
- inline Scalar const&
- Vector2D<Scalar>::x(Scalar const& __s){
- _x = __s;
- return x();
- }
-
-
- template<class Scalar>
- inline Scalar const&
- Vector2D<Scalar>::y(Scalar const& __s){
- _y = __s;
- return y();
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>&
- Vector2D<Scalar>::xy(Scalar const& __x, Scalar const& __y){
- _x = __x;
- _y = __y;
- return *this;
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::positive() const{
- return *this;
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::negative() const{
- return Vector2D<Scalar>(-x(), -y());
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::right() const{
- return Vector2D<Scalar>(-y(), x());
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::add(Vector2D const& __v) const{
- return Vector2D<Scalar>(x() + __v.x(), y() + __v.y());
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::sub(Vector2D const& __v) const{
- return Vector2D<Scalar>(x() - __v.x(), y() - __v.y());
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::mul(Scalar const& __s) const{
- return Vector2D<Scalar>(x() * __s, y() * __s);
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::div(Scalar const& __s) const{
- return Vector2D<Scalar>(x() / __s, y() / __s);
- }
-
-
- template<class Scalar>
- inline Scalar
- Vector2D<Scalar>::dot(Vector2D const& __v) const{
- return (x() * __v.x() + y() * __v.y());
- }
-
-
- template<class Scalar>
- inline Scalar
- Vector2D<Scalar>::cross(Vector2D const& __v) const{
- return (x() * __v.y() - y() * __v.x());
- }
-
-
- template<class Scalar>
- inline Scalar
- Vector2D<Scalar>::length() const{
- return Scalar(sqrt(double(length2())));
- }
-
-
- template<class Scalar>
- inline Scalar
- Vector2D<Scalar>::length2() const{
- return squ(x()) + squ(y());
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>&
- Vector2D<Scalar>::normalize(){
- return copy(normalized());
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::normalized() const{
- return div(length());
- }
-
- template<class Scalar>
- inline Vector2D<Scalar>&
- Vector2D<Scalar>::rotate(Scalar const& __theta){
- return copy(rotated(__theta));
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::rotated(Scalar const& __theta) const{
- Scalar cs(cos(-double(__theta)));
- Scalar sn(sin(-double(__theta)));
- Vector2D<Scalar> new_x(cs, sn);
- return Vector2D<Scalar>(new_x.dot(*this), new_x.cross(*this));
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>&
- Vector2D<Scalar>::reflect(Vector2D const& __v){
- return copy(reflected(__v));
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::reflected(Vector2D const& __v) const{
- return __v.mul(__v.dot(*this) * 2 / __v.length2()).sub(*this);
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- Vector2D<Scalar>::matrix() const{
- Matrix<Scalar> ret(2, 0, Scalar(0));
- ret(0, 0) = x();
- ret(1, 0) = y();
- return ret;
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- Vector2D<Scalar>::matrix(Scalar const& __homo) const{
- Matrix<Scalar> ret(3, 0, Scalar(0));
- ret(0, 0) = x();
- ret(1, 0) = y();
- ret(2, 0) = __homo;
- return ret;
- }
-
-
- template<class Scalar>
- inline Scalar const&
- Vector2D<Scalar>::operator()(size_t n) const{
- return (n == 0 ? x() : y());
- }
-
-
- template<class Scalar>
- inline Scalar&
- Vector2D<Scalar>::operator()(size_t n){
- return (n == 0 ? _x : _y);
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>&
- Vector2D<Scalar>::operator()(Scalar const& __x, Scalar const& __y){
- x(__x);
- y(__y);
- return *this;
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::operator+() const{
- return positive();
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::operator-() const{
- return negative();
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::operator~() const{
- return right();
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::operator+(Vector2D const& __v) const{
- return add(__v);
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::operator-(Vector2D const& __v) const{
- return sub(__v);
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::operator*(Scalar const& __s) const{
- return mul(__s);
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>
- Vector2D<Scalar>::operator/(Scalar const& __s) const{
- return div(__s);
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>&
- Vector2D<Scalar>::operator+=(Vector2D const& __v){
- return copy(add(__v));
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>&
- Vector2D<Scalar>::operator-=(Vector2D const& __v){
- return copy(sub(__v));
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>&
- Vector2D<Scalar>::operator*=(Scalar const& __s){
- return copy(mul(__s));
- }
-
-
- template<class Scalar>
- inline Vector2D<Scalar>&
- Vector2D<Scalar>::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 <cmath>
-
-namespace meow{
- template<class Scalar>
- inline
- Vector3D<Scalar>::Vector3D():
- _x(0),
- _y(0),
- _z(0){
- }
-
-
- template<class Scalar>
- inline
- Vector3D<Scalar>::Vector3D(Vector3D const& __v):
- _x(__v._x),
- _y(__v._y),
- _z(__v._z){
- }
-
-
- template<class Scalar>
- inline
- Vector3D<Scalar>::Vector3D(Scalar const& __x,
- Scalar const& __y,
- Scalar const& __z):
- _x(__x),
- _y(__y),
- _z(__z){
- }
-
-
- template<class Scalar>
- inline
- Vector3D<Scalar>::~Vector3D(){
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>&
- Vector3D<Scalar>::copy(Vector3D const& __v){
- _x = __v.x();
- _y = __v.y();
- _z = __v.z();
- return *this;
- }
-
- template<class Scalar>
- inline Scalar const&
- Vector3D<Scalar>::x() const{
- return _x;
- }
-
-
- template<class Scalar>
- inline Scalar const&
- Vector3D<Scalar>::y() const{
- return _y;
- }
-
-
- template<class Scalar>
- inline Scalar const&
- Vector3D<Scalar>::z() const{
- return _z;
- }
-
-
- template<class Scalar>
- inline Scalar const&
- Vector3D<Scalar>::x(Scalar const& __s){
- _x = __s;
- return x();
- }
-
-
- template<class Scalar>
- inline Scalar const&
- Vector3D<Scalar>::y(Scalar const& __s){
- _y = __s;
- return y();
- }
-
-
- template<class Scalar>
- inline Scalar const&
- Vector3D<Scalar>::z(Scalar const& __s){
- _z = __s;
- return z();
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>&
- Vector3D<Scalar>::xyz(Scalar const& __x,
- Scalar const& __y,
- Scalar const& __z){
- _x = __x;
- _y = __y;
- _z = __z;
- return *this;
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::positive() const{
- return *this;
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::negative() const{
- return Vector3D<Scalar>(-x(), -y(), -z());
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::right() const{
- return Vector3D<Scalar>(-y(), x());
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::add(Vector3D const& __v) const{
- return Vector3D<Scalar>(x() + __v.x(), y() + __v.y(), z() + __v.z());
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::sub(Vector3D const& __v) const{
- return Vector3D<Scalar>(x() - __v.x(), y() - __v.y(), z() - __v.z());
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::mul(Scalar const& __s) const{
- return Vector3D<Scalar>(x() * __s, y() * __s, z() * __s);
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::div(Scalar const& __s) const{
- return Vector3D<Scalar>(x() / __s, y() / __s, z() / __s);
- }
-
-
- template<class Scalar>
- inline Scalar
- Vector3D<Scalar>::dot(Vector3D const& __v) const{
- return (x() * __v.x() + y() * __v.y() + z() * __v.z());
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::cross(Vector3D const& __v) const{
- return Vector3D<Scalar>(y() * __v.z() - z() * __v.y(),
- z() * __v.x() - x() * __v.z(),
- x() * __v.y() - y() * __v.x());
- }
-
-
- template<class Scalar>
- inline Scalar
- Vector3D<Scalar>::length() const{
- return Scalar(sqrt(double(length2())));
- }
-
-
- template<class Scalar>
- inline Scalar
- Vector3D<Scalar>::length2() const{
- return squ(x()) + squ(y()) + squ(z());
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>&
- Vector3D<Scalar>::normalize(){
- return copy(normalized());
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::normalized() const{
- return div(length());
- }
-
- template<class Scalar>
- inline Vector3D<Scalar>&
- Vector3D<Scalar>::rotate(Vector3D const& __axis, Scalar const& __theta){
- return copy(rotated(__axis, __theta));
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::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<class Scalar>
- inline Vector3D<Scalar>&
- Vector3D<Scalar>::reflect(Vector3D const& __v){
- return copy(reflected(__v));
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::reflected(Vector3D const& __v) const{
- return __v.mul(__v.dot(*this) * 3 / __v.length2()).sub(*this);
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- Vector3D<Scalar>::matrix() const{
- Matrix<Scalar> ret(3, 0, Scalar(0));
- ret(0, 0) = x();
- ret(1, 0) = y();
- ret(2, 0) = z();
- return ret;
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- Vector3D<Scalar>::matrix(Scalar const& __homo) const{
- Matrix<Scalar> ret(4, 0, Scalar(0));
- ret(0, 0) = x();
- ret(1, 0) = y();
- ret(2, 0) = z();
- ret(3, 0) = __homo;
- return ret;
- }
-
-
- template<class Scalar>
- inline Scalar const&
- Vector3D<Scalar>::operator()(size_t n) const{
- return (n == 0 ? x() : (n == 1 ? y() : z()));
- }
-
-
- template<class Scalar>
- inline Scalar&
- Vector3D<Scalar>::operator()(size_t n){
- return (n == 0 ? _x : (n == 1 ? _y : _z));
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>&
- Vector3D<Scalar>::operator()(Scalar const& __x,
- Scalar const& __y,
- Scalar const& __z){
- x(__x);
- y(__y);
- z(__z);
- return *this;
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::operator+() const{
- return positive();
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::operator-() const{
- return negative();
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::operator~() const{
- return right();
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::operator+(Vector3D const& __v) const{
- return add(__v);
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::operator-(Vector3D const& __v) const{
- return sub(__v);
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::operator*(Scalar const& __s) const{
- return mul(__s);
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>
- Vector3D<Scalar>::operator/(Scalar const& __s) const{
- return div(__s);
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>&
- Vector3D<Scalar>::operator+=(Vector3D const& __v){
- return copy(add(__v));
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>&
- Vector3D<Scalar>::operator-=(Vector3D const& __v){
- return copy(sub(__v));
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>&
- Vector3D<Scalar>::operator*=(Scalar const& __s){
- return copy(mul(__s));
- }
-
-
- template<class Scalar>
- inline Vector3D<Scalar>&
- Vector3D<Scalar>::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 <cstdlib>
-#include <cmath>
-
-namespace meow{
- template<class Scalar>
- inline void
- Rotation3D<Scalar>::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<Scalar> 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<class Scalar>
- inline
- Rotation3D<Scalar>::Rotation3D():
- LinearTransformation(3u, 3u, 3u){
- _theta[0] = _theta[1] = _theta[2] = Scalar(0);
- _matrix.identitied();
- }
-
-
- template<class Scalar>
- inline void
- Rotation3D<Scalar>::axisTheta(Matrix<Scalar> 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<class Scalar>
- inline Scalar
- Rotation3D<Scalar>::parameter(size_t __i) const{
- return _theta[__i];
- }
-
-
- template<class Scalar>
- inline Scalar
- Rotation3D<Scalar>::parameter(size_t __i, Scalar const& __s) const{
- _theta[__i] = __s;
- calcMatrix();
- return _theta[__i];
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- Rotation3D<Scalar>::transformate(Matrix<Scalar> const& __x) const{
- return _matrix * __x;
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- Rotation3D<Scalar>::jacobian(Matrix<Scalar> const& __x) const{
- return _matrix;
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- Rotation3D<Scalar>::jacobian(Matrix<Scalar> const& __x,
- size_t __i) const{
- Matrix<Scalar> 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<class Scalar>
- inline Matrix<Scalar>
- Rotation3D<Scalar>::invTransformate(Matrix<Scalar> const& __x) const{
- return _matrix.transpose() * __x;
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- Rotation3D<Scalar>::invJacobian(Matrix<Scalar> const& __x) const{
- return _matrix.transpose();
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- Rotation3D<Scalar>::invJacobian(Matrix<Scalar> const& __x,
- size_t __i) const{
- Matrix<Scalar> 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<class Scalar>
- inline Matrix<Scalar>
- Rotation3D<Scalar>::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 <cstdlib>
-
-namespace meow{
- template<class Entry>
- inline size_t
- Matrix<Entry>::index(size_t __r, size_t __c) const{
- return __r * _cols + __c;
- }
-
-
- template<class Entry>
- inline
- Matrix<Entry>::Matrix():
- _rows(0),
- _cols(0),
- _entries(0){
- }
-
-
- template<class Entry>
- inline
- Matrix<Entry>::Matrix(Matrix const& __m):
- _rows(__m._rows),
- _cols(__m._cols),
- _entries(__m._entries){
- }
-
-
- template<class Entry>
- inline
- Matrix<Entry>::Matrix(size_t __rows, size_t __cols, Entry const& __entry):
- _rows(__rows),
- _cols(__cols),
- _entries(__rows * __cols, __entry){
- }
-
-
- template<class Entry>
- inline
- Matrix<Entry>::~Matrix(){
- }
-
- template<class Entry>
- inline Matrix<Entry>&
- Matrix<Entry>::copy(Matrix const& __m){
- _rows = __m._rows;
- _cols = __m._cols;
- _entries = __m._entries;
- }
-
-
- template<class Entry>
- inline bool
- Matrix<Entry>::valid() const{
- return (rows() > 0 && cols() > 0);
- }
-
- template<class Entry>
- inline size_t
- Matrix<Entry>::rows() const{
- return _rows;
- }
- template<class Entry>
- inline size_t
- Matrix<Entry>::cols() const{
- return _cols;
- }
-
-
- template<class Entry>
- inline size_t
- Matrix<Entry>::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<class Entry>
- inline Entry const&
- Matrix<Entry>::entry(size_t __i, size_t __j) const{
- return _entries[index(__i, __j)];
- }
-
-
- template<class Entry>
- inline Entry const&
- Matrix<Entry>::entry(size_t __i, size_t __j, Entry const& __entry){
- _entries[index(__i, __j)] = __entry;
- return entry(__i, __j);
- }
-
-
- template<class Entry>
- inline void
- Matrix<Entry>::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<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::subMatrix(size_t __rFirst, size_t __rLast,
- size_t __cFirst, size_t __cLast) const{
- if(__rFirst > __rLast || __cFirst > __cLast)
- return Matrix<Entry>();
- 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<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::row(size_t __row) const{
- return subMatrix(__row, __row, 0, cols() - 1);
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::col(size_t __col) const{
- return subMatrix(0, rows() - 1, __col, __col);
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::positive() const{
- return *this;
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::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<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::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<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::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<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::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<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::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<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::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<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::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<class Entry>
- inline Matrix<Entry>&
- Matrix<Entry>::identitied(){
- copy(identity());
- return (*this);
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::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<class Entry>
- inline Matrix<Entry>&
- Matrix<Entry>::transposed(){
- copy(transpose());
- return (*this);
- }
-
-
- template<class Entry>
- inline Matrix<Entry>&
- Matrix<Entry>::operator=(Matrix const& __m){
- return copy(__m);
- }
-
-
- template<class Entry>
- inline Entry const&
- Matrix<Entry>::operator()(size_t __i, size_t __j) const{
- return entry(__i, __j);
- }
-
-
- template<class Entry>
- inline Entry&
- Matrix<Entry>::operator()(size_t __i, size_t __j){
- return _entries[index(__i, __j)];
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::operator+() const{
- return positive();
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::operator-() const{
- return negative();
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::operator+(Matrix const& __m) const{
- return add(__m);
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::operator-(Matrix const& __m) const{
- return sub(__m);
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::operator*(Matrix const& __m) const{
- return mul(__m);
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::operator*(Entry const& __s) const{
- return mul(__s);
- }
-
-
- template<class Entry>
- inline Matrix<Entry>
- Matrix<Entry>::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 <cstdlib>
-
-namespace meow{
- template<class Scalar>
- inline
- BallProjection<Scalar>::BallProjection(size_t __dimension):
- Transformation(__dimension, 1, __dimension, 1, 1),
- _dimension(__dimension),
- _radius(1){
- }
-
-
- template<class Scalar>
- inline
- BallProjection<Scalar>::BallProjection(size_t __dimension,
- Scalar const& __radius):
- Transformation(__dimension, 1, __dimension, 1, 1),
- _dimension(__dimension),
- _radius(1){
- radius(__radius);
- }
-
-
- template<class Scalar>
- inline Scalar
- BallProjection<Scalar>::parameter(size_t __i) const{
- return radius();
- }
-
-
- template<class Scalar>
- inline Scalar
- BallProjection<Scalar>::parameter(size_t __i, Scalar const& __s){
- return radius(__s);
- }
-
-
- template<class Scalar>
- inline Scalar
- BallProjection<Scalar>::radius() const{
- return _radius;
- }
-
-
- template<class Scalar>
- inline Scalar
- BallProjection<Scalar>::radius(Scalar const& __radius){
- _radius = __radius;
- return radius();
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- BallProjection<Scalar>::transformate(Matrix<Scalar> const& __x) const{
- Matrix<Scalar> 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<class Scalar>
- inline Matrix<Scalar>
- BallProjection<Scalar>::jacobian(Matrix<Scalar> 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<Scalar> 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<class Scalar>
- inline Matrix<Scalar>
- BallProjection<Scalar>::jacobian(Matrix<Scalar> const& __x,
- size_t __i) const{
- Matrix<Scalar> 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<class Scalar>
- inline
- PhotoProjection<Scalar>::PhotoProjection(size_t __dimension):
- Transformation(__dimension, 1, __dimension, 1, 0),
- _dimension(__dimension),
- _focal(1){
- }
-
-
- template<class Scalar>
- inline
- PhotoProjection<Scalar>::PhotoProjection(size_t __dimension,
- Scalar const& __focal):
- Transformation(__dimension, 1, __dimension, 1, 0),
- _dimension(__dimension),
- _focal(1){
- focal(__focal);
- }
-
-
- template<class Scalar>
- inline Scalar
- PhotoProjection<Scalar>::parameter(size_t __i) const{
- return focal();
- }
-
-
- template<class Scalar>
- inline Scalar
- PhotoProjection<Scalar>::parameter(size_t __i, Scalar const& __s){
- return focal(__s);
- }
-
-
- template<class Scalar>
- inline Scalar
- PhotoProjection<Scalar>::focal() const{
- return _focal;
- }
-
-
- template<class Scalar>
- inline Scalar
- PhotoProjection<Scalar>::focal(Scalar const& __focal){
- _focal = __focal;
- return focal();
- }
-
-
- template<class Scalar>
- inline Matrix<Scalar>
- PhotoProjection<Scalar>::transformate(Matrix<Scalar> const& __x) const{
- Matrix<Scalar> 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<class Scalar>
- inline Matrix<Scalar>
- PhotoProjection<Scalar>::jacobian(Matrix<Scalar> const& __x) const{
- Matrix<Scalar> 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<class Scalar>
- inline Matrix<Scalar>
- PhotoProjection<Scalar>::jacobian(Matrix<Scalar> const& __x,
- size_t __i) const{
- Matrix<Scalar> 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 <algorithm>
-
-#include <cmath>
-
-namespace meow{
-
- template<class T>
- inline T noEPS(T value, T eps){
- T epsp((eps < T(0)) ? -eps : eps);
- return ((value < -epsp || value > epsp)
- ? value
- : T(0));
- }
-
- template<class T>
- inline T normalize(T lower, T upper, T value){
- return (value - lower) / (upper - lower);
- }
-
- template<class T>
- inline T denormalize(T lower, T upper, T _ratio){
- return lower + _ratio * (upper - lower);
- }
-
- template<class T>
- inline T ratioMapping(T l1, T u1, T m1, T l2, T u2){
- return denormalize(l2, u2, normalize(l1, u1, m1));
- }
-
- template<class T>
- inline T inRange(T const& mn, T const& mx, T const& v){
- return std::min(mx, std::max(mn, v));
- }
-
-
- template<class T>
- inline T squ(T const& x){
- return x * x;
- }
-
-
- template<class T>
- inline T cub(T const& x){
- return x * x * x;
- }
-
-
- template<class T>
- inline double average( T const& beg, T const& end, double sigs){
- int N = 0;
- double av = 0;
- for(T it = beg; it != end; it++, N++){
- av += *it;
- }
- av /= N;
- double sig = 0;
- for(T it = beg; it != end; it++){
- sig += (*it - av) * (*it - av);
- }
- sig = sqrt(sig / N);
- double lower = av - sig * sigs, upper = av + sig * sigs;
- double ret = 0, retn = 0;
- for(T it = beg; it != end; it++){
- if(lower <= *it && *it <= upper){
- ret += *it;
- retn++;
- }
- }
- return ret / retn;
- }
-
-
- template<class T>
- inline double average( T const& beg, T const& end, T const& p, double sigs){
- int N = 0;
- double ps = 0;
- for(T it = beg, ip = p; it != end; it++, N++, ip++){
- ps += *ip;
- }
- double av = 0;
- for(T it = beg, ip = p; it != end; it++, ip++){
- av += *it * *ip / ps;
- }
- double sig = 0;
- for(T it = beg, ip = p; it != end; it++, ip++){
- sig += *ip / ps * (*it - av) * (*it - av);
- }
- sig = sqrt(sig);
- double lower = av - sig * sigs, upper = av + sig * sigs;
- double ret = 0, retn = 0;
- for(T it = beg, ip = p; it != end; it++, ip++){
- if(lower <= *it && *it <= upper){
- ret += *it * *ip;
- retn += *ip;
- }
- }
- if(retn <= 1e-10) return av;
- return ret / retn;
- }
-}
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 <cstdio>
-
-namespace meow{
- template<size_t sid>
- 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<sid>(name);
- if(ret->read(__f, __binary, fg) == false){
- delete ret;
- ret = NULL;
- }
- return ret;
- }
-
-
- template<size_t sid>
- inline ObjPort::bool write(FILE* __f, bool __binary,
- ObjBase* __obj, unsigned int __fg){
- std::string name = Selector<sid>::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 <map>
-#include <queue>
-
-
-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<std::string, size_t>::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<size_t, Property*>::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<size_t, Property*>::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<size_t, Property*>::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<std::string, size_t>::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<size_t, Property*>::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<std::string, size_t>::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 <cstdio>
-#include <cstdlib>
-#include <cstdarg>
-#include <cstring>
-
-#include <string>
-#include <stack>
-
-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;
- }
-}