diff options
author | cathook <b01902109@csie.ntu.edu.tw> | 2014-04-22 02:22:21 +0800 |
---|---|---|
committer | cathook <b01902109@csie.ntu.edu.tw> | 2014-04-22 02:22:21 +0800 |
commit | a18df7f42f62932001cbb1c61c458abaf5d8bace (patch) | |
tree | 9e350f8f32a50ee76636ae6cb94e925a832239f6 | |
parent | 1817d739e89b1d4c1c09d5f553ce5068fab0e4d7 (diff) | |
download | meow-a18df7f42f62932001cbb1c61c458abaf5d8bace.tar meow-a18df7f42f62932001cbb1c61c458abaf5d8bace.tar.gz meow-a18df7f42f62932001cbb1c61c458abaf5d8bace.tar.bz2 meow-a18df7f42f62932001cbb1c61c458abaf5d8bace.tar.lz meow-a18df7f42f62932001cbb1c61c458abaf5d8bace.tar.xz meow-a18df7f42f62932001cbb1c61c458abaf5d8bace.tar.zst meow-a18df7f42f62932001cbb1c61c458abaf5d8bace.zip |
重寫readme
-rw-r--r-- | README.asciidoc | 600 | ||||
-rw-r--r-- | README.html | 1192 | ||||
-rw-r--r-- | description.asciidoc | 34 | ||||
-rw-r--r-- | meowpp/Usage.h | 123 | ||||
-rw-r--r-- | meowpp/dsa/DisjointSet.h | 71 | ||||
-rw-r--r-- | meowpp/dsa/KD_Tree.h | 120 | ||||
-rw-r--r-- | meowpp/dsa/MergeableHeap.h | 131 | ||||
-rw-r--r-- | meowpp/dsa/MergeableHeap.hpp | 2 | ||||
-rw-r--r-- | meowpp/dsa/SegmentTree.h | 100 | ||||
-rw-r--r-- | meowpp/dsa/SplayTree.h | 241 | ||||
-rw-r--r-- | meowpp/dsa/SplayTree.hpp | 2 | ||||
-rw-r--r-- | meowpp/utility.h | 121 | ||||
-rwxr-xr-x | readme_generate.py | 52 |
13 files changed, 1670 insertions, 1119 deletions
diff --git a/README.asciidoc b/README.asciidoc index d64ab13..9998a00 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -2,33 +2,35 @@ == Description -一個不需要, 也不建議先compile成obj files的templates. +一個不需要, 也不應該先compile成obj files的templates. -TIP: *README.html* is more beautiful. +.Links +* https://github.com/cathook/meow[GitHub] +* http://www.csie.ntu.edu.tw/~b01902109/readme/template_meow/README.html[README.html] == File Tree === *meowpp/* C++ templates -[width="90%"] * *utility.h* some useful functions, - `stringPringf()` , `stringReplace` , `cstringEndWith` , + `stringPringf()` , `stringReplace()` , `cstringEndWith()` , `debugPrintf()` , `messagePrintf()` , `constant PI` , - `noEPS()` , `normalize()` , `denormalize` , - `ratioMapping` , `inRange()` , `squ()` , `average()` + `noEPS()` , `normalize()` , `denormalize()` , + `ratioMapping()` , `inRange()` , `squ()` , `average()` * *Usage.h* `class Usage` * *colors/* Color splces and transformer ** *RGB.h* `class RGBi` , `class RGBf` -** *YUV.h* `class YUVi` , `class YUVf` , `RGB_to_YUV()` , `YUV_to_RGB` -** *HSL.h* `class HSLf` , `RGB_to_HSL()` , `HSL_to_RGB` , - `YUV_to_HSL()` , `HSL_to_YUV` -** *HSV.h* `class HSVf` , `RGB_to_HSV()` , `HSV_to_RGB` , - `YUV_to_HSV()` , `HSV_to_YUV` , - `HSL_to_HSV()` , `HSV_to_HSL` +** *YUV.h* `class YUVi` , `class YUVf` , `RGB_to_YUV()` , `YUV_to_RGB()` +** *HSL.h* `class HSLf` , `RGB_to_HSL()` , `HSL_to_RGB()` , + `YUV_to_HSL()` , `HSL_to_YUV()` +** *HSV.h* `class HSVf` , `RGB_to_HSV()` , `HSV_to_RGB()` , + `YUV_to_HSV()` , `HSV_to_YUV()` , + `HSL_to_HSV()` , `HSV_to_HSL()` * *dsa/* Data Structures and Algorithms ** *DisjointSet.h* `class DisjointSet` -** *Heaps.h* `class MergeableHeap` -** *KD_Tree.h* `class KD_Tree` -** *SplayTree.h* `class SplayTree` +** *Heaps.h* `class MergeableHeap<Element>` +** *KD_Tree.h* `class KD_Tree<Vector, Scalar>` +** *SegemenTree.h* `class SegmentTree<Value>` +** *SplayTree.h* `class SplayTree<Key, Value>` * *oo/* ** *Register_Implement.h* `class RegisterInterface` , `class ImplementInterface` @@ -36,58 +38,64 @@ TIP: *README.html* is more beautiful. == Structures/Classes/Functions +:b: | === meow:: *Functios* in utility.h [options="header",width="100%",cols="1>s,5<,1<,10<",grid="rows"] |============================================================== -|Name | Parameters | Return Type | Description -|stringPrintf |(char const * fmt, ...)|std::string | -Format print to C++ string and return it -|stringReplace |(std::string str, + -std::string const& from, + -std::string const& to) | std::string | -Return a string like `str`, but all `from` be replaced by `to` -|cstringEndWith |(char const* str, int n, ...) | bool | -Return whether `str` is end with one of the c-string you specify in +|Name | Parameters | Return_Type | Description +|stringPrintf |(char const * `fmt`, ...) | std::string +|Format print to C++ string and return it +|stringReplace |(std::string `str`, + + +std::string const& `from`, + + +std::string const& `to`) | std::string +|Return a string like `str`, but all `from` be replaced by `to` +|cstringEndWith |(char const* `str`, + +int `n`, ...) | bool +|Return whether `str` is end with one of the c-string you specify in the parameters or not -|debugPrintf |(char const* fmt, ...) | void| -Print debug message (file name, line number, ...etc) when `DEBUG` is +|debugPrintf |(char const* `fmt`, ...) | void +|Print debug message (file name, line number, ...etc) when `DEBUG` is defined -|messagePrintf |(int level_change, char const* fmt, ...) | void| -階層式的訊息輸出 -|noEPS |(double value, double eps = 1e-9) | double | +|messagePrintf |(int `level_change`, + +char const* `fmt`, ...) | void +|階層式的訊息輸出 +|noEPS |(double `value`, double `eps` = 1e-9) | double | 如果abs(輸入的數值) < eps, 則回傳0, 否則回傳輸入的數值 -|normalize |(double lower, double upper, + -double value) | double | -(value - lower) / (upper - lower) -|denormalize |(double lower, double upper, + -double ratio) | double | -lower + (upper - lower) * ratio -|ratioMapping |(double l1, double u1, + -double m1, double l2, + -double u2) -| double | -denormalize(l2, u2, normalize(l1, u1, m1)) -|inRange<T> |(T const& mn, T const& mx, + -T const& v) | T | -std::max(mn, std::min(mx, v)) -|squ<T> |(T const& x) | T| -x * x -|average<T>|(T const& beg, T const& end, + -double sigs)| T| +|normalize |(double `lower`, double `upper`, + + double value) +| double | `(value - lower) / (upper - lower)` +|denormalize |(double `lower`, double `upper`, + + + double `ratio`) | double | `lower + (upper - lower) * ratio` +|ratioMapping |(double `l1`, double `u1`, + + +double `m1`, double `l2`, + +double `u2`) +| double | `denormalize(l2, u2, normalize(l1, u1, m1))` +|inRange<T> |(T const& `mn`, T const& `mx`, + + T const& `v`) | T | +`std::max(mn, std::min(mx, v))` +|squ<T> |(T const& `x`) | T| `x * x` +|average<T>|(T const& `beg`, T const& `end`, + + double `sigs`)| T| 只將 `sigs` 個標準差以內的數據拿來取平均 -|average<T>|(T const& beg, T const& end, + -T const& p, double sigs)| T| -同上, 不過這次用 `p` 來加權平均 +|average<T>|(T const& `beg`, T const& `end`, + + + T const& `p`, double `sigs`)| T| 同上, 不過這次用 `p` 來加權平均 |============================================================== [NOTE] -`stringReplace()` 不是用什麼好方法寫的因此執行效率很低請別虐待它. + -額外附贈一個 `const double PI = 3.141592653589......` +==================================== +* `stringReplace()` 不是用什麼好方法寫的因此執行效率很低請別虐待它. +* 額外附贈一個 `const double PI = 3.141592653589......` +==================================== ''' === meow:: *Usage* (C++ Class) -.Description +==== Description `Usage` 是用來分析argc, argv和輸出usage document的class. argc, argv的部份, 有以下規則 @@ -97,7 +105,7 @@ argc, argv的部份, 有以下規則 反之則一定要設定. 另外可以給定value的預設值以及哪些value是可接受的 * `<value>` 其他, 一律視為process arguments -.Methods +==== Methods * `Usage(String const& _name)` + 建構子, 所有說明文字中 *<name>* 都會被代換成 `_name` * `Usage()` + @@ -115,8 +123,8 @@ String const& value_type, String const& value_default, bool must)` + " *是否一定要設定此參數* " , 回傳表成功與否 *(bool)* * `addOptionValueAccept(unsigned char option, String const& value, String const& description)` + -針對某個option, 新增一個可接受的額外選項 (如果某個option從頭到尾都沒有 -新增可接受的選項, 則視為不限制), 回傳成功與否 *(bool)* +針對某個option, 新增一個可接受的額外選項 (如果某個option從頭到尾都 +沒有新增可接受的選項, 則視為不限制), 回傳成功與否 *(bool)* * `hasOptionSetup(unsigned char option)` + 回傳是否有此選項 *(bool)* * `getOptionValuesCount(unsigned char option)` + @@ -139,9 +147,12 @@ String const& value, String const& description)` + 輸入argv, argc, 回傳是否沒有錯誤發生 *(bool)* , 其中如果有錯誤發生, 且 `errmsg != NULL` 則會將錯誤訊息寫入之 -NOTE: `String` 是 `std::string` . + -`Strings` 是 `std::vector< std::string> >`. + -如果沒有寫回傳什麼, 就是回傳 `void` +[NOTE] +================================== +* `String` 是 `std::string` . +* `Strings` 是 `std::vector< std::string> >`. +* 如果沒有寫回傳什麼, 就是回傳 `void` +================================== ''' @@ -163,220 +174,287 @@ which will return the pointer to the corresponding class. ''' === meow:: *DisjointSet* (C++ class) -.Description -`DisjointSet` is a lighting data structure that maintain N numbers from -*0* to *N-1* with methods below: - -[options="header",width="100%",cols="1>,1<s,5<,1<,1<,10<",grid="rows"] -|======================================================================= -|Const?|Name| Parameters| Return Type| Time Complexity| Description -|const|root|(size_t number)|size_t|very fast| -Return the *group id* of the number given -|const|size|()|size_t|very fast| -Return *N* -||reset|(size_t N)|void|very fast| -Clean and initalize -||merge|(size_t number1, + -size_t number2)|size_t|very fast| -*Union* the group contains number1 and the group contains number2. -Return the merged group id -|======================================================================= -NOTE: *very fast* means that you can consider it as constant time. +==== Description +`DisjointSet` 是個*輕量級Data Dtructure*, 用來維護一堆互斥集的資訊. +相關資料可參考 +link:http://www.csie.ntnu.edu.tw/~u91029/DisjointSets.html[演算法筆記] + +==== Support Methods + +[options="header",width="100%",cols="1>m,3>s,7<,3<,3^,20<",grid="rows"] +|===================================================================== +|Const?|Name | Parameters | Return_Type| Time_Complexity| Description +|const |root |(size_t `number`) | size_t | very fast +|回傳 `number` 所在的 *集合的編號* (0~N-1) +|const |size |() | size_t | very fast +|回傳 *總集合大小* +| |reset|(size_t `N`) | void | O(N) +| 清空, 並且設定總集合大小為 `N` +| |merge|(size_t `number1`, + +size_t `number2`)| size_t | very fast +| 將 `number1` 所在的集合 跟 `number2` 所在的集合 *合併*, +並回傳合併後新的集合的編號 +|===================================================================== + +[NOTE] +======================================== +* *very fast* 表示它算的真的超級快, 可以視為常數時間. +* 預設值所有 `number` 所在的集合的編號就是 `number` 本身, +即沒有任兩個數在同一個set裡面 +======================================== ''' -=== meow:: *MergeableHeap<Key, Value>* (C++ class) -.Description -MergeableHeap is a kind of maximum-heap with a special method `merge`, -which will merge another MergeableHeap into itself in O(logN) time. - -.Template Request -* `Key` should has `operator<` - -.Support methods -* N <- number of elements in the heap -* M <- number of elements in the other heap if need -[options="header",width="100%",cols="1>,1<s,3<,1<,1<,10<",grid="rows"] -|======================================================================= -|Const?|Name| Parameters| Return Type| Time Complexity| Description -||operator= | (MergeableHeap const&)| *this | O(N) -| Copy operator. -||moveTo | (MergeableHeap*) | void | O(M) -| Transform the this->data to the heap specified in parameters -|const|top | () | Element | O(1) -| Return the maximum element in the heap. -|const|size | () | size_t | O(1) -| Return the number of elements in the heap. -|const|empty| () | bool | O(1) -| Return whether the heap is empty or not. -||push |(Element) |void | O(log N) -| Add a element into the heap -||pop |() |void | O(log N) -| Delete the maximum element from the heap -||merge |(MergeableHeap*) |void | O(log M) -| Merge the specified MergeableHeap(with size=M) into itself -||clear |() |void | O(N) -| Delete all elements from the heap -|======================================================================= - -WARNING: Consider there are two MergeableHeap `A` and `B`. + -`B` will become empty after you call `A.merge(&B)`. + -The data in `B` will override by data in `A` and `A` will become empty after -you call `A.moveTo(&B)` +=== meow:: *MergeableHeap<Element>* (C++ class) +==== Description +一個用 *左偏樹* 實作的 *Maximum-Heap* , 除了原本heap有的功能外, +還支援 `merge`, `split` 等功能 + +==== Template Class Operators Request +[options="header",width="70%",cols="1>m,1<,3<s,5<,3<,15<",grid="rows"] +|===================================================================== +|Const?|Typename| Operator | Parameters | Return_Type| Description +|const |Element |operator< |(Element `v`)| bool | 大小比較 +|===================================================================== + +==== Support Methods + +* N <- `this` 中擁有的資料數 + +[options="header",width="100%",cols="1>m,2>s,7<,3<,3^,20<",grid="rows"] +|===================================================================== +|Const?|Name | Parameters | Return_Type| Time_Complexity| Description +||moveTo|(MergeableHeap* `h`)|void|O(M) +|將 `this` 的資料複寫到 `h` 上面, 同時清空自己, +時間複雜度中的M是 `h` 所擁有的資料數 +|const|top|()|Element const&|O(1) +|回傳最大的那個 `Element` +|const|size|()|size_t|O(1) +|回傳 `this` 中擁有的資料數 +|const|empty|()|bool|O(1) +|回傳 `this` 是否為空 +||push|(Element const& `e`)|void|O(logN) +|將 `e` 加入 +||pop|()|void|O(logN) +|將最大的 `Element` 移除 +||clear|()|void|O(N) +|將資料清空 +||merge|(MergeableHeap* `heap2`)|void|O(logN+logM) +|將 `heap2` 的資料統統加到 `this` 中, 並且清空 `heap2` +時間複雜度中的M是 `heap2` 的資料數 +|============================================== +[WARNING] +============================================== +* 假設現在有兩個MergeableHeap `A` 和 `B`, 則: +** 執行 `A.merge(&B)` 後 `B` 會變成空的 +** 執行 `B.moveTo(&A)` 後 `B` 會變成空的, `A` 原本擁有的資料也會覆蓋掉 +============================================== ''' + === meow:: *KD_Tree<Vector, Scalar>* (C++ class) -.Description -`KD_Tree` is *K-dimension tree*, which is a multiple set contain lots of -vector with K dimension. - -.Template Request -* `Vector` should has `operator[]` to allow the KD_Tree, `operator<` to -compare when two vector are point to the same place, `operator==` -access the k-dimensions -* `Scalar` should has `operator*`, `operator+`, `operator<` - -.Support Methods -* N <- numbers of element in the kd-tree -* K <- dimensions -* `Vector` is the tyepname of the vector -* `Vectors` is the typename of the std::vector<Vector> -[options="header",width="100%",cols="1>,1<s,5<,1<,2<,10<",grid="rows"] -|======================================================================= -|Const?|Name| Parameters| Return Type| Time Complexity| Description -|const|root|(size_t number)|size_t|very fast| -||insert|(Vector const& v)|void|O(1)|Insert a vector -||erase |(Vector const& v)|bool|O(N*x)| Find a vector which is the same -as `v` and remove it from the KD_Tree, `x` in the Big-O time complex -is cost by `Vector::operator==`. -|| build|()|void|O(KN logN) if need | Build the data structure if need. -|| forceBuild|()|void|O(KN logN) | Build the data structure(the `insert()` -method will not build the data structure immediately) -|const|query|(Vector const& v, int k)|Vectors|O(kN ^1-1/k^ ) | -Using Euclidean-Distance to find the 1st to k-th nearest neighbor from `v` . -And return; -||clear|()|O(1)|Clear all data -||reset|(size_t dimension)|O(1)|Clear all data and then -set the this->dimension be `dimension` -|======================================================================= -NOTE: O(kN ^1-1/k^ ) is reference from wiki. + -`query()` and `rangeQuery()` will run `build()` first if you called `insert()` -before call them. And `build()` is very slow, so you should not use this class -as a dynamic tree +==== Description +`KD_Tree` 全名k-dimension tree, 用來維護由 *N個K維度向量所成的集合*, +並可於該set中查找 *前i個離給定向量最接近的向量* + +==== Template Class Operators Request +[options="header",width="70%",cols="1>m,1<,3<s,5<,3<,15<",grid="rows"] +|===================================================================== +|Const?|Typename| Operator | Parameters | Return_Type| Description +|const | Vector|operator[] |(size_t `n`) | Scalar | 取得第 `n` 維度量 +|const | Vector|operator< |(Vector `v`) | bool | 權重比較 +|const | Scalar|operator* |(Scalar `s`) | Scalar | 相乘 +|const | Scalar|operator+ |(Scalar `s`) | Scalar | 相加 +|const | Scalar|operator- |(Scalar `s`) | Scalar | 相差 +|const | Scalar|operator< |(Scalar `s`) | bool | 大小比較 +|===================================================================== + +==== Custom Type Definitions +* `Vectors` <- `std::vector<Vector>` + +==== Support Methods + +* N <- `this` 中擁有的資料數 +* K <- `this` 資料維度 + +[options="header",width="100%",cols="1>m,3>s,7<,3<,3^,20<",grid="rows"] +|===================================================================== +|Const?|Name | Parameters | Return_Type| Time_Complexity| Description +||insert|(Vector const& `v`)|void| O(1) +|將向量 `v` 加到set中 +||erase|(Vector const& `v`)|bool| O(N) +|將向量 `v` 從set中移除, '~TODO:可以再優化~' +||build|()|void|O(KN logN) or O(1) +|檢查距上一次 `build()` 至今是否有 `insert/erase` 被呼叫, +若有, 重新建樹, 否則不做事 +||forceBuild|()|void|O(KN logN) +|重新建樹 +|const|query|(Vector const& `v`, + +size_t `i`, + +bool `cmp`)|Vectors +|O(KN ^1-1/K^ ) +|於set中找尋距離 `v` 前 `i` 近的向量, 並依照由近而遠的順序排序. +如果有兩個向量 `v1`,`v2` 距離一樣, 且 `cmp` 為 `true` , 則直接依照 +`v1 < v2` 來決定誰在前面. 最後回傳一陣列包含所有解. +||clear|()|void|O(1) +|清空所有資料 +||reset|(size_t `dimension`)|void|O(1) +|清空所有資料並且指定維度為 `dimension` +|===================================================================== + +[NOTE] +======================================== +* 此資料結構只有在 N >> 2 ^K^ 時才比較有優勢, +當 K 逐漸變大時, 所花時間會跟暴搜沒兩樣 +======================================== ''' === meow:: *SplayTree<Key, Value>* (C++ class) -.Description -Like `std::map`, `SplayTree` is an dictionary(key->value). But it has -some extra method, such as `split()`, `merge()`, `keyOffset()`. - -.Data Type -* `Key` is the tyepname of the key -* `Value` is the typename of value -* `SplayTree<Key, Value>:: *Element* ` is a typename which contain -(key->value). It has some methods below: -** `->first ` a constant reference to `Key` -** `->second` a reference to `Value` -** `operator==, operator!=` compare function, check if the two `Element` -is pointer to the same (key->value) - -.Template Request -* `Key` should has `operator<`, `operator+` - -.Support Methods -* N <- numbers of element in the SplayTree -* M <- numbers of element in another SplayTree -[options="header",width="100%",cols="1>,1<s,5<,1<,3^,10<",grid="rows"] -|======================================================================= -|Const?|Name| Parameters| Return Type| Time Complexity| Description -||operator=|(SplayTree const&)| *this | O(N) | copy operator -||moveTo|(SplayTree* t)|void|O(M)| Transform the data in this to `t` -|const|lowerBound|(Key k)|Element|O(logN)| Find the smallest (key->value) -which `k <= key` and return -|const|upperBound|(Key k)|Element|O(logN)| Find the smallest (key->value) -which `k < key` and return -|const|rLowerBound|(Key k)|Element|O(logN)| Find the largest (key->value) -which `key <= k` and return -|const|rUpperBound|(Key k)|Element|O(logN)| Find the largest (key->value) -which `key < k` and return -|const| find|(Key k)|Element|O(logN)| Find the element (key->value) which -`key == k` and return -|const|order|(size_t k)|Element|O(logN)| Find the `k`-th small element. -note that `k` start from zero like a normal C/C++ array. -|const|first|()|Element|O(logN)| Return the smallest element -|const|last|()|Element|O(logN)| Return the largest element -|const|end|()|Element|O(1)|Return an empty element(it can be use to -check if `find()` is successful) -|const|size|()|size_t|O(1)| Return number of elements in the tree -|const|empty|()|bool|O(1)|Return whether the tree is empty -||clear|()|void|O(N)|Clear -||keyOffset|(Key offset)|void|O(1)| Let all the keys in the tree -plus offset -||insert|(Key k, Value v)|bool | O(logN)| Insert an element. -If the tree already has an element with same key, return `false`. -||erase|(Key k)|bool | O(logN)|Erase an element from the tree with -given key. Return `false` if the element not found. -||operator[]|(Key k)|Value|O(logN)|Like `find()` , but it will insert an element -automatic if the corrosponding element not found -||splitOut|(Key const& upper_bound, + -SplayTree* out)|void | O(log N) | Split out all the elements with key -larger than `upper_bound` and store then into `out` -||mergeAfter|(SplayTree* t)|bool|O(logN + logM)|If not all of the elements in this -are smaller than elements in `t`, return `false` , else merge `t` into -itself and return `true`. -||merge|(SplayTree* t)|bool|O(logN + logM)|If all of the elements in this -are smaller than elements in `t` or all of the elements in this larger than -elements in `t` , merge `t` into itself and return `true`. -Else return `false` -|======================================================================= -WARNING: Consider there are two SplayTree `A` and `B`. + -`B` will become empty after you call `A.mergeAfter(&B)` -or `A.merge(&B)` successful. + -The data in `B` will override by data in `A` and `A` will become empty after -you call `A.moveTo(&B)` +==== Description +`SplayTree` 是一種神乎其技的資料結構, 維護一堆 Key->Value . 並且支援 +一些 `std::map` 難以快速實踐的操作, 如 `split` , `merge` , `keyOffset` + +==== Template Class Operators Request +[options="header",width="70%",cols="1>m,1<,3<s,5<,3<,15<",grid="rows"] +|===================================================================== +|Const?|Typename| Operator| Parameters | Return_Type| Description +|const |Key |operator+|(Key `k`) | Key | 相加 +|const |Key |operator<|(Key `k`) | bool | 大小比較 +| |Key |'Key' |(int `n`) | | 建構子, `n` 永遠是0 +| |Value | 'Value' |( ) | | 建構子 +|===================================================================== + +==== Custom Type Definitions + +* `Element` -> 用來當作回傳資料的媒介 +** 重定義 `operator->()` 到 `std::pair<Key const&, Value&>*` +** 重定義 `operator*()` 到 `std::pair<Key const&, Value&>&` +** 有 `operator==` , `operator!=`, `operator=` 可用 +** 可以直接用 `(*e).second = some_value` 來改變SplayTree中的資料 + +==== Support Methods + +* N <- `this` 中擁有的資料數 +* M <- `tree2` 中擁有的資料數 + +[options="header",width="100%",cols="1>m,3>s,7<,3<,3^,20<",grid="rows"] +|===================================================================== +|Const?|Name | Parameters | Return_Type| Time_Complexity| Description +||moveTo|(SplayTree* `tree2`)|void|O(M) +|將 `this` 的資料複寫到 `tree2` 上面, 同時清空自己, +時間複雜度中的M是 `tree2` 所擁有的資料數 +|const|lowerBound|(Key const& `k`)|Element|O(logN) +|找出第一個(最小的) Element且 `k` <= 它的 Key, 並且回傳之. +找不到的話回傳 `this->end()` +|const|lowerBound|(Key const& `k`)|Element|O(logN) +|找出第一個(最小的) Element且 `k` < 它的 Key, 並且回傳之. +找不到的話回傳 `this->end()` +|const|lowerBound|(Key const& `k`)|Element|O(logN) +|找出第一個(最小的) Element且 `k` >= 它的 Key, 並且回傳之. +找不到的話回傳 `this->end()` +|const|lowerBound|(Key const& `k`)|Element|O(logN) +|找出第一個(最小的) Element且 `k` > 它的 Key, 並且回傳之. +找不到的話回傳 `this->end()` +|const|find|(Key const& `k`)|Element|O(logN) +|找出 Key= `k` 的Elemenet 並回傳. 找不到的話回傳 `this->end()` +|const|order|(size_t `ord`)|Element|O(logN) +|將Elements依照Key由小到大排序, 回傳第 `ord` 個Element (由0算起). +其中如果 `ord` > N - 1, 則會回傳 `this->last()` +|const|first|(size_t `ord`)|Element|O(logN) +|回傳Key最小的Element, 如果SplayTree為空, 則回傳 `this->end()` +|const|last|(size_t `ord`)|Element|O(logN) +|回傳Key最大的Element, 如果SplayTree為空, 則回傳 `this->end()` +|const|end|()|Element|O(1) +|回傳一個指向NULL的Element, 以供 `find` , `order` , `first` +, `last` 等判斷是否有找到相對應的Element +|const|size|()|size_t|O(1)| 回傳資料數 +|const|size|()|bool|O(1)| 回傳是否為空 +||clear|()|void|O(N)| 清空資料 +||keyOffset|(Key const& `delta`)|void|O(1) +|將所有Element的Key同加上 `delta` +||insert|(Key const& `key`, + +Value const& `value`)|bool|O(logN) +|檢查是否已有Element的Key 為 `key`, 若有則回傳 `false` , 否則將 +一個 (Key -> Value) = (`key` -> `value`)的Element加入, 並回傳 `true` +將所有Element的Key同加上 `delta` +||erase|(Key const& `key`)|bool|O(logN) +|檢查是否已有Element的Key 為 `key`, 若有則刪除之, 並回傳 `true`, +否則則回傳 `false` +||operator[]|(Key const& `key`)|Value&|O(logN) +|檢查是否已有Element的Key 為 `key`, 若有則回傳相對應的Value的Reference +否則先執行 `insert(key, Value())` 再回傳相對應的Reference +||splitOut|(Key const& `upper_bound`, + +SplayTree* `tree2`)|void +|O(logN) + O(M) +|將 `tree2` 清空, 再將所有Key > `upper_bound` 的Element都丟到 `tree2` +||mergeAfter|(SplayTree* `tree2`)|void|O(logN) + O(logM) +|檢查是否 `this` 中的 Key 都小於 `tree2` 中的Key, 是的話把 `tree2` +中的 Element 都搬到 `this` , 同時清空 `tree2` , 回傳 `true`. 否則 +回傳 `false` +||merge|(SplayTree* `tree2`)|void|O(logN) + O(logM) +|檢查是否 `this` 中的 Key 都小於 `tree2` 中的Key 或者 +是否 `this` 中的 Key 都大於 `tree2` 中的Key, 是的話把 `tree2` +中的 Element 都搬到 `this` , 同時清空 `tree2` , 回傳 `true`. 否則 +回傳 `false` +|===================================================================== + +[NOTE] +======================================== +* 假設現在有兩個SplayTree `A` 和 `B`, 則: +** 執行 `B.moveTo(&A)` 後 `B` 會變成空的, `A` 原本擁有的資料也會覆蓋掉 +** 執行 `A.merge(&B)` 或 `A.mergeAfter(&B)` 後 +如果檢查發現確實可以merge, 則之後 `B` 會變成空的 +======================================== ''' -=== meow:: *SegmentTree<Value>* (C++ class) -.Description -`SegmentTree` is a data structure that can maintain an array, and -support *range update* , *range query* - -.Template Request -* `Value` should has -** `operator+(Value)` offset -** `operator|(Value)` merge two nodes -** `operator*(size_t)` ?? - -For example, if you want to maintain *range minimum* - -* `Value::operator+(Value v2)` will be `this->realValue + v2.realValue` -* `Value::operator|(Value v2)` will be `std::min(this->realValue, v2.realValue)` -* `Value::operator*(size_t n)` will be `this->realValue` - -If you want to maintain *range sum* - -* `Value::operator+(Value v2)` will be `this->realValue + v2.realValue` -* `Value::operator|(Value v2)` will be `this->realValue + v2.realValue)` -* `Value::operator*(size_t n)` will be `this->realValue * n` - -.Support methods -* N <- array size -[options="header",width="100%",cols="1>,1<s,3<,1<,1<,10<",grid="rows"] -|======================================================================= -|Const?|Name| Parameters| Return Type| Time Complexity| Description -||reset|(size_t N)|void|O(1)| -Clear and reset the array size to N (from `0` to `N - 1`) -|const|query|(ssize_t __first, ssize_t __last)|Value|O(logN)| -Range query -||override|(ssize_t __first, ssize_t __last, Value const& __value)|void| -O(logN)| Let the element in the array index from `__first` to `__last` -be `__value` -||offset|(ssize_t __first, ssize_t __last, Value const& __value)|void| -O(logN)| Let the element in the array index from `__first` to `__last` -plus `__value` -|======================================================================= -''' +=== meow:: *SegmentTree<Value>* (C++ class) +==== Description +維護一個陣列, 並且讓user可以有區間查詢, 區間修改的小東東 + +==== Template Class Operators Request +[options="header",width="70%",cols="1>m,1<,3<s,5<,3<,15<",grid="rows"] +|===================================================================== +|Const?|Typename| Operator | Parameters |Return_Type| Description +|const |Value |operator+ |(Value `v`)|Value | 相加(位移) +|const |Value |operator* |(size_t `n`)|Value | 每個Value都一樣, +長為 `n` 的區間的值 +|const |Value |operator{b}|(Value `v`)|Value | 區間合併後的值 +|===================================================================== + +* 若要維護區間最小值, 即每次都是詢問範圍 `[a, b]` 的最小值, 則可以定義 +** `operator+` 為 '回傳相加值' +** `operator*` 為 '回傳*this' +** `operator|` 為 '回傳std::min(*this, v)' +* 若要維護區間最總和, 即每次都是詢問範圍 `[a, b]` 的總和, 則可以定義 +** `operator+` 為 '回傳相加值' +** `operator*` 為 '回傳(*this) * n' +** `operator|` 為 '回傳相加值' + +==== Support Methods + +* N <- `this` 所維護的陣列長度 + +[options="header",width="100%",cols="1>m,2>s,7<,3<,3^,20<",grid="rows"] +|===================================================================== +|Const?|Name | Parameters | Return_Type| Time_Complexity| Description +||reset|(size_t `size`)|void|O(1) +|將資料清空且設定維護範圍是 `0~size - 1` 其中時間複雜度確切多少未知 +要看 `std::vector::resize()` 的效率 +|const|query|(ssize_t `first`, + +ssize_t `last`)|Value|O(logN) +|回傳區間 `[first,last]` (邊界都含) 的區間值 +||override|(ssize_t `first`, + +ssize_t `last`, + +Value const& `value`) +|void|O(logN) +|將區間 `[first,last]` 全部都設定成 `value` +||offset|(ssize_t `first`, + +ssize_t `last`, + +Value const& `delta`) +|void|O(logN) +|將區間 `[first,last]` 全部都加上 `delta` +|============================================== diff --git a/README.html b/README.html index e629055..b2a3db3 100644 --- a/README.html +++ b/README.html @@ -352,8 +352,8 @@ body { margin-top: 1em;
}
-.paragraph p, li, dd, .content { max-width: 90%; }
-.admonitionblock { max-width: 85%; }
+.paragraph p, li, dd, .content { max-width: 100%; }
+.admonitionblock { max-width: 95%; }
div.sectionbody div.ulist > ul > li {
list-style-type: square;
@@ -685,15 +685,19 @@ asciidoc.install(2); <div class="sect1">
<h2 id="_description">Description</h2>
<div class="sectionbody">
-<div class="paragraph"><p>一個不需要, 也不建議先compile成obj files的templates.</p></div>
-<div class="admonitionblock">
-<table><tr>
-<td class="icon">
-<div class="title">Tip</div>
-</td>
-<td class="content"><strong>README.html</strong> is more beautiful.</td>
-</tr></table>
-</div>
+<div class="paragraph"><p>一個不需要, 也不應該先compile成obj files的templates.</p></div>
+<div class="ulist"><div class="title">Links</div><ul>
+<li>
+<p>
+<a href="https://github.com/cathook/meow">GitHub</a>
+</p>
+</li>
+<li>
+<p>
+<a href="http://www.csie.ntu.edu.tw/~b01902109/readme/template_meow/README.html">README.html</a>
+</p>
+</li>
+</ul></div>
</div>
</div>
<div class="sect1">
@@ -705,10 +709,10 @@ asciidoc.install(2); <li>
<p>
<strong>utility.h</strong> some useful functions,
- <span class="monospaced">stringPringf()</span> , <span class="monospaced">stringReplace</span> , <span class="monospaced">cstringEndWith</span> ,
+ <span class="monospaced">stringPringf()</span> , <span class="monospaced">stringReplace()</span> , <span class="monospaced">cstringEndWith()</span> ,
<span class="monospaced">debugPrintf()</span> , <span class="monospaced">messagePrintf()</span> , <span class="monospaced">constant PI</span> ,
- <span class="monospaced">noEPS()</span> , <span class="monospaced">normalize()</span> , <span class="monospaced">denormalize</span> ,
- <span class="monospaced">ratioMapping</span> , <span class="monospaced">inRange()</span> , <span class="monospaced">squ()</span> , <span class="monospaced">average()</span>
+ <span class="monospaced">noEPS()</span> , <span class="monospaced">normalize()</span> , <span class="monospaced">denormalize()</span> ,
+ <span class="monospaced">ratioMapping()</span> , <span class="monospaced">inRange()</span> , <span class="monospaced">squ()</span> , <span class="monospaced">average()</span>
</p>
</li>
<li>
@@ -728,20 +732,20 @@ asciidoc.install(2); </li>
<li>
<p>
-<strong>YUV.h</strong> <span class="monospaced">class YUVi</span> , <span class="monospaced">class YUVf</span> , <span class="monospaced">RGB_to_YUV()</span> , <span class="monospaced">YUV_to_RGB</span>
+<strong>YUV.h</strong> <span class="monospaced">class YUVi</span> , <span class="monospaced">class YUVf</span> , <span class="monospaced">RGB_to_YUV()</span> , <span class="monospaced">YUV_to_RGB()</span>
</p>
</li>
<li>
<p>
-<strong>HSL.h</strong> <span class="monospaced">class HSLf</span> , <span class="monospaced">RGB_to_HSL()</span> , <span class="monospaced">HSL_to_RGB</span> ,
- <span class="monospaced">YUV_to_HSL()</span> , <span class="monospaced">HSL_to_YUV</span>
+<strong>HSL.h</strong> <span class="monospaced">class HSLf</span> , <span class="monospaced">RGB_to_HSL()</span> , <span class="monospaced">HSL_to_RGB()</span> ,
+ <span class="monospaced">YUV_to_HSL()</span> , <span class="monospaced">HSL_to_YUV()</span>
</p>
</li>
<li>
<p>
-<strong>HSV.h</strong> <span class="monospaced">class HSVf</span> , <span class="monospaced">RGB_to_HSV()</span> , <span class="monospaced">HSV_to_RGB</span> ,
- <span class="monospaced">YUV_to_HSV()</span> , <span class="monospaced">HSV_to_YUV</span> ,
- <span class="monospaced">HSL_to_HSV()</span> , <span class="monospaced">HSV_to_HSL</span>
+<strong>HSV.h</strong> <span class="monospaced">class HSVf</span> , <span class="monospaced">RGB_to_HSV()</span> , <span class="monospaced">HSV_to_RGB()</span> ,
+ <span class="monospaced">YUV_to_HSV()</span> , <span class="monospaced">HSV_to_YUV()</span> ,
+ <span class="monospaced">HSL_to_HSV()</span> , <span class="monospaced">HSV_to_HSL()</span>
</p>
</li>
</ul></div>
@@ -758,17 +762,22 @@ asciidoc.install(2); </li>
<li>
<p>
-<strong>Heaps.h</strong> <span class="monospaced">class MergeableHeap</span>
+<strong>Heaps.h</strong> <span class="monospaced">class MergeableHeap<Element></span>
+</p>
+</li>
+<li>
+<p>
+<strong>KD_Tree.h</strong> <span class="monospaced">class KD_Tree<Vector, Scalar></span>
</p>
</li>
<li>
<p>
-<strong>KD_Tree.h</strong> <span class="monospaced">class KD_Tree</span>
+<strong>SegemenTree.h</strong> <span class="monospaced">class SegmentTree<Value></span>
</p>
</li>
<li>
<p>
-<strong>SplayTree.h</strong> <span class="monospaced">class SplayTree</span>
+<strong>SplayTree.h</strong> <span class="monospaced">class SplayTree<Key, Value></span>
</p>
</li>
</ul></div>
@@ -805,99 +814,104 @@ width:100%; <col style="width:58%;">
<thead>
<tr>
-<th class="tableblock halign-right valign-top" >Name </th>
-<th class="tableblock halign-left valign-top" > Parameters </th>
-<th class="tableblock halign-left valign-top" > Return Type </th>
+<th class="tableblock halign-right valign-top" >Name </th>
+<th class="tableblock halign-left valign-top" > Parameters </th>
+<th class="tableblock halign-left valign-top" > Return_Type </th>
<th class="tableblock halign-left valign-top" > Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>stringPrintf</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(char const * fmt, …)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(char const * <span class="monospaced">fmt</span>, …)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">std::string</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Format print to C++ string and return it</p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>stringReplace</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(std::string str,<br>
-std::string const& from,<br>
-std::string const& to)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(std::string <span class="monospaced">str</span>,<br></p>
+<p class="tableblock">std::string const& <span class="monospaced">from</span>,<br></p>
+<p class="tableblock">std::string const& <span class="monospaced">to</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">std::string</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Return a string like <span class="monospaced">str</span>, but all <span class="monospaced">from</span> be replaced by <span class="monospaced">to</span></p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>cstringEndWith</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(char const* str, int n, …)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(char const* <span class="monospaced">str</span>,<br>
+int <span class="monospaced">n</span>, …)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Return whether <span class="monospaced">str</span> is end with one of the c-string you specify in
the parameters or not</p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>debugPrintf</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(char const* fmt, …)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(char const* <span class="monospaced">fmt</span>, …)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Print debug message (file name, line number, …etc) when <span class="monospaced">DEBUG</span> is
defined</p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>messagePrintf</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(int level_change, char const* fmt, …)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(int <span class="monospaced">level_change</span>,<br>
+char const* <span class="monospaced">fmt</span>, …)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">階層式的訊息輸出</p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>noEPS</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(double value, double eps = 1e-9)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(double <span class="monospaced">value</span>, double <span class="monospaced">eps</span> = 1e-9)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">double</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">如果abs(輸入的數值) < eps, 則回傳0, 否則回傳輸入的數值</p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>normalize</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(double lower, double upper,<br>
-double value)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(double <span class="monospaced">lower</span>, double <span class="monospaced">upper</span>, <br>
+ double value)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">double</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(value - lower) / (upper - lower)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">(value - lower) / (upper - lower)</span></p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>denormalize</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(double lower, double upper,<br>
-double ratio)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(double <span class="monospaced">lower</span>, double <span class="monospaced">upper</span>,
+<br>
+ double <span class="monospaced">ratio</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">double</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">lower + (upper - lower) * ratio</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">lower + (upper - lower) * ratio</span></p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>ratioMapping</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(double l1, double u1,<br>
-double m1, double l2,<br>
-double u2)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(double <span class="monospaced">l1</span>, double <span class="monospaced">u1</span>,
+<br>
+double <span class="monospaced">m1</span>, double <span class="monospaced">l2</span>,<br>
+double <span class="monospaced">u2</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">double</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">denormalize(l2, u2, normalize(l1, u1, m1))</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">denormalize(l2, u2, normalize(l1, u1, m1))</span></p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>inRange<T></strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(T const& mn, T const& mx,<br>
-T const& v)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(T const& <span class="monospaced">mn</span>, T const& <span class="monospaced">mx</span>, <br>
+ T const& <span class="monospaced">v</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">T</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">std::max(mn, std::min(mx, v))</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">std::max(mn, std::min(mx, v))</span></p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>squ<T></strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(T const& x)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(T const& <span class="monospaced">x</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">T</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">x * x</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">x * x</span></p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>average<T></strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(T const& beg, T const& end,<br>
-double sigs)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(T const& <span class="monospaced">beg</span>, T const& <span class="monospaced">end</span>, <br>
+ double <span class="monospaced">sigs</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">T</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">只將 <span class="monospaced">sigs</span> 個標準差以內的數據拿來取平均</p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>average<T></strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(T const& beg, T const& end,<br>
-T const& p, double sigs)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(T const& <span class="monospaced">beg</span>, T const& <span class="monospaced">end</span>,
+<br>
+ T const& <span class="monospaced">p</span>, double <span class="monospaced">sigs</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">T</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">同上, 不過這次用 <span class="monospaced">p</span> 來加權平均</p></td>
</tr>
@@ -908,15 +922,29 @@ T const& p, double sigs)</p></td> <td class="icon">
<div class="title">Note</div>
</td>
-<td class="content"><span class="monospaced">stringReplace()</span> 不是用什麼好方法寫的因此執行效率很低請別虐待它.<br>
-額外附贈一個 <span class="monospaced">const double PI = 3.141592653589......</span></td>
+<td class="content">
+<div class="ulist"><ul>
+<li>
+<p>
+<span class="monospaced">stringReplace()</span> 不是用什麼好方法寫的因此執行效率很低請別虐待它.
+</p>
+</li>
+<li>
+<p>
+額外附贈一個 <span class="monospaced">const double PI = 3.141592653589......</span>
+</p>
+</li>
+</ul></div>
+</td>
</tr></table>
</div>
<hr>
</div>
<div class="sect2">
<h3 id="_meow_strong_usage_strong_c_class">meow:: <strong>Usage</strong> (C++ Class)</h3>
-<div class="paragraph"><div class="title">Description</div><p><span class="monospaced">Usage</span> 是用來分析argc, argv和輸出usage document的class.
+<div class="sect3">
+<h4 id="_description_2">Description</h4>
+<div class="paragraph"><p><span class="monospaced">Usage</span> 是用來分析argc, argv和輸出usage document的class.
argc, argv的部份, 有以下規則</p></div>
<div class="ulist"><ul>
<li>
@@ -937,7 +965,10 @@ argc, argv的部份, 有以下規則</p></div> </p>
</li>
</ul></div>
-<div class="ulist"><div class="title">Methods</div><ul>
+</div>
+<div class="sect3">
+<h4 id="_methods">Methods</h4>
+<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">Usage(String const& _name)</span><br>
@@ -981,8 +1012,8 @@ String const& value_type, String const& value_default, bool must)</span> <p>
<span class="monospaced">addOptionValueAccept(unsigned char option,
String const& value, String const& description)</span><br>
-針對某個option, 新增一個可接受的額外選項 (如果某個option從頭到尾都沒有
-新增可接受的選項, 則視為不限制), 回傳成功與否 <strong>(bool)</strong>
+針對某個option, 新增一個可接受的額外選項 (如果某個option從頭到尾都
+沒有新增可接受的選項, 則視為不限制), 回傳成功與否 <strong>(bool)</strong>
</p>
</li>
<li>
@@ -1052,13 +1083,30 @@ String const& value, String const& description)</span><br> <td class="icon">
<div class="title">Note</div>
</td>
-<td class="content"><span class="monospaced">String</span> 是 <span class="monospaced">std::string</span> .<br>
-<span class="monospaced">Strings</span> 是 <span class="monospaced">std::vector< std::string> ></span>.<br>
-如果沒有寫回傳什麼, 就是回傳 <span class="monospaced">void</span></td>
+<td class="content">
+<div class="ulist"><ul>
+<li>
+<p>
+<span class="monospaced">String</span> 是 <span class="monospaced">std::string</span> .
+</p>
+</li>
+<li>
+<p>
+<span class="monospaced">Strings</span> 是 <span class="monospaced">std::vector< std::string> ></span>.
+</p>
+</li>
+<li>
+<p>
+如果沒有寫回傳什麼, 就是回傳 <span class="monospaced">void</span>
+</p>
+</li>
+</ul></div>
+</td>
</tr></table>
</div>
<hr>
</div>
+</div>
<div class="sect2">
<h3 id="_meow_strong_implementinterface_registerinterface_strong_c_class">meow:: <strong>ImplementInterface/RegisterInterface</strong> (C++ Class)</h3>
<div class="paragraph"><div class="title">Description</div><p>Assume there is a problem which can be solved by different algorithms.
@@ -1090,62 +1138,68 @@ which will return the pointer to the corresponding class. </div>
<div class="sect2">
<h3 id="_meow_strong_disjointset_strong_c_class">meow:: <strong>DisjointSet</strong> (C++ class)</h3>
-<div class="paragraph"><div class="title">Description</div><p><span class="monospaced">DisjointSet</span> is a lighting data structure that maintain N numbers from
-<strong>0</strong> to <strong>N-1</strong> with methods below:</p></div>
+<div class="sect3">
+<h4 id="_description_3">Description</h4>
+<div class="paragraph"><p><span class="monospaced">DisjointSet</span> 是個<strong>輕量級Data Dtructure</strong>, 用來維護一堆互斥集的資訊.
+相關資料可參考
+<a href="http://www.csie.ntnu.edu.tw/~u91029/DisjointSets.html">演算法筆記</a></p></div>
+</div>
+<div class="sect3">
+<h4 id="_support_methods">Support Methods</h4>
<table class="tableblock frame-all grid-rows"
style="
width:100%;
">
-<col style="width:5%;">
-<col style="width:5%;">
-<col style="width:26%;">
-<col style="width:5%;">
-<col style="width:5%;">
-<col style="width:52%;">
+<col style="width:2%;">
+<col style="width:8%;">
+<col style="width:18%;">
+<col style="width:8%;">
+<col style="width:8%;">
+<col style="width:54%;">
<thead>
<tr>
<th class="tableblock halign-right valign-top" >Const?</th>
-<th class="tableblock halign-left valign-top" >Name</th>
-<th class="tableblock halign-left valign-top" > Parameters</th>
-<th class="tableblock halign-left valign-top" > Return Type</th>
-<th class="tableblock halign-left valign-top" > Time Complexity</th>
+<th class="tableblock halign-right valign-top" >Name </th>
+<th class="tableblock halign-left valign-top" > Parameters </th>
+<th class="tableblock halign-left valign-top" > Return_Type</th>
+<th class="tableblock halign-center valign-top" > Time_Complexity</th>
<th class="tableblock halign-left valign-top" > Description</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>root</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t number)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>root</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t <span class="monospaced">number</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">size_t</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">very fast</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Return the <strong>group id</strong> of the number given</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">very fast</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳 <span class="monospaced">number</span> 所在的 <strong>集合的編號</strong> (0~N-1)</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>size</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>size</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">size_t</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">very fast</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Return <strong>N</strong></p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">very fast</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳 <strong>總集合大小</strong></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>reset</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t N)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>reset</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t <span class="monospaced">N</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">very fast</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Clean and initalize</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(N)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">清空, 並且設定總集合大小為 <span class="monospaced">N</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>merge</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t number1,<br>
-size_t number2)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>merge</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t <span class="monospaced">number1</span>,<br>
+size_t <span class="monospaced">number2</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">size_t</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">very fast</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>Union</strong> the group contains number1 and the group contains number2.
-Return the merged group id</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">very fast</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將 <span class="monospaced">number1</span> 所在的集合 跟 <span class="monospaced">number2</span> 所在的集合 <strong>合併</strong>,
+並回傳合併後新的集合的編號</p></td>
</tr>
</tbody>
</table>
@@ -1154,31 +1208,73 @@ Return the merged group id</p></td> <td class="icon">
<div class="title">Note</div>
</td>
-<td class="content"><strong>very fast</strong> means that you can consider it as constant time.</td>
-</tr></table>
-</div>
-<hr>
-</div>
-<div class="sect2">
-<h3 id="_meow_strong_mergeableheap_lt_key_value_gt_strong_c_class">meow:: <strong>MergeableHeap<Key, Value></strong> (C++ class)</h3>
-<div class="paragraph"><div class="title">Description</div><p>MergeableHeap is a kind of maximum-heap with a special method <span class="monospaced">merge</span>,
-which will merge another MergeableHeap into itself in O(logN) time.</p></div>
-<div class="ulist"><div class="title">Template Request</div><ul>
+<td class="content">
+<div class="ulist"><ul>
<li>
<p>
-<span class="monospaced">Key</span> should has <span class="monospaced">operator<</span>
+<strong>very fast</strong> 表示它算的真的超級快, 可以視為常數時間.
</p>
</li>
-</ul></div>
-<div class="ulist"><div class="title">Support methods</div><ul>
<li>
<p>
-N ← number of elements in the heap
+預設值所有 <span class="monospaced">number</span> 所在的集合的編號就是 <span class="monospaced">number</span> 本身,
+即沒有任兩個數在同一個set裡面
</p>
</li>
+</ul></div>
+</td>
+</tr></table>
+</div>
+<hr>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_meow_strong_mergeableheap_lt_element_gt_strong_c_class">meow:: <strong>MergeableHeap<Element></strong> (C++ class)</h3>
+<div class="sect3">
+<h4 id="_description_4">Description</h4>
+<div class="paragraph"><p>一個用 <strong>左偏樹</strong> 實作的 <strong>Maximum-Heap</strong> , 除了原本heap有的功能外,
+還支援 <span class="monospaced">merge</span>, <span class="monospaced">split</span> 等功能</p></div>
+</div>
+<div class="sect3">
+<h4 id="_template_class_operators_request">Template Class Operators Request</h4>
+<table class="tableblock frame-all grid-rows"
+style="
+width:70%;
+">
+<col style="width:3%;">
+<col style="width:3%;">
+<col style="width:10%;">
+<col style="width:17%;">
+<col style="width:10%;">
+<col style="width:53%;">
+<thead>
+<tr>
+<th class="tableblock halign-right valign-top" >Const?</th>
+<th class="tableblock halign-left valign-top" >Typename</th>
+<th class="tableblock halign-left valign-top" > Operator </th>
+<th class="tableblock halign-left valign-top" > Parameters </th>
+<th class="tableblock halign-left valign-top" > Return_Type</th>
+<th class="tableblock halign-left valign-top" > Description</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator<</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Element <span class="monospaced">v</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">大小比較</p></td>
+</tr>
+</tbody>
+</table>
+</div>
+<div class="sect3">
+<h4 id="_support_methods_2">Support Methods</h4>
+<div class="ulist"><ul>
<li>
<p>
-M ← number of elements in the other heap if need
+N ← <span class="monospaced">this</span> 中擁有的資料數
</p>
</li>
</ul></div>
@@ -1186,94 +1282,88 @@ M ← number of elements in the other heap if need style="
width:100%;
">
+<col style="width:2%;">
<col style="width:5%;">
-<col style="width:5%;">
-<col style="width:17%;">
-<col style="width:5%;">
-<col style="width:5%;">
-<col style="width:58%;">
+<col style="width:19%;">
+<col style="width:8%;">
+<col style="width:8%;">
+<col style="width:55%;">
<thead>
<tr>
<th class="tableblock halign-right valign-top" >Const?</th>
-<th class="tableblock halign-left valign-top" >Name</th>
-<th class="tableblock halign-left valign-top" > Parameters</th>
-<th class="tableblock halign-left valign-top" > Return Type</th>
-<th class="tableblock halign-left valign-top" > Time Complexity</th>
+<th class="tableblock halign-right valign-top" >Name </th>
+<th class="tableblock halign-left valign-top" > Parameters </th>
+<th class="tableblock halign-left valign-top" > Return_Type</th>
+<th class="tableblock halign-center valign-top" > Time_Complexity</th>
<th class="tableblock halign-left valign-top" > Description</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator=</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(MergeableHeap const&)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">*this</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(N)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Copy operator.</p></td>
-</tr>
-<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>moveTo</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(MergeableHeap*)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>moveTo</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(MergeableHeap* <span class="monospaced">h</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(M)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Transform the this→data to the heap specified in parameters</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(M)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將 <span class="monospaced">this</span> 的資料複寫到 <span class="monospaced">h</span> 上面, 同時清空自己,
+時間複雜度中的M是 <span class="monospaced">h</span> 所擁有的資料數</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>top</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>top</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(1)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Return the maximum element in the heap.</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Element const&</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳最大的那個 <span class="monospaced">Element</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>size</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>size</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">size_t</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(1)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Return the number of elements in the heap.</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳 <span class="monospaced">this</span> 中擁有的資料數</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>empty</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>empty</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(1)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Return whether the heap is empty or not.</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳 <span class="monospaced">this</span> 是否為空</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>push</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Element)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>push</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Element const& <span class="monospaced">e</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(log N)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Add a element into the heap</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將 <span class="monospaced">e</span> 加入</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>pop</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>pop</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(log N)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Delete the maximum element from the heap</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將最大的 <span class="monospaced">Element</span> 移除</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>merge</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(MergeableHeap*)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>clear</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(log M)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Merge the specified MergeableHeap(with size=M) into itself</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(N)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將資料清空</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>clear</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>merge</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(MergeableHeap* <span class="monospaced">heap2</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(N)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Delete all elements from the heap</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN+logM)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將 <span class="monospaced">heap2</span> 的資料統統加到 <span class="monospaced">this</span> 中, 並且清空 <span class="monospaced">heap2</span>
+時間複雜度中的M是 <span class="monospaced">heap2</span> 的資料數</p></td>
</tr>
</tbody>
</table>
@@ -1282,51 +1372,134 @@ width:100%; <td class="icon">
<div class="title">Warning</div>
</td>
-<td class="content">Consider there are two MergeableHeap <span class="monospaced">A</span> and <span class="monospaced">B</span>.<br>
-<span class="monospaced">B</span> will become empty after you call <span class="monospaced">A.merge(&B)</span>.<br>
-The data in <span class="monospaced">B</span> will override by data in <span class="monospaced">A</span> and <span class="monospaced">A</span> will become empty after
-you call <span class="monospaced">A.moveTo(&B)</span></td>
-</tr></table>
-</div>
-<hr>
-</div>
-<div class="sect2">
-<h3 id="_meow_strong_kd_tree_lt_vector_scalar_gt_strong_c_class">meow:: <strong>KD_Tree<Vector, Scalar></strong> (C++ class)</h3>
-<div class="paragraph"><div class="title">Description</div><p><span class="monospaced">KD_Tree</span> is <strong>K-dimension tree</strong>, which is a multiple set contain lots of
-vector with K dimension.</p></div>
-<div class="ulist"><div class="title">Template Request</div><ul>
+<td class="content">
+<div class="ulist"><ul>
<li>
<p>
-<span class="monospaced">Vector</span> should has <span class="monospaced">operator[]</span> to allow the KD_Tree, <span class="monospaced">operator<</span> to
-compare when two vector are point to the same place, <span class="monospaced">operator==</span>
-access the k-dimensions
+假設現在有兩個MergeableHeap <span class="monospaced">A</span> 和 <span class="monospaced">B</span>, 則:
</p>
-</li>
+<div class="ulist"><ul>
<li>
<p>
-<span class="monospaced">Scalar</span> should has <span class="monospaced">operator*</span>, <span class="monospaced">operator+</span>, <span class="monospaced">operator<</span>
+執行 <span class="monospaced">A.merge(&B)</span> 後 <span class="monospaced">B</span> 會變成空的
</p>
</li>
-</ul></div>
-<div class="ulist"><div class="title">Support Methods</div><ul>
<li>
<p>
-N ← numbers of element in the kd-tree
+執行 <span class="monospaced">B.moveTo(&A)</span> 後 <span class="monospaced">B</span> 會變成空的, <span class="monospaced">A</span> 原本擁有的資料也會覆蓋掉
</p>
</li>
+</ul></div>
+</li>
+</ul></div>
+</td>
+</tr></table>
+</div>
+<hr>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_meow_strong_kd_tree_lt_vector_scalar_gt_strong_c_class">meow:: <strong>KD_Tree<Vector, Scalar></strong> (C++ class)</h3>
+<div class="sect3">
+<h4 id="_description_5">Description</h4>
+<div class="paragraph"><p><span class="monospaced">KD_Tree</span> 全名k-dimension tree, 用來維護由 <strong>N個K維度向量所成的集合</strong>,
+並可於該set中查找 <strong>前i個離給定向量最接近的向量</strong></p></div>
+</div>
+<div class="sect3">
+<h4 id="_template_class_operators_request_2">Template Class Operators Request</h4>
+<table class="tableblock frame-all grid-rows"
+style="
+width:70%;
+">
+<col style="width:3%;">
+<col style="width:3%;">
+<col style="width:10%;">
+<col style="width:17%;">
+<col style="width:10%;">
+<col style="width:53%;">
+<thead>
+<tr>
+<th class="tableblock halign-right valign-top" >Const?</th>
+<th class="tableblock halign-left valign-top" >Typename</th>
+<th class="tableblock halign-left valign-top" > Operator </th>
+<th class="tableblock halign-left valign-top" > Parameters </th>
+<th class="tableblock halign-left valign-top" > Return_Type</th>
+<th class="tableblock halign-left valign-top" > Description</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Vector</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator[]</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t <span class="monospaced">n</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Scalar</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">取得第 <span class="monospaced">n</span> 維度量</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Vector</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator<</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Vector <span class="monospaced">v</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">權重比較</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Scalar</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator*</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Scalar <span class="monospaced">s</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Scalar</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">相乘</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Scalar</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator+</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Scalar <span class="monospaced">s</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Scalar</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">相加</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Scalar</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator-</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Scalar <span class="monospaced">s</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Scalar</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">相差</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Scalar</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator<</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Scalar <span class="monospaced">s</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">大小比較</p></td>
+</tr>
+</tbody>
+</table>
+</div>
+<div class="sect3">
+<h4 id="_custom_type_definitions">Custom Type Definitions</h4>
+<div class="ulist"><ul>
<li>
<p>
-K ← dimensions
+<span class="monospaced">Vectors</span> ← <span class="monospaced">std::vector<Vector></span>
</p>
</li>
+</ul></div>
+</div>
+<div class="sect3">
+<h4 id="_support_methods_3">Support Methods</h4>
+<div class="ulist"><ul>
<li>
<p>
-<span class="monospaced">Vector</span> is the tyepname of the vector
+N ← <span class="monospaced">this</span> 中擁有的資料數
</p>
</li>
<li>
<p>
-<span class="monospaced">Vectors</span> is the typename of the std::vector<Vector>
+K ← <span class="monospaced">this</span> 資料維度
</p>
</li>
</ul></div>
@@ -1334,82 +1507,83 @@ K ← dimensions style="
width:100%;
">
-<col style="width:5%;">
-<col style="width:5%;">
-<col style="width:25%;">
-<col style="width:5%;">
-<col style="width:10%;">
-<col style="width:50%;">
+<col style="width:2%;">
+<col style="width:8%;">
+<col style="width:18%;">
+<col style="width:8%;">
+<col style="width:8%;">
+<col style="width:54%;">
<thead>
<tr>
<th class="tableblock halign-right valign-top" >Const?</th>
-<th class="tableblock halign-left valign-top" >Name</th>
-<th class="tableblock halign-left valign-top" > Parameters</th>
-<th class="tableblock halign-left valign-top" > Return Type</th>
-<th class="tableblock halign-left valign-top" > Time Complexity</th>
+<th class="tableblock halign-right valign-top" >Name </th>
+<th class="tableblock halign-left valign-top" > Parameters </th>
+<th class="tableblock halign-left valign-top" > Return_Type</th>
+<th class="tableblock halign-center valign-top" > Time_Complexity</th>
<th class="tableblock halign-left valign-top" > Description</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>root</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t number)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">size_t</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">very fast</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"></p></td>
-</tr>
-<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>insert</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Vector const& v)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>insert</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Vector const& <span class="monospaced">v</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(1)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Insert a vector</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將向量 <span class="monospaced">v</span> 加到set中</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>erase</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Vector const& v)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>erase</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Vector const& <span class="monospaced">v</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(N*x)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Find a vector which is the same
-as <span class="monospaced">v</span> and remove it from the KD_Tree, <span class="monospaced">x</span> in the Big-O time complex
-is cost by <span class="monospaced">Vector::operator==</span>.</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(N)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將向量 <span class="monospaced">v</span> 從set中移除, <em><sub>TODO:可以再優化</sub></em></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>build</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>build</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(KN logN) if need</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Build the data structure if need.</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(KN logN) or O(1)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">檢查距上一次 <span class="monospaced">build()</span> 至今是否有 <span class="monospaced">insert/erase</span> 被呼叫,
+若有, 重新建樹, 否則不做事</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>forceBuild</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>forceBuild</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(KN logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Build the data structure(the <span class="monospaced">insert()</span>
-method will not build the data structure immediately)</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(KN logN)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">重新建樹</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>query</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Vector const& v, int k)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>query</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Vector const& <span class="monospaced">v</span>,<br>
+size_t <span class="monospaced">i</span>,<br>
+bool <span class="monospaced">cmp</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Vectors</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(kN <sup>1-1/k</sup> )</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Using Euclidean-Distance to find the 1st to k-th nearest neighbor from <span class="monospaced">v</span> .
-And return;</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(KN <sup>1-1/K</sup> )</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">於set中找尋距離 <span class="monospaced">v</span> 前 <span class="monospaced">i</span> 近的向量, 並依照由近而遠的順序排序.
+如果有兩個向量 <span class="monospaced">v1</span>,<span class="monospaced">v2</span> 距離一樣, 且 <span class="monospaced">cmp</span> 為 <span class="monospaced">true</span> , 則直接依照
+<span class="monospaced">v1 < v2</span> 來決定誰在前面. 最後回傳一陣列包含所有解.</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>clear</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>clear</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(1)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Clear all data</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">清空所有資料</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>reset</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t <span class="monospaced">dimension</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">清空所有資料並且指定維度為 <span class="monospaced">dimension</span></p></td>
</tr>
</tbody>
</table>
@@ -1418,70 +1592,129 @@ And return;</p></td> <td class="icon">
<div class="title">Note</div>
</td>
-<td class="content">O(kN <sup>1-1/k</sup> ) is reference from wiki.<br>
-<span class="monospaced">query()</span> and <span class="monospaced">rangeQuery()</span> will run <span class="monospaced">build()</span> first if you called <span class="monospaced">insert()</span>
-before call them. And <span class="monospaced">build()</span> is very slow, so you should not use this class
-as a dynamic tree</td>
+<td class="content">
+<div class="ulist"><ul>
+<li>
+<p>
+此資料結構只有在 N >> 2 <sup>K</sup> 時才比較有優勢,
+當 K 逐漸變大時, 所花時間會跟暴搜沒兩樣
+</p>
+</li>
+</ul></div>
+</td>
</tr></table>
</div>
<hr>
</div>
+</div>
<div class="sect2">
<h3 id="_meow_strong_splaytree_lt_key_value_gt_strong_c_class">meow:: <strong>SplayTree<Key, Value></strong> (C++ class)</h3>
-<div class="paragraph"><div class="title">Description</div><p>Like <span class="monospaced">std::map</span>, <span class="monospaced">SplayTree</span> is an dictionary(key→value). But it has
-some extra method, such as <span class="monospaced">split()</span>, <span class="monospaced">merge()</span>, <span class="monospaced">keyOffset()</span>.</p></div>
-<div class="ulist"><div class="title">Data Type</div><ul>
+<div class="sect3">
+<h4 id="_description_6">Description</h4>
+<div class="paragraph"><p><span class="monospaced">SplayTree</span> 是一種神乎其技的資料結構, 維護一堆 Key→Value . 並且支援
+一些 <span class="monospaced">std::map</span> 難以快速實踐的操作, 如 <span class="monospaced">split</span> , <span class="monospaced">merge</span> , <span class="monospaced">keyOffset</span></p></div>
+</div>
+<div class="sect3">
+<h4 id="_template_class_operators_request_3">Template Class Operators Request</h4>
+<table class="tableblock frame-all grid-rows"
+style="
+width:70%;
+">
+<col style="width:3%;">
+<col style="width:3%;">
+<col style="width:10%;">
+<col style="width:17%;">
+<col style="width:10%;">
+<col style="width:53%;">
+<thead>
+<tr>
+<th class="tableblock halign-right valign-top" >Const?</th>
+<th class="tableblock halign-left valign-top" >Typename</th>
+<th class="tableblock halign-left valign-top" > Operator</th>
+<th class="tableblock halign-left valign-top" > Parameters </th>
+<th class="tableblock halign-left valign-top" > Return_Type</th>
+<th class="tableblock halign-left valign-top" > Description</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Key</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator+</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key <span class="monospaced">k</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Key</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">相加</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Key</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator<</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key <span class="monospaced">k</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">大小比較</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Key</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong><em>Key</em></strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(int <span class="monospaced">n</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">建構子, <span class="monospaced">n</span> 永遠是0</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Value</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong><em>Value</em></strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">( )</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">建構子</p></td>
+</tr>
+</tbody>
+</table>
+</div>
+<div class="sect3">
+<h4 id="_custom_type_definitions_2">Custom Type Definitions</h4>
+<div class="ulist"><ul>
<li>
<p>
-<span class="monospaced">Key</span> is the tyepname of the key
+<span class="monospaced">Element</span> → 用來當作回傳資料的媒介
</p>
-</li>
+<div class="ulist"><ul>
<li>
<p>
-<span class="monospaced">Value</span> is the typename of value
+重定義 <span class="monospaced">operator->()</span> 到 <span class="monospaced">std::pair<Key const&, Value&>*</span>
</p>
</li>
<li>
<p>
-`SplayTree<Key, Value>:: <strong>Element</strong> ` is a typename which contain
-(key→value). It has some methods below:
-</p>
-<div class="ulist"><ul>
-<li>
-<p>
-<span class="monospaced">->first ` a constant reference to `Key</span>
+重定義 <span class="monospaced">operator*()</span> 到 <span class="monospaced">std::pair<Key const&, Value&>&</span>
</p>
</li>
<li>
<p>
-<span class="monospaced">->second</span> a reference to <span class="monospaced">Value</span>
+有 <span class="monospaced">operator==</span> , <span class="monospaced">operator!=</span>, <span class="monospaced">operator=</span> 可用
</p>
</li>
<li>
<p>
-<span class="monospaced">operator==, operator!=</span> compare function, check if the two <span class="monospaced">Element</span>
-is pointer to the same (key→value)
+可以直接用 <span class="monospaced">(*e).second = some_value</span> 來改變SplayTree中的資料
</p>
</li>
</ul></div>
</li>
</ul></div>
-<div class="ulist"><div class="title">Template Request</div><ul>
-<li>
-<p>
-<span class="monospaced">Key</span> should has <span class="monospaced">operator<</span>, <span class="monospaced">operator+</span>
-</p>
-</li>
-</ul></div>
-<div class="ulist"><div class="title">Support Methods</div><ul>
+</div>
+<div class="sect3">
+<h4 id="_support_methods_4">Support Methods</h4>
+<div class="ulist"><ul>
<li>
<p>
-N ← numbers of element in the SplayTree
+N ← <span class="monospaced">this</span> 中擁有的資料數
</p>
</li>
<li>
<p>
-M ← numbers of element in another SplayTree
+M ← <span class="monospaced">tree2</span> 中擁有的資料數
</p>
</li>
</ul></div>
@@ -1489,293 +1722,344 @@ M ← numbers of element in another SplayTree style="
width:100%;
">
-<col style="width:4%;">
-<col style="width:4%;">
-<col style="width:23%;">
-<col style="width:4%;">
-<col style="width:14%;">
-<col style="width:47%;">
+<col style="width:2%;">
+<col style="width:8%;">
+<col style="width:18%;">
+<col style="width:8%;">
+<col style="width:8%;">
+<col style="width:54%;">
<thead>
<tr>
<th class="tableblock halign-right valign-top" >Const?</th>
-<th class="tableblock halign-left valign-top" >Name</th>
-<th class="tableblock halign-left valign-top" > Parameters</th>
-<th class="tableblock halign-left valign-top" > Return Type</th>
-<th class="tableblock halign-center valign-top" > Time Complexity</th>
+<th class="tableblock halign-right valign-top" >Name </th>
+<th class="tableblock halign-left valign-top" > Parameters </th>
+<th class="tableblock halign-left valign-top" > Return_Type</th>
+<th class="tableblock halign-center valign-top" > Time_Complexity</th>
<th class="tableblock halign-left valign-top" > Description</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator=</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(SplayTree const&)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">*this</p></td>
-<td class="tableblock halign-center valign-top" ><p class="tableblock">O(N)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">copy operator</p></td>
-</tr>
-<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>moveTo</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(SplayTree* t)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>moveTo</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(SplayTree* <span class="monospaced">tree2</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(M)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Transform the data in this to <span class="monospaced">t</span></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將 <span class="monospaced">this</span> 的資料複寫到 <span class="monospaced">tree2</span> 上面, 同時清空自己,
+時間複雜度中的M是 <span class="monospaced">tree2</span> 所擁有的資料數</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>lowerBound</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key k)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>lowerBound</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& <span class="monospaced">k</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Find the smallest (key→value)
-which <span class="monospaced">k <= key</span> and return</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">找出第一個(最小的) Element且 <span class="monospaced">k</span> ⇐ 它的 Key, 並且回傳之.
+找不到的話回傳 <span class="monospaced">this->end()</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>upperBound</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key k)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>lowerBound</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& <span class="monospaced">k</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Find the smallest (key→value)
-which <span class="monospaced">k < key</span> and return</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">找出第一個(最小的) Element且 <span class="monospaced">k</span> < 它的 Key, 並且回傳之.
+找不到的話回傳 <span class="monospaced">this->end()</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>rLowerBound</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key k)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>lowerBound</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& <span class="monospaced">k</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Find the largest (key→value)
-which <span class="monospaced">key <= k</span> and return</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">找出第一個(最小的) Element且 <span class="monospaced">k</span> >= 它的 Key, 並且回傳之.
+找不到的話回傳 <span class="monospaced">this->end()</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>rUpperBound</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key k)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>lowerBound</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& <span class="monospaced">k</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Find the largest (key→value)
-which <span class="monospaced">key < k</span> and return</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">找出第一個(最小的) Element且 <span class="monospaced">k</span> > 它的 Key, 並且回傳之.
+找不到的話回傳 <span class="monospaced">this->end()</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>find</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key k)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>find</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& <span class="monospaced">k</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Find the element (key→value) which
-<span class="monospaced">key == k</span> and return</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">找出 Key= <span class="monospaced">k</span> 的Elemenet 並回傳. 找不到的話回傳 <span class="monospaced">this->end()</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>order</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t k)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>order</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t <span class="monospaced">ord</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Find the <span class="monospaced">k</span>-th small element.
-note that <span class="monospaced">k</span> start from zero like a normal C/C++ array.</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將Elements依照Key由小到大排序, 回傳第 <span class="monospaced">ord</span> 個Element (由0算起).
+其中如果 <span class="monospaced">ord</span> > N - 1, 則會回傳 <span class="monospaced">this->last()</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>first</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>first</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t <span class="monospaced">ord</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Return the smallest element</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳Key最小的Element, 如果SplayTree為空, 則回傳 <span class="monospaced">this->end()</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>last</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>last</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t <span class="monospaced">ord</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Return the largest element</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳Key最大的Element, 如果SplayTree為空, 則回傳 <span class="monospaced">this->end()</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>end</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>end</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Element</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Return an empty element(it can be use to
-check if <span class="monospaced">find()</span> is successful)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳一個指向NULL的Element, 以供 <span class="monospaced">find</span> , <span class="monospaced">order</span> , <span class="monospaced">first</span>
+, <span class="monospaced">last</span> 等判斷是否有找到相對應的Element</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>size</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>size</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">size_t</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Return number of elements in the tree</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳資料數</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>empty</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>size</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Return whether the tree is empty</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳是否為空</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>clear</strong></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>clear</strong></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">()</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(N)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Clear</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">清空資料</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>keyOffset</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key offset)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>keyOffset</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& <span class="monospaced">delta</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Let all the keys in the tree
-plus offset</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將所有Element的Key同加上 <span class="monospaced">delta</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>insert</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key k, Value v)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>insert</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& <span class="monospaced">key</span>,<br>
+Value const& <span class="monospaced">value</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Insert an element.
-If the tree already has an element with same key, return <span class="monospaced">false</span>.</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">檢查是否已有Element的Key 為 <span class="monospaced">key</span>, 若有則回傳 <span class="monospaced">false</span> , 否則將
+一個 (Key → Value) = (<span class="monospaced">key</span> → <span class="monospaced">value</span>)的Element加入, 並回傳 <span class="monospaced">true</span>
+將所有Element的Key同加上 <span class="monospaced">delta</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>erase</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key k)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>erase</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& <span class="monospaced">key</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Erase an element from the tree with
-given key. Return <span class="monospaced">false</span> if the element not found.</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">檢查是否已有Element的Key 為 <span class="monospaced">key</span>, 若有則刪除之, 並回傳 <span class="monospaced">true</span>,
+否則則回傳 <span class="monospaced">false</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator[]</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key k)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Value</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>operator[]</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& <span class="monospaced">key</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Value&</p></td>
<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Like <span class="monospaced">find()</span> , but it will insert an element
-automatic if the corrosponding element not found</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">檢查是否已有Element的Key 為 <span class="monospaced">key</span>, 若有則回傳相對應的Value的Reference
+否則先執行 <span class="monospaced">insert(key, Value())</span> 再回傳相對應的Reference</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>splitOut</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& upper_bound,<br>
-SplayTree* out)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>splitOut</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Key const& <span class="monospaced">upper_bound</span>,<br>
+SplayTree* <span class="monospaced">tree2</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-center valign-top" ><p class="tableblock">O(log N)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Split out all the elements with key
-larger than <span class="monospaced">upper_bound</span> and store then into <span class="monospaced">out</span></p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN) + O(M)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將 <span class="monospaced">tree2</span> 清空, 再將所有Key > <span class="monospaced">upper_bound</span> 的Element都丟到 <span class="monospaced">tree2</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>mergeAfter</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(SplayTree* t)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
-<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN + logM)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">If not all of the elements in this
-are smaller than elements in <span class="monospaced">t</span>, return <span class="monospaced">false</span> , else merge <span class="monospaced">t</span> into
-itself and return <span class="monospaced">true</span>.</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>mergeAfter</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(SplayTree* <span class="monospaced">tree2</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN) + O(logM)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">檢查是否 <span class="monospaced">this</span> 中的 Key 都小於 <span class="monospaced">tree2</span> 中的Key, 是的話把 <span class="monospaced">tree2</span>
+中的 Element 都搬到 <span class="monospaced">this</span> , 同時清空 <span class="monospaced">tree2</span> , 回傳 <span class="monospaced">true</span>. 否則
+回傳 <span class="monospaced">false</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>merge</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(SplayTree* t)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">bool</p></td>
-<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN + logM)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">If all of the elements in this
-are smaller than elements in <span class="monospaced">t</span> or all of the elements in this larger than
-elements in <span class="monospaced">t</span> , merge <span class="monospaced">t</span> into itself and return <span class="monospaced">true</span>.
-Else return <span class="monospaced">false</span></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>merge</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(SplayTree* <span class="monospaced">tree2</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN) + O(logM)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">檢查是否 <span class="monospaced">this</span> 中的 Key 都小於 <span class="monospaced">tree2</span> 中的Key 或者
+是否 <span class="monospaced">this</span> 中的 Key 都大於 <span class="monospaced">tree2</span> 中的Key, 是的話把 <span class="monospaced">tree2</span>
+中的 Element 都搬到 <span class="monospaced">this</span> , 同時清空 <span class="monospaced">tree2</span> , 回傳 <span class="monospaced">true</span>. 否則
+回傳 <span class="monospaced">false</span></p></td>
</tr>
</tbody>
</table>
<div class="admonitionblock">
<table><tr>
<td class="icon">
-<div class="title">Warning</div>
+<div class="title">Note</div>
</td>
-<td class="content">Consider there are two SplayTree <span class="monospaced">A</span> and <span class="monospaced">B</span>.<br>
-<span class="monospaced">B</span> will become empty after you call <span class="monospaced">A.mergeAfter(&B)</span>
-or <span class="monospaced">A.merge(&B)</span> successful.<br>
-The data in <span class="monospaced">B</span> will override by data in <span class="monospaced">A</span> and <span class="monospaced">A</span> will become empty after
-you call <span class="monospaced">A.moveTo(&B)</span></td>
-</tr></table>
-</div>
-<hr>
-</div>
-<div class="sect2">
-<h3 id="_meow_strong_segmenttree_lt_value_gt_strong_c_class">meow:: <strong>SegmentTree<Value></strong> (C++ class)</h3>
-<div class="paragraph"><div class="title">Description</div><p><span class="monospaced">SegmentTree</span> is a data structure that can maintain an array, and
-support <strong>range update</strong> , <strong>range query</strong></p></div>
-<div class="ulist"><div class="title">Template Request</div><ul>
-<li>
-<p>
-<span class="monospaced">Value</span> should has
-</p>
+<td class="content">
<div class="ulist"><ul>
<li>
<p>
-<span class="monospaced">operator+(Value)</span> offset
+假設現在有兩個SplayTree <span class="monospaced">A</span> 和 <span class="monospaced">B</span>, 則:
</p>
-</li>
+<div class="ulist"><ul>
<li>
<p>
-<span class="monospaced">operator|(Value)</span> merge two nodes
+執行 <span class="monospaced">B.moveTo(&A)</span> 後 <span class="monospaced">B</span> 會變成空的, <span class="monospaced">A</span> 原本擁有的資料也會覆蓋掉
</p>
</li>
<li>
<p>
-<span class="monospaced">operator*(size_t)</span> ??
+執行 <span class="monospaced">A.merge(&B)</span> 或 <span class="monospaced">A.mergeAfter(&B)</span> 後
+如果檢查發現確實可以merge, 則之後 <span class="monospaced">B</span> 會變成空的
</p>
</li>
</ul></div>
</li>
</ul></div>
-<div class="paragraph"><p>For example, if you want to maintain <strong>range minimum</strong></p></div>
+</td>
+</tr></table>
+</div>
+<hr>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_meow_strong_segmenttree_lt_value_gt_strong_c_class">meow:: <strong>SegmentTree<Value></strong> (C++ class)</h3>
+<div class="sect3">
+<h4 id="_description_7">Description</h4>
+<div class="paragraph"><p>維護一個陣列, 並且讓user可以有區間查詢, 區間修改的小東東</p></div>
+</div>
+<div class="sect3">
+<h4 id="_template_class_operators_request_4">Template Class Operators Request</h4>
+<table class="tableblock frame-all grid-rows"
+style="
+width:70%;
+">
+<col style="width:3%;">
+<col style="width:3%;">
+<col style="width:10%;">
+<col style="width:17%;">
+<col style="width:10%;">
+<col style="width:53%;">
+<thead>
+<tr>
+<th class="tableblock halign-right valign-top" >Const?</th>
+<th class="tableblock halign-left valign-top" >Typename</th>
+<th class="tableblock halign-left valign-top" > Operator </th>
+<th class="tableblock halign-left valign-top" > Parameters </th>
+<th class="tableblock halign-left valign-top" >Return_Type</th>
+<th class="tableblock halign-left valign-top" > Description</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Value</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator+</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Value <span class="monospaced">v</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Value</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">相加(位移)</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Value</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator*</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t <span class="monospaced">n</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Value</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">每個Value都一樣,
+長為 <span class="monospaced">n</span> 的區間的值</p></td>
+</tr>
+<tr>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Value</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>operator|</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(Value <span class="monospaced">v</span>)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">Value</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">區間合併後的值</p></td>
+</tr>
+</tbody>
+</table>
+<div class="ulist"><ul>
+<li>
+<p>
+若要維護區間最小值, 即每次都是詢問範圍 <span class="monospaced">[a, b]</span> 的最小值, 則可以定義
+</p>
<div class="ulist"><ul>
<li>
<p>
-<span class="monospaced">Value::operator+(Value v2)</span> will be <span class="monospaced">this->realValue + v2.realValue</span>
+<span class="monospaced">operator+</span> 為 <em>回傳相加值</em>
</p>
</li>
<li>
<p>
-<span class="monospaced">Value::operator|(Value v2)</span> will be <span class="monospaced">std::min(this->realValue, v2.realValue)</span>
+<span class="monospaced">operator*</span> 為 <em>回傳*this</em>
</p>
</li>
<li>
<p>
-<span class="monospaced">Value::operator*(size_t n)</span> will be <span class="monospaced">this->realValue</span>
+<span class="monospaced">operator|</span> 為 <em>回傳std::min(*this, v)</em>
</p>
</li>
</ul></div>
-<div class="paragraph"><p>If you want to maintain <strong>range sum</strong></p></div>
+</li>
+<li>
+<p>
+若要維護區間最總和, 即每次都是詢問範圍 <span class="monospaced">[a, b]</span> 的總和, 則可以定義
+</p>
<div class="ulist"><ul>
<li>
<p>
-<span class="monospaced">Value::operator+(Value v2)</span> will be <span class="monospaced">this->realValue + v2.realValue</span>
+<span class="monospaced">operator+</span> 為 <em>回傳相加值</em>
</p>
</li>
<li>
<p>
-<span class="monospaced">Value::operator|(Value v2)</span> will be <span class="monospaced">this->realValue + v2.realValue)</span>
+<span class="monospaced">operator*</span> 為 <em>回傳(*this) * n</em>
</p>
</li>
<li>
<p>
-<span class="monospaced">Value::operator*(size_t n)</span> will be <span class="monospaced">this->realValue * n</span>
+<span class="monospaced">operator|</span> 為 <em>回傳相加值</em>
</p>
</li>
</ul></div>
-<div class="ulist"><div class="title">Support methods</div><ul>
+</li>
+</ul></div>
+</div>
+<div class="sect3">
+<h4 id="_support_methods_5">Support Methods</h4>
+<div class="ulist"><ul>
<li>
<p>
-N ← array size
+N ← <span class="monospaced">this</span> 所維護的陣列長度
</p>
</li>
</ul></div>
@@ -1783,60 +2067,64 @@ N ← array size style="
width:100%;
">
+<col style="width:2%;">
<col style="width:5%;">
-<col style="width:5%;">
-<col style="width:17%;">
-<col style="width:5%;">
-<col style="width:5%;">
-<col style="width:58%;">
+<col style="width:19%;">
+<col style="width:8%;">
+<col style="width:8%;">
+<col style="width:55%;">
<thead>
<tr>
<th class="tableblock halign-right valign-top" >Const?</th>
-<th class="tableblock halign-left valign-top" >Name</th>
-<th class="tableblock halign-left valign-top" > Parameters</th>
-<th class="tableblock halign-left valign-top" > Return Type</th>
-<th class="tableblock halign-left valign-top" > Time Complexity</th>
+<th class="tableblock halign-right valign-top" >Name </th>
+<th class="tableblock halign-left valign-top" > Parameters </th>
+<th class="tableblock halign-left valign-top" > Return_Type</th>
+<th class="tableblock halign-center valign-top" > Time_Complexity</th>
<th class="tableblock halign-left valign-top" > Description</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>reset</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t N)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>reset</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(size_t <span class="monospaced">size</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(1)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Clear and reset the array size to N (from <span class="monospaced">0</span> to <span class="monospaced">N - 1</span>)</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(1)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將資料清空且設定維護範圍是 <span class="monospaced">0~size - 1</span> 其中時間複雜度確切多少未知
+要看 <span class="monospaced">std::vector::resize()</span> 的效率</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock">const</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>query</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(ssize_t <em>first, ssize_t </em>last)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced">const</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>query</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(ssize_t <span class="monospaced">first</span>,<br>
+ssize_t <span class="monospaced">last</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">Value</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Range query</p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">回傳區間 <span class="monospaced">[first,last]</span> (邊界都含) 的區間值</p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>override</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(ssize_t <em>first, ssize_t </em>last, Value const& __value)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>override</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(ssize_t <span class="monospaced">first</span>,<br>
+ssize_t <span class="monospaced">last</span>,<br>
+Value const& <span class="monospaced">value</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Let the element in the array index from <span class="monospaced">__first</span> to <span class="monospaced">__last</span>
-be <span class="monospaced">__value</span></p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將區間 <span class="monospaced">[first,last]</span> 全部都設定成 <span class="monospaced">value</span></p></td>
</tr>
<tr>
-<td class="tableblock halign-right valign-top" ><p class="tableblock"></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock"><strong>offset</strong></p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">(ssize_t <em>first, ssize_t </em>last, Value const& __value)</p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock monospaced"></p></td>
+<td class="tableblock halign-right valign-top" ><p class="tableblock"><strong>offset</strong></p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">(ssize_t <span class="monospaced">first</span>,<br>
+ssize_t <span class="monospaced">last</span>,<br>
+Value const& <span class="monospaced">delta</span>)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">void</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">O(logN)</p></td>
-<td class="tableblock halign-left valign-top" ><p class="tableblock">Let the element in the array index from <span class="monospaced">__first</span> to <span class="monospaced">__last</span>
-plus <span class="monospaced">__value</span></p></td>
+<td class="tableblock halign-center valign-top" ><p class="tableblock">O(logN)</p></td>
+<td class="tableblock halign-left valign-top" ><p class="tableblock">將區間 <span class="monospaced">[first,last]</span> 全部都加上 <span class="monospaced">delta</span></p></td>
</tr>
</tbody>
</table>
-<hr>
+</div>
</div>
</div>
</div>
@@ -1844,7 +2132,7 @@ plus <span class="monospaced">__value</span></p></td> <div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
-Last updated 2014-04-21 14:11:29 CST
+Last updated 2014-04-22 02:21:30 CST
</div>
</div>
</body>
diff --git a/description.asciidoc b/description.asciidoc index f768289..f55fdad 100644 --- a/description.asciidoc +++ b/description.asciidoc @@ -2,36 +2,40 @@ == Description -一個不需要, 也不建議先compile成obj files的templates. +一個不需要, 也不應該先compile成obj files的templates. -TIP: *README.html* is more beautiful. +.Links +* https://github.com/cathook/meow[GitHub] +* http://www.csie.ntu.edu.tw/~b01902109/readme/template_meow/README.html[README.html] == File Tree === *meowpp/* C++ templates -[width="90%"] * *utility.h* some useful functions, - `stringPringf()` , `stringReplace` , `cstringEndWith` , + `stringPringf()` , `stringReplace()` , `cstringEndWith()` , `debugPrintf()` , `messagePrintf()` , `constant PI` , - `noEPS()` , `normalize()` , `denormalize` , - `ratioMapping` , `inRange()` , `squ()` , `average()` + `noEPS()` , `normalize()` , `denormalize()` , + `ratioMapping()` , `inRange()` , `squ()` , `average()` * *Usage.h* `class Usage` * *colors/* Color splces and transformer ** *RGB.h* `class RGBi` , `class RGBf` -** *YUV.h* `class YUVi` , `class YUVf` , `RGB_to_YUV()` , `YUV_to_RGB` -** *HSL.h* `class HSLf` , `RGB_to_HSL()` , `HSL_to_RGB` , - `YUV_to_HSL()` , `HSL_to_YUV` -** *HSV.h* `class HSVf` , `RGB_to_HSV()` , `HSV_to_RGB` , - `YUV_to_HSV()` , `HSV_to_YUV` , - `HSL_to_HSV()` , `HSV_to_HSL` +** *YUV.h* `class YUVi` , `class YUVf` , `RGB_to_YUV()` , `YUV_to_RGB()` +** *HSL.h* `class HSLf` , `RGB_to_HSL()` , `HSL_to_RGB()` , + `YUV_to_HSL()` , `HSL_to_YUV()` +** *HSV.h* `class HSVf` , `RGB_to_HSV()` , `HSV_to_RGB()` , + `YUV_to_HSV()` , `HSV_to_YUV()` , + `HSL_to_HSV()` , `HSV_to_HSL()` * *dsa/* Data Structures and Algorithms ** *DisjointSet.h* `class DisjointSet` -** *Heaps.h* `class MergeableHeap` -** *KD_Tree.h* `class KD_Tree` -** *SplayTree.h* `class SplayTree` +** *Heaps.h* `class MergeableHeap<Element>` +** *KD_Tree.h* `class KD_Tree<Vector, Scalar>` +** *SegemenTree.h* `class SegmentTree<Value>` +** *SplayTree.h* `class SplayTree<Key, Value>` * *oo/* ** *Register_Implement.h* `class RegisterInterface` , `class ImplementInterface` == Structures/Classes/Functions + +:b: | diff --git a/meowpp/Usage.h b/meowpp/Usage.h index 22f7329..d2ef083 100644 --- a/meowpp/Usage.h +++ b/meowpp/Usage.h @@ -88,68 +88,67 @@ namespace meow{ Strings usage_end ; Strings proc_arguments; }; - /******************************************************************* - @asciidoc - === meow:: *Usage* (C++ Class) - .Description - `Usage` 是用來分析argc, argv和輸出usage document的class. - argc, argv的部份, 有以下規則 - - * `-c` 其中 `c` 可以代換成正常的一個字元的字符, - 這種選像要嘛就是 *有設置* , 不然就是 *沒設置* - * `-c <value>` 附加一個value, 這種選項可以是選擇性 ,即要設定與否都可以, - 反之則一定要設定. 另外可以給定value的預設值以及哪些value是可接受的 - * `<value>` 其他, 一律視為process arguments - - .Methods - * `Usage(String const& _name)` + - 建構子, 所有說明文字中 *<name>* 都會被代換成 `_name` - * `Usage()` + - 建構子, `_name` 自動取為 " *nobody* " - * `import(Usage const& usage)` + - 將另一個usage的設定匯入, 回傳成功與否 *(bool)* - * `update(Usage const& usage)` + - 將另一個usage分析argc,argv出來的資料拿來用, 回傳成功與否 *(bool)* - * `addOption(unsigned char option, String const& description)` + - 新增一個不接額外選項的參數, 並附上說明文字, 回傳成功與否 *(bool)* - * `addOption(unsigned char option, String const& description, - String const& value_type, String const& value_default, bool must)` + - 新增一個有額外選項的參數, 並附上說明文字, 額外選項的型別跟預設值. - 說明文字中所有的" *<types>* "將會被取代指定的型別, 其中 `must` 代表 - " *是否一定要設定此參數* " , 回傳表成功與否 *(bool)* - * `addOptionValueAccept(unsigned char option, - String const& value, String const& description)` + - 針對某個option, 新增一個可接受的額外選項 (如果某個option從頭到尾都沒有 - 新增可接受的選項, 則視為不限制), 回傳成功與否 *(bool)* - * `hasOptionSetup(unsigned char option)` + - 回傳是否有此選項 *(bool)* - * `getOptionValuesCount(unsigned char option)` + - 回傳此參數被設置了幾次 *(size_t)* , 只對有接額外參數的有效 - * `getOptionValue(unsigned char option, size_t index)` + - 回傳第`index`個額外選項 *(String)* - * `getProcArgsCount()` + - 回傳有多少個Process Arguments *(size_t)* - * `getProcArg(size_t index)` + - 取得第`index`個Process Argument *(String)* - * `getProcArgs()` + - 回傳一個陣列, 包含所有Process Arguments *(Strings)* - * `addUsageBegin(String const& des)` + - 新增一段usage document於每個選項逐條說明之前 - * `addUsageEnd (String const& des)` + - 新增一段usage document於每個選項逐條說明之後 - * `String getUsage()` + - 回傳usage document *(String)* - * `setArguments(int argc, char** argv, String* errmsg)` + - 輸入argv, argc, 回傳是否沒有錯誤發生 *(bool)* , 其中如果有錯誤發生, - 且 `errmsg != NULL` 則會將錯誤訊息寫入之 - -NOTE: `String` 是 `std::string` . + -`Strings` 是 `std::vector< std::string> >`. + -如果沒有寫回傳什麼, 就是回傳 `void` - -''' -@asciidoc- - ******************************************************************/ + //# === meow:: *Usage* (C++ Class) + //# ==== Description + //# `Usage` 是用來分析argc, argv和輸出usage document的class. + //# argc, argv的部份, 有以下規則 + //# + //# * `-c` 其中 `c` 可以代換成正常的一個字元的字符, + //# 這種選像要嘛就是 *有設置* , 不然就是 *沒設置* + //# * `-c <value>` 附加一個value, 這種選項可以是選擇性 ,即要設定與否都可以, + //# 反之則一定要設定. 另外可以給定value的預設值以及哪些value是可接受的 + //# * `<value>` 其他, 一律視為process arguments + //# + //# ==== Methods + //# * `Usage(String const& _name)` + + //# 建構子, 所有說明文字中 *<name>* 都會被代換成 `_name` + //# * `Usage()` + + //# 建構子, `_name` 自動取為 " *nobody* " + //# * `import(Usage const& usage)` + + //# 將另一個usage的設定匯入, 回傳成功與否 *(bool)* + //# * `update(Usage const& usage)` + + //# 將另一個usage分析argc,argv出來的資料拿來用, 回傳成功與否 *(bool)* + //# * `addOption(unsigned char option, String const& description)` + + //# 新增一個不接額外選項的參數, 並附上說明文字, 回傳成功與否 *(bool)* + //# * `addOption(unsigned char option, String const& description, + //# String const& value_type, String const& value_default, bool must)` + + //# 新增一個有額外選項的參數, 並附上說明文字, 額外選項的型別跟預設值. + //# 說明文字中所有的" *<types>* "將會被取代指定的型別, 其中 `must` 代表 + //# " *是否一定要設定此參數* " , 回傳表成功與否 *(bool)* + //# * `addOptionValueAccept(unsigned char option, + //# String const& value, String const& description)` + + //# 針對某個option, 新增一個可接受的額外選項 (如果某個option從頭到尾都 + //# 沒有新增可接受的選項, 則視為不限制), 回傳成功與否 *(bool)* + //# * `hasOptionSetup(unsigned char option)` + + //# 回傳是否有此選項 *(bool)* + //# * `getOptionValuesCount(unsigned char option)` + + //# 回傳此參數被設置了幾次 *(size_t)* , 只對有接額外參數的有效 + //# * `getOptionValue(unsigned char option, size_t index)` + + //# 回傳第`index`個額外選項 *(String)* + //# * `getProcArgsCount()` + + //# 回傳有多少個Process Arguments *(size_t)* + //# * `getProcArg(size_t index)` + + //# 取得第`index`個Process Argument *(String)* + //# * `getProcArgs()` + + //# 回傳一個陣列, 包含所有Process Arguments *(Strings)* + //# * `addUsageBegin(String const& des)` + + //# 新增一段usage document於每個選項逐條說明之前 + //# * `addUsageEnd (String const& des)` + + //# 新增一段usage document於每個選項逐條說明之後 + //# * `String getUsage()` + + //# 回傳usage document *(String)* + //# * `setArguments(int argc, char** argv, String* errmsg)` + + //# 輸入argv, argc, 回傳是否沒有錯誤發生 *(bool)* , 其中如果有錯誤發生, + //# 且 `errmsg != NULL` 則會將錯誤訊息寫入之 + //# + //#[NOTE] + //#================================== + //# * `String` 是 `std::string` . + //# * `Strings` 是 `std::vector< std::string> >`. + //# * 如果沒有寫回傳什麼, 就是回傳 `void` + //#================================== + //# + //#''' } #include "Usage.hpp" diff --git a/meowpp/dsa/DisjointSet.h b/meowpp/dsa/DisjointSet.h index b33a839..b918adb 100644 --- a/meowpp/dsa/DisjointSet.h +++ b/meowpp/dsa/DisjointSet.h @@ -1,10 +1,18 @@ #ifndef DisjointSet_H__ #define DisjointSet_H__ + #include <vector> #include <cstdlib> namespace meow{ + //# + //#=== meow:: *DisjointSet* (C++ class) + //#==== Description + //# `DisjointSet` 是個*輕量級Data Dtructure*, 用來維護一堆互斥集的資訊. + //# 相關資料可參考 + //# link:http://www.csie.ntnu.edu.tw/~u91029/DisjointSets.html[演算法筆記] + //# class DisjointSet{ private: size_t n; @@ -17,39 +25,46 @@ namespace meow{ DisjointSet(); DisjointSet(size_t _n); DisjointSet(DisjointSet const& dsj); - // + + //#==== Support Methods + //# + //#[options="header",width="100%",cols="1>m,3>s,7<,3<,3^,20<",grid="rows"] + //#|===================================================================== + //#|Const?|Name | Parameters | Return_Type| Time_Complexity| Description + + + //#|const |root |(size_t `number`) | size_t | very fast + //#|回傳 `number` 所在的 *集合的編號* (0~N-1) size_t root (size_t a ) const; + + + //#|const |size |() | size_t | very fast + //#|回傳 *總集合大小* size_t size ( ) const; - // + + + //#| |reset|(size_t `N`) | void | O(N) + //#| 清空, 並且設定總集合大小為 `N` void reset(size_t _n ); + + + //#| |merge|(size_t `number1`,\size_t `number2`)| size_t | very fast + //#| 將 `number1` 所在的集合 跟 `number2` 所在的集合 *合併*, + //# 並回傳合併後新的集合的編號 size_t merge(size_t a, size_t b); + + + //#|===================================================================== }; - /********************************************************* - @asciidoc - === meow:: *DisjointSet* (C++ class) - .Description - `DisjointSet` is a lighting data structure that maintain N numbers from - *0* to *N-1* with methods below: - - [options="header",width="100%",cols="1>,1<s,5<,1<,1<,10<",grid="rows"] - |======================================================================= - |Const?|Name| Parameters| Return Type| Time Complexity| Description - |const|root|(size_t number)|size_t|very fast| - Return the *group id* of the number given - |const|size|()|size_t|very fast| - Return *N* - ||reset|(size_t N)|void|very fast| - Clean and initalize - ||merge|(size_t number1, + - size_t number2)|size_t|very fast| - *Union* the group contains number1 and the group contains number2. - Return the merged group id - |======================================================================= -NOTE: *very fast* means that you can consider it as constant time. - -''' -@asciidoc- - *********************************************************/ + //# + //#[NOTE] + //#======================================== + //# * *very fast* 表示它算的真的超級快, 可以視為常數時間. + //# * 預設值所有 `number` 所在的集合的編號就是 `number` 本身, + //# 即沒有任兩個數在同一個set裡面 + //#======================================== + //# + //# ''' } #include "DisjointSet.hpp" diff --git a/meowpp/dsa/KD_Tree.h b/meowpp/dsa/KD_Tree.h index 2ba81a1..035d6eb 100644 --- a/meowpp/dsa/KD_Tree.h +++ b/meowpp/dsa/KD_Tree.h @@ -8,6 +8,24 @@ #include <utility.h> namespace meow{ + //# + //#=== meow:: *KD_Tree<Vector, Scalar>* (C++ class) + //#==== Description + //# `KD_Tree` 全名k-dimension tree, 用來維護由 *N個K維度向量所成的集合*, + //# 並可於該set中查找 *前i個離給定向量最接近的向量* + //# + //#==== Template Class Operators Request + //#[options="header",width="70%",cols="1>m,1<,3<s,5<,3<,15<",grid="rows"] + //#|===================================================================== + //#|Const?|Typename| Operator | Parameters | Return_Type| Description + //#|const | Vector|operator[] |(size_t `n`) | Scalar | 取得第 `n` 維度量 + //#|const | Vector|operator< |(Vector `v`) | bool | 權重比較 + //#|const | Scalar|operator* |(Scalar `s`) | Scalar | 相乘 + //#|const | Scalar|operator+ |(Scalar `s`) | Scalar | 相加 + //#|const | Scalar|operator- |(Scalar `s`) | Scalar | 相差 + //#|const | Scalar|operator< |(Scalar `s`) | bool | 大小比較 + //#|===================================================================== + //# template<class Vector, class Scalar> class KD_Tree{ private: @@ -68,68 +86,76 @@ namespace meow{ std::vector<size_t>* __orders, int __depth); public: + //#==== Custom Type Definitions + //# * `Vectors` <- `std::vector<Vector>` + //# typedef typename std::vector<Vector> Vectors; // KD_Tree(); KD_Tree(size_t __dimension); ~KD_Tree(); - // + + //#==== Support Methods + //# + //# * N <- `this` 中擁有的資料數 + //# * K <- `this` 資料維度 + //# + //#[options="header",width="100%",cols="1>m,3>s,7<,3<,3^,20<",grid="rows"] + //#|===================================================================== + //#|Const?|Name | Parameters | Return_Type| Time_Complexity| Description + + + //#||insert|(Vector const& `v`)|void| O(1) + //#|將向量 `v` 加到set中 void insert(Vector const& __vector); + + + //#||erase|(Vector const& `v`)|bool| O(N) + //#|將向量 `v` 從set中移除, '~TODO:可以再優化~' bool erase (Vector const& __vector); + + + //#||build|()|void|O(KN logN) or O(1) + //#|檢查距上一次 `build()` 至今是否有 `insert/erase` 被呼叫, + //# 若有, 重新建樹, 否則不做事 void build(); + + + //#||forceBuild|()|void|O(KN logN) + //#|重新建樹 void forceBuild(); - // + + + //#|const|query|(Vector const& `v`,\size_t `i`,\bool `cmp`)|Vectors + //#|O(KN ^1-1/K^ ) + //#|於set中找尋距離 `v` 前 `i` 近的向量, 並依照由近而遠的順序排序. + //# 如果有兩個向量 `v1`,`v2` 距離一樣, 且 `cmp` 為 `true` , 則直接依照 + //# `v1 < v2` 來決定誰在前面. 最後回傳一陣列包含所有解. Vectors query(Vector const& __vector, size_t __nearestNumber, bool __compareWholeVector) const; - // + + + //#||clear|()|void|O(1) + //#|清空所有資料 void clear(); + + + //#||reset|(size_t `dimension`)|void|O(1) + //#|清空所有資料並且指定維度為 `dimension` void reset(size_t __dimension); + + + //#|===================================================================== }; - /********************************************************* - @asciidoc - === meow:: *KD_Tree<Vector, Scalar>* (C++ class) - .Description - `KD_Tree` is *K-dimension tree*, which is a multiple set contain lots of - vector with K dimension. - - .Template Request - * `Vector` should has `operator[]` to allow the KD_Tree, `operator<` to - compare when two vector are point to the same place, `operator==` - access the k-dimensions - * `Scalar` should has `operator*`, `operator+`, `operator<` - - .Support Methods - * N <- numbers of element in the kd-tree - * K <- dimensions - * `Vector` is the tyepname of the vector - * `Vectors` is the typename of the std::vector<Vector> - [options="header",width="100%",cols="1>,1<s,5<,1<,2<,10<",grid="rows"] - |======================================================================= - |Const?|Name| Parameters| Return Type| Time Complexity| Description - |const|root|(size_t number)|size_t|very fast| - ||insert|(Vector const& v)|void|O(1)|Insert a vector - ||erase |(Vector const& v)|bool|O(N*x)| Find a vector which is the same - as `v` and remove it from the KD_Tree, `x` in the Big-O time complex - is cost by `Vector::operator==`. - || build|()|void|O(KN logN) if need | Build the data structure if need. - || forceBuild|()|void|O(KN logN) | Build the data structure(the `insert()` - method will not build the data structure immediately) - |const|query|(Vector const& v, int k)|Vectors|O(kN ^1-1/k^ ) | - Using Euclidean-Distance to find the 1st to k-th nearest neighbor from `v` . - And return; - ||clear|()|O(1)|Clear all data - ||reset|(size_t dimension)|O(1)|Clear all data and then - set the this->dimension be `dimension` - |======================================================================= -NOTE: O(kN ^1-1/k^ ) is reference from wiki. + -`query()` and `rangeQuery()` will run `build()` first if you called `insert()` -before call them. And `build()` is very slow, so you should not use this class -as a dynamic tree - -''' -@asciidoc- - *********************************************************/ + //# + //#[NOTE] + //#======================================== + //# * 此資料結構只有在 N >> 2 ^K^ 時才比較有優勢, + //# 當 K 逐漸變大時, 所花時間會跟暴搜沒兩樣 + //#======================================== + //# + //# ''' } #include "KD_Tree.hpp" diff --git a/meowpp/dsa/MergeableHeap.h b/meowpp/dsa/MergeableHeap.h index 1e47afd..c1a2460 100644 --- a/meowpp/dsa/MergeableHeap.h +++ b/meowpp/dsa/MergeableHeap.h @@ -4,6 +4,19 @@ #include <cstdlib> namespace meow{ + //# + //#=== meow:: *MergeableHeap<Element>* (C++ class) + //#==== Description + //# 一個用 *左偏樹* 實作的 *Maximum-Heap* , 除了原本heap有的功能外, + //# 還支援 `merge`, `split` 等功能 + //# + //#==== Template Class Operators Request + //#[options="header",width="70%",cols="1>m,1<,3<s,5<,3<,15<",grid="rows"] + //#|===================================================================== + //#|Const?|Typename| Operator | Parameters | Return_Type| Description + //#|const |Element |operator< |(Element `v`)| bool | 大小比較 + //#|===================================================================== + //# template<class Element> class MergeableHeap{ // maximum-heap private: @@ -23,66 +36,70 @@ namespace meow{ public: MergeableHeap(); MergeableHeap(MergeableHeap const& _heap2); - // - ~MergeableHeap(); - // MergeableHeap& operator=(MergeableHeap const& _heap2); - void moveTo(MergeableHeap* _heap2); - // - Element const& top () const; - size_t size () const; - size_t empty() const; - // - void push (Element const& _value); - void pop ( ); - void clear( ); + ~MergeableHeap(); + + //#==== Support Methods + //# + //# * N <- `this` 中擁有的資料數 + //# + //#[options="header",width="100%",cols="1>m,2>s,7<,3<,3^,20<",grid="rows"] + //#|===================================================================== + //#|Const?|Name | Parameters | Return_Type| Time_Complexity| Description + + + //#||moveTo|(MergeableHeap* `h`)|void|O(M) + //#|將 `this` 的資料複寫到 `h` 上面, 同時清空自己, + //# 時間複雜度中的M是 `h` 所擁有的資料數 + void moveTo(MergeableHeap* _heap2); + + + //#|const|top|()|Element const&|O(1) + //#|回傳最大的那個 `Element` + Element const& top() const; + + + //#|const|size|()|size_t|O(1) + //#|回傳 `this` 中擁有的資料數 + size_t size() const; + + + //#|const|empty|()|bool|O(1) + //#|回傳 `this` 是否為空 + bool empty() const; + + + //#||push|(Element const& `e`)|void|O(logN) + //#|將 `e` 加入 + void push(Element const& _value); + + + //#||pop|()|void|O(logN) + //#|將最大的 `Element` 移除 + void pop(); + + + //#||clear|()|void|O(N) + //#|將資料清空 + void clear(); + + + //#||merge|(MergeableHeap* `heap2`)|void|O(logN+logM) + //#|將 `heap2` 的資料統統加到 `this` 中, 並且清空 `heap2` + //# 時間複雜度中的M是 `heap2` 的資料數 void merge(MergeableHeap* _heap2); + + //#|============================================== }; - - /********************************************************* - @asciidoc - === meow:: *MergeableHeap<Key, Value>* (C++ class) - .Description - MergeableHeap is a kind of maximum-heap with a special method `merge`, - which will merge another MergeableHeap into itself in O(logN) time. - - .Template Request - * `Key` should has `operator<` - - .Support methods - * N <- number of elements in the heap - * M <- number of elements in the other heap if need - [options="header",width="100%",cols="1>,1<s,3<,1<,1<,10<",grid="rows"] - |======================================================================= - |Const?|Name| Parameters| Return Type| Time Complexity| Description - ||operator= | (MergeableHeap const&)| *this | O(N) - | Copy operator. - ||moveTo | (MergeableHeap*) | void | O(M) - | Transform the this->data to the heap specified in parameters - |const|top | () | Element | O(1) - | Return the maximum element in the heap. - |const|size | () | size_t | O(1) - | Return the number of elements in the heap. - |const|empty| () | bool | O(1) - | Return whether the heap is empty or not. - ||push |(Element) |void | O(log N) - | Add a element into the heap - ||pop |() |void | O(log N) - | Delete the maximum element from the heap - ||merge |(MergeableHeap*) |void | O(log M) - | Merge the specified MergeableHeap(with size=M) into itself - ||clear |() |void | O(N) - | Delete all elements from the heap - |======================================================================= - -WARNING: Consider there are two MergeableHeap `A` and `B`. + -`B` will become empty after you call `A.merge(&B)`. + -The data in `B` will override by data in `A` and `A` will become empty after -you call `A.moveTo(&B)` - -''' -@asciidoc- - *********************************************************/ + //# [WARNING] + //#============================================== + //# * 假設現在有兩個MergeableHeap `A` 和 `B`, 則: + //# ** 執行 `A.merge(&B)` 後 `B` 會變成空的 + //# ** 執行 `B.moveTo(&A)` 後 `B` 會變成空的, `A` 原本擁有的資料也會覆蓋掉 + //#============================================== + //# + //# ''' + //# } #include "MergeableHeap.hpp" diff --git a/meowpp/dsa/MergeableHeap.hpp b/meowpp/dsa/MergeableHeap.hpp index be7dcea..e7f5978 100644 --- a/meowpp/dsa/MergeableHeap.hpp +++ b/meowpp/dsa/MergeableHeap.hpp @@ -92,7 +92,7 @@ namespace meow{ return (root == NULL ? 0 : root->weight); } template<class Element> // empty - inline size_t MergeableHeap<Element>::empty() const{ return (size() == 0); } + inline bool MergeableHeap<Element>::empty() const{ return (size() == 0); } ////////////////////////////////////////////////////////// // **# MergeableHeap -- update: push, pop, merge #** // ////////////////////////////////////////////////////////// diff --git a/meowpp/dsa/SegmentTree.h b/meowpp/dsa/SegmentTree.h index 585ea5d..89fd5d9 100644 --- a/meowpp/dsa/SegmentTree.h +++ b/meowpp/dsa/SegmentTree.h @@ -2,6 +2,30 @@ #define SegmentTree_H__ namespace meow{ + //# + //#=== meow:: *SegmentTree<Value>* (C++ class) + //#==== Description + //# 維護一個陣列, 並且讓user可以有區間查詢, 區間修改的小東東 + //# + //#==== Template Class Operators Request + //#[options="header",width="70%",cols="1>m,1<,3<s,5<,3<,15<",grid="rows"] + //#|===================================================================== + //#|Const?|Typename| Operator | Parameters |Return_Type| Description + //#|const |Value |operator+ |(Value `v`)|Value | 相加(位移) + //#|const |Value |operator* |(size_t `n`)|Value | 每個Value都一樣, + //# 長為 `n` 的區間的值 + //#|const |Value |operator{b}|(Value `v`)|Value | 區間合併後的值 + //#|===================================================================== + //# + //# * 若要維護區間最小值, 即每次都是詢問範圍 `[a, b]` 的最小值, 則可以定義 + //# ** `operator+` 為 '回傳相加值' + //# ** `operator*` 為 '回傳*this' + //# ** `operator|` 為 '回傳std::min(*this, v)' + //# * 若要維護區間最總和, 即每次都是詢問範圍 `[a, b]` 的總和, 則可以定義 + //# ** `operator+` 為 '回傳相加值' + //# ** `operator*` 為 '回傳(*this) * n' + //# ** `operator|` 為 '回傳相加值' + //# template<class Value> class SegmentTree{ private: @@ -28,11 +52,38 @@ namespace meow{ SegmentTree(size_t __size); SegmentTree(SegmentTree const& __tree2); // + //#==== Support Methods + //# + //# * N <- `this` 所維護的陣列長度 + //# + //#[options="header",width="100%",cols="1>m,2>s,7<,3<,3^,20<",grid="rows"] + //#|===================================================================== + //#|Const?|Name | Parameters | Return_Type| Time_Complexity| Description + + + //#||reset|(size_t `size`)|void|O(1) + //#|將資料清空且設定維護範圍是 `0~size - 1` 其中時間複雜度確切多少未知 + //# 要看 `std::vector::resize()` 的效率 void reset(size_t __size); - // + + + //#|const|query|(ssize_t `first`,\ssize_t `last`)|Value|O(logN) + //#|回傳區間 `[first,last]` (邊界都含) 的區間值 Value query (ssize_t __first, ssize_t __last) const; + + + //#||override|(ssize_t `first`,\ssize_t `last`,\Value const& `value`) + //#|void|O(logN) + //#|將區間 `[first,last]` 全部都設定成 `value` void override(ssize_t __first, ssize_t __last, Value const& __value); + + + //#||offset|(ssize_t `first`,\ssize_t `last`,\Value const& `delta`) + //#|void|O(logN) + //#|將區間 `[first,last]` 全部都加上 `delta` void offset (ssize_t __first, ssize_t __last, Value const& __delta); + + // void print(){ for(int i = 0; i < _size; i++){ query(i, i); @@ -52,52 +103,9 @@ namespace meow{ printf("\n"); } } + + //#|============================================== }; - /********************************************************* - @asciidoc - === meow:: *SegmentTree<Value>* (C++ class) - .Description - `SegmentTree` is a data structure that can maintain an array, and - support *range update* , *range query* - - .Template Request - * `Value` should has - ** `operator+(Value)` offset - ** `operator|(Value)` merge two nodes - ** `operator*(size_t)` ?? - - For example, if you want to maintain *range minimum* - - * `Value::operator+(Value v2)` will be `this->realValue + v2.realValue` - * `Value::operator|(Value v2)` will be `std::min(this->realValue, v2.realValue)` - * `Value::operator*(size_t n)` will be `this->realValue` - - If you want to maintain *range sum* - - * `Value::operator+(Value v2)` will be `this->realValue + v2.realValue` - * `Value::operator|(Value v2)` will be `this->realValue + v2.realValue)` - * `Value::operator*(size_t n)` will be `this->realValue * n` - - .Support methods - * N <- array size - [options="header",width="100%",cols="1>,1<s,3<,1<,1<,10<",grid="rows"] - |======================================================================= - |Const?|Name| Parameters| Return Type| Time Complexity| Description - ||reset|(size_t N)|void|O(1)| - Clear and reset the array size to N (from `0` to `N - 1`) - |const|query|(ssize_t __first, ssize_t __last)|Value|O(logN)| - Range query - ||override|(ssize_t __first, ssize_t __last, Value const& __value)|void| - O(logN)| Let the element in the array index from `__first` to `__last` - be `__value` - ||offset|(ssize_t __first, ssize_t __last, Value const& __value)|void| - O(logN)| Let the element in the array index from `__first` to `__last` - plus `__value` - |======================================================================= - -''' -@asciidoc- - *********************************************************/ } #include "SegmentTree.hpp" diff --git a/meowpp/dsa/SplayTree.h b/meowpp/dsa/SplayTree.h index f738ded..f8cdd20 100644 --- a/meowpp/dsa/SplayTree.h +++ b/meowpp/dsa/SplayTree.h @@ -4,6 +4,22 @@ #include "utility.h" namespace meow{ + //# + //#=== meow:: *SplayTree<Key, Value>* (C++ class) + //#==== Description + //# `SplayTree` 是一種神乎其技的資料結構, 維護一堆 Key->Value . 並且支援 + //# 一些 `std::map` 難以快速實踐的操作, 如 `split` , `merge` , `keyOffset` + //# + //#==== Template Class Operators Request + //#[options="header",width="70%",cols="1>m,1<,3<s,5<,3<,15<",grid="rows"] + //#|===================================================================== + //#|Const?|Typename| Operator| Parameters | Return_Type| Description + //#|const |Key |operator+|(Key `k`) | Key | 相加 + //#|const |Key |operator<|(Key `k`) | bool | 大小比較 + //#| |Key |'Key' |(int `n`) | | 建構子, `n` 永遠是0 + //#| |Value | 'Value' |( ) | | 建構子 + //#|===================================================================== + //# template<class Key, class Value> class SplayTree{ private: @@ -44,6 +60,14 @@ namespace meow{ // void print(Node* __now, int __depth) const; public: + //#==== Custom Type Definitions + //# + //# * `Element` -> 用來當作回傳資料的媒介 + //# ** 重定義 `operator->()` 到 `std::pair<Key const&, Value&>*` + //# ** 重定義 `operator*()` 到 `std::pair<Key const&, Value&>&` + //# ** 有 `operator==` , `operator!=`, `operator=` 可用 + //# ** 可以直接用 `(*e).second = some_value` 來改變SplayTree中的資料 + //# class Element{ private: typedef std::pair<Key const&, Value&> Entry; @@ -69,109 +93,146 @@ namespace meow{ SplayTree(); SplayTree(SplayTree const& __tree2); ~SplayTree(); - // SplayTree& operator=(SplayTree const& __tree2); - void moveTo(SplayTree* __tree2); // + //#==== Support Methods + //# + //# * N <- `this` 中擁有的資料數 + //# * M <- `tree2` 中擁有的資料數 + //# + //#[options="header",width="100%",cols="1>m,3>s,7<,3<,3^,20<",grid="rows"] + //#|===================================================================== + //#|Const?|Name | Parameters | Return_Type| Time_Complexity| Description + + + //#||moveTo|(SplayTree* `tree2`)|void|O(M) + //#|將 `this` 的資料複寫到 `tree2` 上面, 同時清空自己, + //# 時間複雜度中的M是 `tree2` 所擁有的資料數 + void moveTo(SplayTree* __tree2); + + + //#|const|lowerBound|(Key const& `k`)|Element|O(logN) + //#|找出第一個(最小的) Element且 `k` <= 它的 Key, 並且回傳之. + //# 找不到的話回傳 `this->end()` Element lowerBound(Key const& __key) const; + + + //#|const|lowerBound|(Key const& `k`)|Element|O(logN) + //#|找出第一個(最小的) Element且 `k` < 它的 Key, 並且回傳之. + //# 找不到的話回傳 `this->end()` Element upperBound(Key const& __key) const; + + + //#|const|lowerBound|(Key const& `k`)|Element|O(logN) + //#|找出第一個(最小的) Element且 `k` >= 它的 Key, 並且回傳之. + //# 找不到的話回傳 `this->end()` Element rLowerBound(Key const& __key) const; + + + //#|const|lowerBound|(Key const& `k`)|Element|O(logN) + //#|找出第一個(最小的) Element且 `k` > 它的 Key, 並且回傳之. + //# 找不到的話回傳 `this->end()` Element rUpperBound(Key const& __key) const; + + + //#|const|find|(Key const& `k`)|Element|O(logN) + //#|找出 Key= `k` 的Elemenet 並回傳. 找不到的話回傳 `this->end()` Element find (Key const& __key) const; - Element order(size_t __order ) const; - Element first( ) const; - Element last ( ) const; - Element end( ) const; - // + + + //#|const|order|(size_t `ord`)|Element|O(logN) + //#|將Elements依照Key由小到大排序, 回傳第 `ord` 個Element (由0算起). + //# 其中如果 `ord` > N - 1, 則會回傳 `this->last()` + Element order(size_t __order) const; + + + //#|const|first|(size_t `ord`)|Element|O(logN) + //#|回傳Key最小的Element, 如果SplayTree為空, 則回傳 `this->end()` + Element first() const; + + + //#|const|last|(size_t `ord`)|Element|O(logN) + //#|回傳Key最大的Element, 如果SplayTree為空, 則回傳 `this->end()` + Element last() const; + + + //#|const|end|()|Element|O(1) + //#|回傳一個指向NULL的Element, 以供 `find` , `order` , `first` + //# , `last` 等判斷是否有找到相對應的Element + Element end() const; + + + //#|const|size|()|size_t|O(1)| 回傳資料數 size_t size() const; + + + //#|const|size|()|bool|O(1)| 回傳是否為空 bool empty() const; - // - void clear(); - void keyOffset(Key const& __delta); - bool insert (Key const& __key, Value const& __value); - bool erase (Key const& __key); + + + //#||clear|()|void|O(N)| 清空資料 + void clear(); + + + //#||keyOffset|(Key const& `delta`)|void|O(1) + //#|將所有Element的Key同加上 `delta` + void keyOffset(Key const& __delta); + + + //#||insert|(Key const& `key`,\Value const& `value`)|bool|O(logN) + //#|檢查是否已有Element的Key 為 `key`, 若有則回傳 `false` , 否則將 + //# 一個 (Key -> Value) = (`key` -> `value`)的Element加入, 並回傳 `true` + //# 將所有Element的Key同加上 `delta` + bool insert(Key const& __key, Value const& __value); + + + //#||erase|(Key const& `key`)|bool|O(logN) + //#|檢查是否已有Element的Key 為 `key`, 若有則刪除之, 並回傳 `true`, + //# 否則則回傳 `false` + bool erase(Key const& __key); + + + //#||operator[]|(Key const& `key`)|Value&|O(logN) + //#|檢查是否已有Element的Key 為 `key`, 若有則回傳相對應的Value的Reference + //# 否則先執行 `insert(key, Value())` 再回傳相對應的Reference Value& operator[](Key const& __key); - void splitOut(Key const& __upper_bound, SplayTree* __right); - bool mergeAfter(SplayTree* __tree2); - bool merge (SplayTree* __tree2); + + + //#||splitOut|(Key const& `upper_bound`,\SplayTree* `tree2`)|void + //#|O(logN) + O(M) + //#|將 `tree2` 清空, 再將所有Key > `upper_bound` 的Element都丟到 `tree2` + void splitOut(Key const& __upper_bound, SplayTree* __right); + + + //#||mergeAfter|(SplayTree* `tree2`)|void|O(logN) + O(logM) + //#|檢查是否 `this` 中的 Key 都小於 `tree2` 中的Key, 是的話把 `tree2` + //# 中的 Element 都搬到 `this` , 同時清空 `tree2` , 回傳 `true`. 否則 + //# 回傳 `false` + bool mergeAfter(SplayTree* __tree2); + + + //#||merge|(SplayTree* `tree2`)|void|O(logN) + O(logM) + //#|檢查是否 `this` 中的 Key 都小於 `tree2` 中的Key 或者 + //# 是否 `this` 中的 Key 都大於 `tree2` 中的Key, 是的話把 `tree2` + //# 中的 Element 都搬到 `this` , 同時清空 `tree2` , 回傳 `true`. 否則 + //# 回傳 `false` + bool merge(SplayTree* __tree2); + // // void print() const; + //#|===================================================================== }; - /********************************************************* - @asciidoc - === meow:: *SplayTree<Key, Value>* (C++ class) - .Description - Like `std::map`, `SplayTree` is an dictionary(key->value). But it has - some extra method, such as `split()`, `merge()`, `keyOffset()`. - - .Data Type - * `Key` is the tyepname of the key - * `Value` is the typename of value - * `SplayTree<Key, Value>:: *Element* ` is a typename which contain - (key->value). It has some methods below: - ** `->first ` a constant reference to `Key` - ** `->second` a reference to `Value` - ** `operator==, operator!=` compare function, check if the two `Element` - is pointer to the same (key->value) - - .Template Request - * `Key` should has `operator<`, `operator+` - - .Support Methods - * N <- numbers of element in the SplayTree - * M <- numbers of element in another SplayTree - [options="header",width="100%",cols="1>,1<s,5<,1<,3^,10<",grid="rows"] - |======================================================================= - |Const?|Name| Parameters| Return Type| Time Complexity| Description - ||operator=|(SplayTree const&)| *this | O(N) | copy operator - ||moveTo|(SplayTree* t)|void|O(M)| Transform the data in this to `t` - |const|lowerBound|(Key k)|Element|O(logN)| Find the smallest (key->value) - which `k <= key` and return - |const|upperBound|(Key k)|Element|O(logN)| Find the smallest (key->value) - which `k < key` and return - |const|rLowerBound|(Key k)|Element|O(logN)| Find the largest (key->value) - which `key <= k` and return - |const|rUpperBound|(Key k)|Element|O(logN)| Find the largest (key->value) - which `key < k` and return - |const| find|(Key k)|Element|O(logN)| Find the element (key->value) which - `key == k` and return - |const|order|(size_t k)|Element|O(logN)| Find the `k`-th small element. - note that `k` start from zero like a normal C/C++ array. - |const|first|()|Element|O(logN)| Return the smallest element - |const|last|()|Element|O(logN)| Return the largest element - |const|end|()|Element|O(1)|Return an empty element(it can be use to - check if `find()` is successful) - |const|size|()|size_t|O(1)| Return number of elements in the tree - |const|empty|()|bool|O(1)|Return whether the tree is empty - ||clear|()|void|O(N)|Clear - ||keyOffset|(Key offset)|void|O(1)| Let all the keys in the tree - plus offset - ||insert|(Key k, Value v)|bool | O(logN)| Insert an element. - If the tree already has an element with same key, return `false`. - ||erase|(Key k)|bool | O(logN)|Erase an element from the tree with - given key. Return `false` if the element not found. - ||operator[]|(Key k)|Value|O(logN)|Like `find()` , but it will insert an element - automatic if the corrosponding element not found - ||splitOut|(Key const& upper_bound, + - SplayTree* out)|void | O(log N) | Split out all the elements with key - larger than `upper_bound` and store then into `out` - ||mergeAfter|(SplayTree* t)|bool|O(logN + logM)|If not all of the elements in this - are smaller than elements in `t`, return `false` , else merge `t` into - itself and return `true`. - ||merge|(SplayTree* t)|bool|O(logN + logM)|If all of the elements in this - are smaller than elements in `t` or all of the elements in this larger than - elements in `t` , merge `t` into itself and return `true`. - Else return `false` - |======================================================================= -WARNING: Consider there are two SplayTree `A` and `B`. + -`B` will become empty after you call `A.mergeAfter(&B)` -or `A.merge(&B)` successful. + -The data in `B` will override by data in `A` and `A` will become empty after -you call `A.moveTo(&B)` - -''' -@asciidoc- - *********************************************************/ + //# + //#[NOTE] + //#======================================== + //# * 假設現在有兩個SplayTree `A` 和 `B`, 則: + //# ** 執行 `B.moveTo(&A)` 後 `B` 會變成空的, `A` 原本擁有的資料也會覆蓋掉 + //# ** 執行 `A.merge(&B)` 或 `A.mergeAfter(&B)` 後 + //# 如果檢查發現確實可以merge, 則之後 `B` 會變成空的 + //#======================================== + //# + //# ''' + //# } #include "SplayTree.hpp" diff --git a/meowpp/dsa/SplayTree.hpp b/meowpp/dsa/SplayTree.hpp index 47615db..77331ef 100644 --- a/meowpp/dsa/SplayTree.hpp +++ b/meowpp/dsa/SplayTree.hpp @@ -31,7 +31,7 @@ namespace meow{ SplayTree<Key, Value>::offsetDown(Node* __node) const{ if(__node->_lChild != NULL) offsetAdd(__node->_lChild, __node->_keyOffset); if(__node->_rChild != NULL) offsetAdd(__node->_rChild, __node->_keyOffset); - __node->_keyOffset = 0; + __node->_keyOffset = Key(0); } // template<class Key, class Value> diff --git a/meowpp/utility.h b/meowpp/utility.h index 4f3b36a..ec47225 100644 --- a/meowpp/utility.h +++ b/meowpp/utility.h @@ -40,59 +40,74 @@ namespace meow{ template<class T> inline double average(T const& beg, T const& end, T const& p, double sigs); - /******************************************************************* - @asciidoc - === meow:: *Functios* in utility.h - [options="header",width="100%",cols="1>s,5<,1<,10<",grid="rows"] - |============================================================== - |Name | Parameters | Return Type | Description - |stringPrintf |(char const * fmt, ...)|std::string | - Format print to C++ string and return it - |stringReplace |(std::string str, + - std::string const& from, + - std::string const& to) | std::string | - Return a string like `str`, but all `from` be replaced by `to` - |cstringEndWith |(char const* str, int n, ...) | bool | - Return whether `str` is end with one of the c-string you specify in - the parameters or not - |debugPrintf |(char const* fmt, ...) | void| - Print debug message (file name, line number, ...etc) when `DEBUG` is - defined - |messagePrintf |(int level_change, char const* fmt, ...) | void| - 階層式的訊息輸出 - |noEPS |(double value, double eps = 1e-9) | double | - 如果abs(輸入的數值) < eps, 則回傳0, 否則回傳輸入的數值 - |normalize |(double lower, double upper, + - double value) | double | - (value - lower) / (upper - lower) - |denormalize |(double lower, double upper, + - double ratio) | double | - lower + (upper - lower) * ratio - |ratioMapping |(double l1, double u1, + - double m1, double l2, + - double u2) - | double | - denormalize(l2, u2, normalize(l1, u1, m1)) - |inRange<T> |(T const& mn, T const& mx, + - T const& v) | T | - std::max(mn, std::min(mx, v)) - |squ<T> |(T const& x) | T| - x * x - |average<T>|(T const& beg, T const& end, + - double sigs)| T| - 只將 `sigs` 個標準差以內的數據拿來取平均 - |average<T>|(T const& beg, T const& end, + - T const& p, double sigs)| T| - 同上, 不過這次用 `p` 來加權平均 - |============================================================== - - [NOTE] - `stringReplace()` 不是用什麼好方法寫的因此執行效率很低請別虐待它. + - 額外附贈一個 `const double PI = 3.141592653589......` - -''' -@asciidoc- - ******************************************************************/ + //# === meow:: *Functios* in utility.h + //# [options="header",width="100%",cols="1>s,5<,1<,10<",grid="rows"] + //# |============================================================== + //# |Name | Parameters | Return_Type | Description + //# |stringPrintf |(char const * `fmt`, ...) | std::string + //# |Format print to C++ string and return it + + + //# |stringReplace |(std::string `str`,\ + //# std::string const& `from`,\ + //# std::string const& `to`) | std::string + //# |Return a string like `str`, but all `from` be replaced by `to` + + + //# |cstringEndWith |(char const* `str`,\int `n`, ...) | bool + //# |Return whether `str` is end with one of the c-string you specify in + //# the parameters or not + + + //# |debugPrintf |(char const* `fmt`, ...) | void + //# |Print debug message (file name, line number, ...etc) when `DEBUG` is + //# defined + + + //# |messagePrintf |(int `level_change`,\char const* `fmt`, ...) | void + //# |階層式的訊息輸出 + + + //# |noEPS |(double `value`, double `eps` = 1e-9) | double | + //# 如果abs(輸入的數值) < eps, 則回傳0, 否則回傳輸入的數值 + + + //# |normalize |(double `lower`, double `upper`, \ double value) + //# | double | `(value - lower) / (upper - lower)` + + + //# |denormalize |(double `lower`, double `upper`, + //# \ double `ratio`) | double | `lower + (upper - lower) * ratio` + + + //# |ratioMapping |(double `l1`, double `u1`, + //# \double `m1`, double `l2`,\double `u2`) + //# | double | `denormalize(l2, u2, normalize(l1, u1, m1))` + + + //# |inRange<T> |(T const& `mn`, T const& `mx`, \ T const& `v`) | T | + //# `std::max(mn, std::min(mx, v))` + + + //# |squ<T> |(T const& `x`) | T| `x * x` + + + //# |average<T>|(T const& `beg`, T const& `end`, \ double `sigs`)| T| + //# 只將 `sigs` 個標準差以內的數據拿來取平均 + + + //# |average<T>|(T const& `beg`, T const& `end`, + //# \ T const& `p`, double `sigs`)| T| 同上, 不過這次用 `p` 來加權平均 + //# |============================================================== + //# + //# [NOTE] + //# ==================================== + //# * `stringReplace()` 不是用什麼好方法寫的因此執行效率很低請別虐待它. + //# * 額外附贈一個 `const double PI = 3.141592653589......` + //# ==================================== + //# + //# ''' + //# } #include "utility.hpp" diff --git a/readme_generate.py b/readme_generate.py index b7da90c..2ee5cc4 100755 --- a/readme_generate.py +++ b/readme_generate.py @@ -4,8 +4,9 @@ import sys; import os; class Reader(): - def __init__(self, suffix): + def __init__(self, suffix, stp): self.suffix = suffix; + self._stop = stp; # def checkOk(self, pathname): for suffix in self.suffix: @@ -19,19 +20,22 @@ class Reader(): return self.getOutputString(input_string); def getOutputString(self, input_string): return '' + def stop(self): + return self._stop; # class AsciidocReader(Reader): def __init__(self): Reader.__init__(self, ['.asciidoc', '.adoc', '.ascii', - ]); + ], + True); def getOutputString(self, input_string): return input_string; # class InReader(Reader): def __init__(self, suffix, start_string, end_string): - Reader.__init__(self, suffix); + Reader.__init__(self, suffix, False); self.start_string = start_string; self. end_string = end_string; def getOutputString(self, input_string): @@ -58,15 +62,48 @@ class InReader(Reader): index += 1; return ret; # +class InLineReader(Reader): + def __init__(self, suffix, prefix): + Reader.__init__(self, suffix, False); + self.prefix = prefix; + def getOutputString(self, input_string): + ret = ''; + line_begin = 0; + while line_begin < len(input_string): + line_end = line_begin; + for line_end in range(line_begin, len(input_string) + 1): + if input_string[line_end] == "\n": + break; + ok = False; + for i in range(line_begin, line_end - len(self.prefix) + 1): + if input_string[i : i + len(self.prefix)] == self.prefix: + ok = True; + break; + if ok: + start = i + len(self.prefix); + while start < line_end: + if input_string[start]!=' ' and input_string[start]!="\t": + break; + start += 1; + ret += input_string[start: line_end].replace('\\', " +\n")+"\n"; + line_begin = line_end + 1; + return ret; +# class CppReader(InReader): def __init__(self): InReader.__init__(self, ['.c', '.cpp', '.h', '.hpp'], '@asciidoc', '@asciidoc-'); +class CppLineReader(InLineReader): + def __init__(self): + InLineReader.__init__(self, + ['.c', '.cpp', '.h', '.hpp'], + '//#'); # readers = [AsciidocReader(), CppReader(), + CppLineReader(), ]; if len(sys.argv) <= 1: readme = 'README.asciidoc'; @@ -82,9 +119,12 @@ for (root, sub_folders, files) in os.walk('./'): if path == './' + readme: continue; if reader.checkOk(filename): - print 'Get asciidoc from ' + path; - readme_f.write(reader.read(path)); - deleted.append(filename); + s = reader.read(path); + if len(s) > 0: + print 'Get asciidoc from ' + path; + readme_f.write(s); + if reader.stop(): + deleted.append(filename); for filename in deleted: files.remove(filename); readme_f.close(); |