diff --git a/README.md b/README.md
index d64c7d91..fd16f005 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ STL (Standard Template Library) Containers and Algorithms for TypeScript
TypeScript-STL is an open-source JavaScript library providing containers and algorithms migrated from C++ STL. You can enjoy STL containers and algorithms in JavaScript. If TypeScript, you will be much happier feeling like using originla STL with type restriction and template programming.
-![Abstract Containers](http://samchon.github.io/typescript-stl/api/assets/images/design/abstract_containers.png)
+![Abstract Containers](http://samchon.github.io/typescript-stl/images/design/class_diagram/abstract_containers.png)
##### Containers
- [**Linear containers**](http://samchon.github.io/typescript-stl/api/interfaces/std.base.container.ilinearcontainer.html)
diff --git a/api/assets/images/design/abstract_containers.png b/api/assets/images/design/abstract_containers.png
deleted file mode 100644
index 6c178886..00000000
Binary files a/api/assets/images/design/abstract_containers.png and /dev/null differ
diff --git a/api/assets/images/design/exceptions.png b/api/assets/images/design/exceptions.png
deleted file mode 100644
index 65fc6d3b..00000000
Binary files a/api/assets/images/design/exceptions.png and /dev/null differ
diff --git a/api/assets/images/design/linear_containers.png b/api/assets/images/design/linear_containers.png
deleted file mode 100644
index c15b5767..00000000
Binary files a/api/assets/images/design/linear_containers.png and /dev/null differ
diff --git a/api/assets/images/design/map_containers.png b/api/assets/images/design/map_containers.png
deleted file mode 100644
index 94231562..00000000
Binary files a/api/assets/images/design/map_containers.png and /dev/null differ
diff --git a/api/assets/images/design/set_containers.png b/api/assets/images/design/set_containers.png
deleted file mode 100644
index cccfac6a..00000000
Binary files a/api/assets/images/design/set_containers.png and /dev/null differ
diff --git a/api/assets/images/tree/Red-black_tree_delete_case_2.svg b/api/assets/images/tree/Red-black_tree_delete_case_2.svg
deleted file mode 100644
index b2dbd693..00000000
--- a/api/assets/images/tree/Red-black_tree_delete_case_2.svg
+++ /dev/null
@@ -1,1145 +0,0 @@
-
-
-
-
-
-
diff --git a/api/assets/images/tree/Red-black_tree_delete_case_3.svg b/api/assets/images/tree/Red-black_tree_delete_case_3.svg
deleted file mode 100644
index 25216d1c..00000000
--- a/api/assets/images/tree/Red-black_tree_delete_case_3.svg
+++ /dev/null
@@ -1,944 +0,0 @@
-
-
-
-
-
-
diff --git a/api/assets/images/tree/Red-black_tree_delete_case_4.svg b/api/assets/images/tree/Red-black_tree_delete_case_4.svg
deleted file mode 100644
index 354e6f75..00000000
--- a/api/assets/images/tree/Red-black_tree_delete_case_4.svg
+++ /dev/null
@@ -1,958 +0,0 @@
-
-
-
-
-
-
diff --git a/api/assets/images/tree/Red-black_tree_delete_case_5.svg b/api/assets/images/tree/Red-black_tree_delete_case_5.svg
deleted file mode 100644
index d6bea65a..00000000
--- a/api/assets/images/tree/Red-black_tree_delete_case_5.svg
+++ /dev/null
@@ -1,755 +0,0 @@
-
-
-
-
-
-
diff --git a/api/assets/images/tree/Red-black_tree_delete_case_6.svg b/api/assets/images/tree/Red-black_tree_delete_case_6.svg
deleted file mode 100644
index 24c31884..00000000
--- a/api/assets/images/tree/Red-black_tree_delete_case_6.svg
+++ /dev/null
@@ -1,865 +0,0 @@
-
-
-
-
-
-
diff --git a/api/assets/images/tree/Red-black_tree_example.svg b/api/assets/images/tree/Red-black_tree_example.svg
deleted file mode 100644
index ae642196..00000000
--- a/api/assets/images/tree/Red-black_tree_example.svg
+++ /dev/null
@@ -1,812 +0,0 @@
-
-
-
diff --git a/api/assets/images/tree/Red-black_tree_insert_case_3.svg b/api/assets/images/tree/Red-black_tree_insert_case_3.svg
deleted file mode 100644
index c3d96f50..00000000
--- a/api/assets/images/tree/Red-black_tree_insert_case_3.svg
+++ /dev/null
@@ -1,730 +0,0 @@
-
-
-
-
-
-
diff --git a/api/assets/images/tree/Red-black_tree_insert_case_4.svg b/api/assets/images/tree/Red-black_tree_insert_case_4.svg
deleted file mode 100644
index 2a4f1360..00000000
--- a/api/assets/images/tree/Red-black_tree_insert_case_4.svg
+++ /dev/null
@@ -1,866 +0,0 @@
-
-
-
-
-
-
diff --git a/api/assets/images/tree/Red-black_tree_insert_case_5.svg b/api/assets/images/tree/Red-black_tree_insert_case_5.svg
deleted file mode 100644
index 1da108ca..00000000
--- a/api/assets/images/tree/Red-black_tree_insert_case_5.svg
+++ /dev/null
@@ -1,873 +0,0 @@
-
-
-
-
-
-
diff --git a/lib/typescript-stl.d.ts b/lib/typescript-stl.d.ts
index a949dd0a..d05d3bc3 100644
--- a/lib/typescript-stl.d.ts
+++ b/lib/typescript-stl.d.ts
@@ -1,4 +1,4 @@
-// Type definitions for TypeScript-STL v1.0.0-rc.3
+// Type definitions for TypeScript-STL v1.0.0
// Project: https://github.com/samchon/typescript-stl
// Definitions by: Jeongho Nam Apply function to range. An abstract container.
- * There is not a single type of {@link Iterator bidirectional iterator}: {@link IContainer Each container}
* may define its own specific iterator type able to iterate through it and access its elements.
- *
+ *
- *
+ *
+ *
*
*
Container properties
@@ -2872,8 +2865,8 @@ declare namespace std {
*
+ *
*
+ *
*
- *
+ *
+ *
*
Row size of the {@link matrix_ matrix} which contains elements.
- * - *Note that the {@link ROW} affects on time complexity of accessing and inserting element. - * Accessing element is {@link ROW} times slower than ordinary {@link Vector} and inserting element - * in middle position is {@link ROW} times faster than ordinary {@link Vector}.
- * - *When the {@link ROW} returns 8, time complexity of accessing element is O(8) and inserting - * element in middle position is O(N/8). ({@link Vector}'s time complexity of accessement is O(1) - * and inserting element is O(N)).
+ * @hidden */ private static ROW; /** - *Minimum {@link capacity}.
- * - *Although a {@link Deque} has few elements, even no element is belonged to, the {@link Deque} - * keeps the minimum {@link capacity} at least.
+ * @hidden */ private static MIN_CAPACITY; /** - *A matrix containing elements.
- * - *This {@link matrix_} is the biggest difference one between {@link Vector} and {@link Deque}. - * Its number of rows follows {@link ROW} and number of columns follows {@link get_col_size} which - * returns divide of {@link capacity} and {@link ROW}.
- * - * By separating segment of elements (segment: row, elements in a segment: col), {@link Deque} takes - * advantage of time complexity on inserting element in middle position. {@link Deque} is {@link ROW} - * times faster than {@link Vector} when inserting elements in middle position. - * - *However, separating segment of elements from matrix, {@link Deque} also takes disadvantage of - * time complexity on accessing element. {@link Deque} is {@link ROW} times slower than {@link Vector} - * when accessing element.
+ * @hidden */ private matrix_; /** - * Number of elements in the {@link Deque}. + * @hidden */ private size_; /** - *Size of allocated storage capacity.
- * - *The {@link capacity_ capacity} is size of the storage space currently allocated for the - * {@link Deque container}, expressed in terms of elements.
- * - *This {@link capacity_ capacity} is not necessarily equal to the {@link Deque container} - * {@link size}. It can be equal or greater, with the extra space allowing to accommodate for growth - * without the need to reallocate on each insertion.
- * - *Notice that this {@link capacity_ capacity} does not suppose a limit on the {@link size} of - * the {@link Deque container}. When this {@link capacity} is exhausted and more is needed, it is - * automatically expanded by the {@link Deque container} (reallocating it storage space). - * The theoretical limit on the {@link size} of a {@link Deque container} is given by member - * {@link max_size}.
- * - *The {@link capacity_ capacity} of a {@link Deque container} can be explicitly altered by - * calling member {@link Deque.reserve}.
+ * @hidden */ private capacity_; /** - * Get column size; {@link capacity_ capacity} / {@link ROW row}. + * @hidden */ private get_col_size(); /** @@ -3480,8 +3434,8 @@ declare namespace std { /** *An iterator of {@link Deque}.
* - *
- *
+ *
+ *
*
A reverse-iterator of Deque.
* - *
- *
+ *
+ *
*
All objects thrown by components of the standard library are derived from this class. * Therefore, all standard exceptions can be caught by catching this type by reference.
* - * + * * * @reference http://www.cplusplus.com/reference/exception/exception * @author Jeongho NamIt is used as a base class for several logical error exceptions.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/logic_error * @author Jeongho NamNo component of the standard library throws exceptions of this type. It is designed as a standard * exception to be thrown by programs.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/domain_error * @author Jeongho NamIt is a standard exception that can be thrown by programs. Some components of the standard library * also throw exceptions of this type to signal invalid arguments.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/invalid_argument * @author Jeongho NamIt is a standard exception that can be thrown by programs. Some components of the standard library, * such as vector and string also throw exceptions of this type to signal errors resizing.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/length_error * @author Jeongho NamIt is used as a base class for several runtime error exceptions.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/runtime_error * @author Jeongho NamIt is a standard exception that can be thrown by programs. Some components of the standard library * also throw exceptions of this type to signal range errors.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/overflow_error * @author Jeongho NamNo component of the standard library throws exceptions of this type. It is designed as a standard * exception to be thrown by programs.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/underflow_error * @author Jeongho NamIt is a standard exception that can be thrown by programs. Some components of the standard library * also throw exceptions of this type to signal range errors.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/range_error * @author Jeongho NamAn iterator of {@link MapContainer map container}.
* - * + * * * @author Jeongho NamA reverse-iterator of {@link MapContainer map container}.
* - * + * * * @author Jeongho Nam{@link HashMap} containers are faster than {@link TreeMap} containers to access individual elements by their * key, although they are generally less efficient for range iteration through a subset of their elements.
* - *
- *
+ *
+ *
*
Elements with equivalent keys are grouped together in the same bucket and in such a way that * an iterator can iterate through all of them. Iterators in the container are doubly linked iterators.
* - *
- *
+ *
+ *
*
An iterator of a Set.
* - * + * * * @author Jeongho NamA reverse-iterator of Set.
* - * + * * * @paramAn abstract set.
- * - *{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of - * individual elements based on their value.
- * - *In an {@link SetContainer}, the value of an element is at the same time its key, used to uniquely - * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be modified - * once in the container - they can be inserted and removed, though.
- * - *{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a - * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index - * table like {@link RBTree tree} or {@link HashBuckets hash-table}.
- * - * - * - *Extract an element.
- * - *Extracts the element pointed to by val and erases it from the {@link UniqueSet}.
- * - * @param val Value to be extracted. - * - * @return A value. - */ - extract(val: T): T; - /** - *Extract an element.
- * - *Extracts the element pointed to by key and erases it from the {@link UniqueMap}.
- * - * @param it An iterator pointing an element to extract. - * - * @return An iterator pointing to the element immediately following it prior to the element being - * erased. If no such element exists,returns {@link end end()}. - */ - extract(it: SetIteratorExtract an element.
- * - *Extracts the element pointed to by key and erases it from the {@link UniqueMap}.
- * - * @param it An iterator pointing an element to extract. - * - * @return An iterator pointing to the element immediately following it prior to the element being - * erased. If no such element exists,returns {@link end end()}. - */ - extract(it: SetReverseIteratorInsert an element.
- * - *Extends the container by inserting new elements, effectively increasing the container {@link size} by - * the number of element inserted (zero or one).
- * - *Because elements in a {@link UniqueSet UniqueSets} are unique, the insertion operation checks whether - * each inserted element is equivalent to an element already in the container, and if so, the element is not - * inserted, returning an iterator to this existing element (if the function returns a value).
- * - *For a similar container allowing for duplicate elements, see {@link MultiSet}.
- * - * @param key Value to be inserted as an element. - * - * @return A {@link Pair}, with its member {@link Pair.first} set to an iterator pointing to either the newly - * inserted element or to the equivalent element already in the {@link UniqueSet}. The - * {@link Pair.second} element in the {@link Pair} is set to true if a new element was inserted or - * false if an equivalent element already existed. - */ - insert(val: T): PairAn abstract set.
@@ -6124,8 +5956,8 @@ declare namespace std.base { * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index * table like {@link RBTree tree} or {@link HashBuckets hash-table}. * - * + * * *Hashed, unordered set.
+ *Hashed, unordered Multiset.
* - *{@link HashSet}s are containers that store unique elements in no particular order, and which - * allow for fast retrieval of individual elements based on their value.
+ *{@link HashMultiSet HashMultiSets} are containers that store elements in no particular order, allowing fast + * retrieval of individual elements based on their value, much like {@link HashSet} containers, + * but allowing different elements to have equivalent values.
* - *In an {@link HashSet}, the value of an element is at the same time its key, that - * identifies it uniquely. Keys are immutable, therefore, the elements in an {@link HashSet} cannot be + *
In an {@link HashMultiSet}, the value of an element is at the same time its key, used to + * identify it. Keys are immutable, therefore, the elements in an {@link HashMultiSet} cannot be * modified once in the container - they can be inserted and removed, though.
* - *Internally, the elements in the {@link HashSet} are not sorted in any particular order, but - * organized into buckets depending on their hash values to allow for fast access to individual elements - * directly by their values (with a constant average time complexity on average).
+ *Internally, the elements in the {@link HashMultiSet} are not sorted in any particular, but + * organized into buckets depending on their hash values to allow for fast access to individual + * elements directly by their values (with a constant average time complexity on average).
* - *{@link HashSet} containers are faster than {@link TreeSet} containers to access individual - * elements by their key, although they are generally less efficient for range iteration through a - * subset of their elements.
+ *Elements with equivalent values are grouped together in the same bucket and in such a way that an + * iterator can iterate through all of them. Iterators in the container are doubly linked iterators.
* - * + * * *An abstract set.
+ * + *{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of + * individual elements based on their value.
+ * + *In an {@link SetContainer}, the value of an element is at the same time its key, used to uniquely + * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be modified + * once in the container - they can be inserted and removed, though.
+ * + *{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a + * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index + * table like {@link RBTree tree} or {@link HashBuckets hash-table}.
+ * + * + * + *Extract an element.
+ * + *Extracts the element pointed to by val and erases it from the {@link UniqueSet}.
+ * + * @param val Value to be extracted. + * + * @return A value. + */ + extract(val: T): T; + /** + *Extract an element.
+ * + *Extracts the element pointed to by key and erases it from the {@link UniqueMap}.
+ * + * @param it An iterator pointing an element to extract. + * + * @return An iterator pointing to the element immediately following it prior to the element being + * erased. If no such element exists,returns {@link end end()}. + */ + extract(it: SetIteratorExtract an element.
+ * + *Extracts the element pointed to by key and erases it from the {@link UniqueMap}.
+ * + * @param it An iterator pointing an element to extract. + * + * @return An iterator pointing to the element immediately following it prior to the element being + * erased. If no such element exists,returns {@link end end()}. + */ + extract(it: SetReverseIteratorInsert an element.
+ * + *Extends the container by inserting new elements, effectively increasing the container {@link size} by + * the number of element inserted (zero or one).
+ * + *Because elements in a {@link UniqueSet UniqueSets} are unique, the insertion operation checks whether + * each inserted element is equivalent to an element already in the container, and if so, the element is not + * inserted, returning an iterator to this existing element (if the function returns a value).
+ * + *For a similar container allowing for duplicate elements, see {@link MultiSet}.
+ * + * @param key Value to be inserted as an element. + * + * @return A {@link Pair}, with its member {@link Pair.first} set to an iterator pointing to either the newly + * inserted element or to the equivalent element already in the {@link UniqueSet}. The + * {@link Pair.second} element in the {@link Pair} is set to true if a new element was inserted or + * false if an equivalent element already existed. + */ + insert(val: T): PairHashed, unordered Multiset.
+ *Hashed, unordered set.
* - *{@link HashMultiSet HashMultiSets} are containers that store elements in no particular order, allowing fast - * retrieval of individual elements based on their value, much like {@link HashSet} containers, - * but allowing different elements to have equivalent values.
+ *{@link HashSet}s are containers that store unique elements in no particular order, and which + * allow for fast retrieval of individual elements based on their value.
* - *In an {@link HashMultiSet}, the value of an element is at the same time its key, used to - * identify it. Keys are immutable, therefore, the elements in an {@link HashMultiSet} cannot be + *
In an {@link HashSet}, the value of an element is at the same time its key, that + * identifies it uniquely. Keys are immutable, therefore, the elements in an {@link HashSet} cannot be * modified once in the container - they can be inserted and removed, though.
* - *Internally, the elements in the {@link HashMultiSet} are not sorted in any particular, but - * organized into buckets depending on their hash values to allow for fast access to individual - * elements directly by their values (with a constant average time complexity on average).
+ *Internally, the elements in the {@link HashSet} are not sorted in any particular order, but + * organized into buckets depending on their hash values to allow for fast access to individual elements + * directly by their values (with a constant average time complexity on average).
* - *Elements with equivalent values are grouped together in the same bucket and in such a way that an - * iterator can iterate through all of them. Iterators in the container are doubly linked iterators.
+ *{@link HashSet} containers are faster than {@link TreeSet} containers to access individual + * elements by their key, although they are generally less efficient for range iteration through a + * subset of their elements.
* - * + * * *
- *
+ *
+ *
*
An iterator, node of a List.
* - *
- *
+ *
+ *
*
A reverse-iterator of List.
* - *
- *
+ *
+ *
*
- *
+ *
+ *
*
- *
+ *
+ *
*
The class inherits from {@link RuntimeError}, to which it adds an {@link ErrorCode} as * member code (and defines a specialized what member).
* - * + * * * @reference http://www.cplusplus.com/reference/system_error/system_error * @author Jeongho NamThe {@link ErrorCategory categories} associated with the {@link ErrorCondition} and the * {@link ErrorCode} define the equivalences between them.
* - * + * * * @reference http://www.cplusplus.com/reference/system_error/error_condition * @author Jeongho NamObjects of this class associate such numerical codes to {@link ErrorCategory error categories}, so that they * can be interpreted when needed as more abstract (and portable) {@link ErrorCondition error conditions}.
* - * + * * * @reference http://www.cplusplus.com/reference/system_error/error_code * @author Jeongho Nam{@link TreeMap}s are typically implemented as binary search trees.
* - * + * * *{@link TreeMultiMap TreeMultiMaps} are typically implemented as binary search trees.
* - * + * * * Tree-structured set, std::set
of STL.
Tree-structured multiple-key set.
* - *{@link TreeSet}s are containers that store unique elements following a specific order.
+ *{@link TreeMultiSet TreeMultiSets} are containers that store elements following a specific order, and + * where multiple elements can have equivalent values.
* - *In a {@link TreeSet}, the value of an element also identifies it (the value is itself the - * key, of type T), and each value must be unique. The value of the elements in a - * {@link TreeSet} cannot be modified once in the container (the elements are always const), but they - * can be inserted or removed from the
+ *In a {@link TreeMultiSet}, the value of an element also identifies it (the value is itself + * the key, of type T). The value of the elements in a {@link TreeMultiSet} cannot + * be modified once in the container (the elements are always const), but they can be inserted or removed + * from the
* - *Internally, the elements in a {@link TreeSet} are always sorted following a specific strict weak - * ordering criterion indicated by its internal comparison method (of {@link less}).
+ *Internally, the elements in a {@link TreeMultiSet TreeMultiSets} are always sorted following a strict + * weak ordering criterion indicated by its internal comparison method (of {@link IComparable.less less}).
* - *{@link TreeSet} containers are generally slower than {@link HashSet} containers to access - * individual elements by their key, but they allow the direct iteration on subsets based on their - * order.
+ *{@link TreeMultiSet} containers are generally slower than {@link HashMultiSet} containers + * to access individual elements by their key, but they allow the direct iteration on subsets based on + * their order.
* - *{@link TreeSet}s are typically implemented as binary search trees.
+ *{@link TreeMultiSet TreeMultiSets} are typically implemented as binary search trees.
* - * + * * *Tree-structured multiple-key set.
+ * Tree-structured set, std::set
of STL.
{@link TreeMultiSet TreeMultiSets} are containers that store elements following a specific order, and - * where multiple elements can have equivalent values.
+ *{@link TreeSet}s are containers that store unique elements following a specific order.
* - *In a {@link TreeMultiSet}, the value of an element also identifies it (the value is itself - * the key, of type T). The value of the elements in a {@link TreeMultiSet} cannot - * be modified once in the container (the elements are always const), but they can be inserted or removed - * from the
+ *In a {@link TreeSet}, the value of an element also identifies it (the value is itself the + * key, of type T), and each value must be unique. The value of the elements in a + * {@link TreeSet} cannot be modified once in the container (the elements are always const), but they + * can be inserted or removed from the
* - *Internally, the elements in a {@link TreeMultiSet TreeMultiSets} are always sorted following a strict - * weak ordering criterion indicated by its internal comparison method (of {@link IComparable.less less}).
+ *Internally, the elements in a {@link TreeSet} are always sorted following a specific strict weak + * ordering criterion indicated by its internal comparison method (of {@link less}).
* - *{@link TreeMultiSet} containers are generally slower than {@link HashMultiSet} containers - * to access individual elements by their key, but they allow the direct iteration on subsets based on - * their order.
+ *{@link TreeSet} containers are generally slower than {@link HashSet} containers to access + * individual elements by their key, but they allow the direct iteration on subsets based on their + * order.
* - *{@link TreeMultiSet TreeMultiSets} are typically implemented as binary search trees.
+ *{@link TreeSet}s are typically implemented as binary search trees.
* - * + * * *
- * An iterator of Vector.
- * A reverse-iterator of Vector.
- * Elements with equivalent keys are grouped together in the same bucket and in such a way that
* an iterator can iterate through all of them. Iterators in the container are doubly linked iterators.
- *
+ * Hash buckets storing {@link MapIterator MapIterators}.
- *
+ *
- *
+ * Hash buckets storing {@link SetIterator SetIterators}.
- *
+ *
- * There is not a single type of {@link IArrayIterator random-access iterator}: Each container may define its
* own specific iterator type able to iterate through it and access its elements.
- * {@link IContainer} is an interface designed for sequence containers. Sequence containers of STL
* (Standard Template Library) are based on the {@link IContainer}.
- * An interface for deque
- * An interface for linear containers.
- *
+ * These constraints enforce a critical property of red-black trees: the path from the root to the farthest
@@ -10717,7 +10689,7 @@ declare namespace std.base {
* the only loop, and any rotations occur after this loop, this proves that a constant number of rotations
* occur. {@link XTreeNode.sibling S} is red. In this case we reverse the colors of {@link XTreeNode.parent P} and
@@ -10958,7 +10930,7 @@ declare namespace std.base {
* {@link XTreeNode.parent P}, {@link XTreeNode.sibling S}, and {@link XTreeNode.sibling
* S}'s children are black. In this case, we simply repaint {@link XTreeNode.sibling S} red. The
@@ -10982,7 +10954,7 @@ declare namespace std.base {
* {@link XTreeNode.sibling S} and {@link XTreeNode.sibling S}'s children are
* black, but {@link XTreeNode.parent P} is red. In this case, we simply exchange the colors of {@link XTreeNode.sibling S} and
@@ -10999,7 +10971,7 @@ declare namespace std.base {
* left child is red, {@link XTreeNode.sibling S}'s right child is
* black, and N is the left child of its parent. In this case we rotate right at {@link XTreeNode.sibling S}, so that
@@ -11038,7 +11010,7 @@ declare namespace std.base {
* Thus, the paths passing through N pass through one additional
* black node. Meanwhile, if a path does not go through N, then there are two possibilities: {@link ITreeMap TreeMultiMaps} are typically implemented as binary search trees. A red-black tree storing {@link MapIterator MapIterators}. {@link ITreeSet TreeMultiSets} are typically implemented as binary search trees. A red-black Tree storing {@link SetIterator SetIterators}. An abstract container.
- * There is not a single type of {@link Iterator bidirectional iterator}: {@link IContainer Each container}
* may define its own specific iterator type able to iterate through it and access its elements.
- *
+ *
- *
+ *
- *
+ * Row size of the {@link matrix_ matrix} which contains elements. Note that the {@link ROW} affects on time complexity of accessing and inserting element.
- * Accessing element is {@link ROW} times slower than ordinary {@link Vector} and inserting element
- * in middle position is {@link ROW} times faster than ordinary {@link Vector}. When the {@link ROW} returns 8, time complexity of accessing element is O(8) and inserting
- * element in middle position is O(N/8). ({@link Vector}'s time complexity of accessement is O(1)
- * and inserting element is O(N)). Minimum {@link capacity}. Although a {@link Deque} has few elements, even no element is belonged to, the {@link Deque}
- * keeps the minimum {@link capacity} at least. An iterator of {@link Deque}.
- *
+ * A reverse-iterator of Deque.
- *
+ * All objects thrown by components of the standard library are derived from this class.
* Therefore, all standard exceptions can be caught by catching this type by reference. It is used as a base class for several logical error exceptions. No component of the standard library throws exceptions of this type. It is designed as a standard
* exception to be thrown by programs. It is a standard exception that can be thrown by programs. Some components of the standard library
* also throw exceptions of this type to signal invalid arguments. It is a standard exception that can be thrown by programs. Some components of the standard library,
* such as vector and string also throw exceptions of this type to signal errors resizing. It is used as a base class for several runtime error exceptions. It is a standard exception that can be thrown by programs. Some components of the standard library
* also throw exceptions of this type to signal range errors. No component of the standard library throws exceptions of this type. It is designed as a standard
* exception to be thrown by programs. It is a standard exception that can be thrown by programs. Some components of the standard library
* also throw exceptions of this type to signal range errors.
+ *
*
*
Container properties
@@ -9200,8 +9166,8 @@ declare namespace std {
/**
*
+ *
*
* @param
+ *
*
* @param
+ *
*
Container properties
@@ -9696,8 +9668,8 @@ declare namespace std.base {
/**
*
+ *
*
+ *
*
Container properties
@@ -9951,8 +9923,8 @@ declare namespace std.base {
/**
*
+ *
*
+ *
*
*
Container properties
@@ -10107,8 +10079,8 @@ declare namespace std.base {
*
+ *
*
* @reference http://www.cplusplus.com/reference/iterator/RandomAccessIterator
@@ -10138,8 +10110,8 @@ declare namespace std.base {
*
+ *
*
*
Container properties
@@ -10330,8 +10302,8 @@ declare namespace std.base {
/**
*
+ *
*
* @author Jeongho Nam
+ *
*
Container properties
*
@@ -11257,13 +11229,19 @@ declare namespace std.base {
/**
*
Container properties
*
@@ -11551,13 +11529,19 @@ declare namespace std.base {
/**
*
+ *
*
*
Container properties
@@ -1933,8 +1933,8 @@ var std;
*
+ *
*
+ *
*
+ *
*
Container properties
@@ -2293,34 +2293,39 @@ var std;
}
}
Object.defineProperty(Deque, "ROW", {
+ ///
+ // Row size of the {@link matrix_ matrix} which contains elements.
+ //
+ // Note that the {@link ROW} affects on time complexity of accessing and inserting element.
+ // Accessing element is {@link ROW} times slower than ordinary {@link Vector} and inserting element
+ // in middle position is {@link ROW} times faster than ordinary {@link Vector}.
+ //
+ // When the {@link ROW} returns 8, time complexity of accessing element is O(8) and inserting
+ // element in middle position is O(N/8). ({@link Vector}'s time complexity of accessement is O(1)
+ // and inserting element is O(N)).
/**
- *
+ *
*
+ *
*
An iterator of {@link MapContainer map container}.
* - * + * * * @author Jeongho NamA reverse-iterator of {@link MapContainer map container}.
* - * + * * * @author Jeongho Nam{@link HashMap} containers are faster than {@link TreeMap} containers to access individual elements by their * key, although they are generally less efficient for range iteration through a subset of their elements.
* - *
- *
+ *
+ *
*
Elements with equivalent keys are grouped together in the same bucket and in such a way that * an iterator can iterate through all of them. Iterators in the container are doubly linked iterators.
* - *
- *
+ *
+ *
*
An iterator of a Set.
* - * + * * * @author Jeongho NamA reverse-iterator of Set.
* - * + * * * @paramAn abstract set.
- * - *{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of - * individual elements based on their value.
- * - *In an {@link SetContainer}, the value of an element is at the same time its key, used to uniquely - * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be modified - * once in the container - they can be inserted and removed, though.
- * - *{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a - * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index - * table like {@link RBTree tree} or {@link HashBuckets hash-table}.
- * - * - * - *Hashed, unordered set.
+ *Hashed, unordered Multiset.
* - *{@link HashSet}s are containers that store unique elements in no particular order, and which - * allow for fast retrieval of individual elements based on their value.
+ *{@link HashMultiSet HashMultiSets} are containers that store elements in no particular order, allowing fast + * retrieval of individual elements based on their value, much like {@link HashSet} containers, + * but allowing different elements to have equivalent values.
* - *In an {@link HashSet}, the value of an element is at the same time its key, that - * identifies it uniquely. Keys are immutable, therefore, the elements in an {@link HashSet} cannot be + *
In an {@link HashMultiSet}, the value of an element is at the same time its key, used to + * identify it. Keys are immutable, therefore, the elements in an {@link HashMultiSet} cannot be * modified once in the container - they can be inserted and removed, though.
* - *Internally, the elements in the {@link HashSet} are not sorted in any particular order, but - * organized into buckets depending on their hash values to allow for fast access to individual elements - * directly by their values (with a constant average time complexity on average).
+ *Internally, the elements in the {@link HashMultiSet} are not sorted in any particular, but + * organized into buckets depending on their hash values to allow for fast access to individual + * elements directly by their values (with a constant average time complexity on average).
* - *{@link HashSet} containers are faster than {@link TreeSet} containers to access individual - * elements by their key, although they are generally less efficient for range iteration through a - * subset of their elements.
+ *Elements with equivalent values are grouped together in the same bucket and in such a way that an + * iterator can iterate through all of them. Iterators in the container are doubly linked iterators.
* - * + * * *An abstract set.
+ * + *{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of + * individual elements based on their value.
+ * + *In an {@link SetContainer}, the value of an element is at the same time its key, used to uniquely + * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be modified + * once in the container - they can be inserted and removed, though.
+ * + *{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a + * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index + * table like {@link RBTree tree} or {@link HashBuckets hash-table}.
+ * + * + * + *Hashed, unordered Multiset.
+ *Hashed, unordered set.
* - *{@link HashMultiSet HashMultiSets} are containers that store elements in no particular order, allowing fast - * retrieval of individual elements based on their value, much like {@link HashSet} containers, - * but allowing different elements to have equivalent values.
+ *{@link HashSet}s are containers that store unique elements in no particular order, and which + * allow for fast retrieval of individual elements based on their value.
* - *In an {@link HashMultiSet}, the value of an element is at the same time its key, used to - * identify it. Keys are immutable, therefore, the elements in an {@link HashMultiSet} cannot be + *
In an {@link HashSet}, the value of an element is at the same time its key, that + * identifies it uniquely. Keys are immutable, therefore, the elements in an {@link HashSet} cannot be * modified once in the container - they can be inserted and removed, though.
* - *Internally, the elements in the {@link HashMultiSet} are not sorted in any particular, but - * organized into buckets depending on their hash values to allow for fast access to individual - * elements directly by their values (with a constant average time complexity on average).
+ *Internally, the elements in the {@link HashSet} are not sorted in any particular order, but + * organized into buckets depending on their hash values to allow for fast access to individual elements + * directly by their values (with a constant average time complexity on average).
* - *Elements with equivalent values are grouped together in the same bucket and in such a way that an - * iterator can iterate through all of them. Iterators in the container are doubly linked iterators.
+ *{@link HashSet} containers are faster than {@link TreeSet} containers to access individual + * elements by their key, although they are generally less efficient for range iteration through a + * subset of their elements.
* - * + * * *
- *
+ *
+ *
*
An iterator, node of a List.
* - *
- *
+ *
+ *
*
A reverse-iterator of List.
* - *
- *
+ *
+ *
*
- *
+ *
+ *
*
- *
+ *
+ *
*
The class inherits from {@link RuntimeError}, to which it adds an {@link ErrorCode} as * member code (and defines a specialized what member).
* - * + * * * @reference http://www.cplusplus.com/reference/system_error/system_error * @author Jeongho NamThe {@link ErrorCategory categories} associated with the {@link ErrorCondition} and the * {@link ErrorCode} define the equivalences between them.
* - * + * * * @reference http://www.cplusplus.com/reference/system_error/error_condition * @author Jeongho NamObjects of this class associate such numerical codes to {@link ErrorCategory error categories}, so that they * can be interpreted when needed as more abstract (and portable) {@link ErrorCondition error conditions}.
* - * + * * * @reference http://www.cplusplus.com/reference/system_error/error_code * @author Jeongho Nam{@link TreeMap}s are typically implemented as binary search trees.
* - * + * * *{@link TreeMultiMap TreeMultiMaps} are typically implemented as binary search trees.
* - * + * * * Tree-structured set, std::set
of STL.
Tree-structured multiple-key set.
* - *{@link TreeSet}s are containers that store unique elements following a specific order.
+ *{@link TreeMultiSet TreeMultiSets} are containers that store elements following a specific order, and + * where multiple elements can have equivalent values.
* - *In a {@link TreeSet}, the value of an element also identifies it (the value is itself the - * key, of type T), and each value must be unique. The value of the elements in a - * {@link TreeSet} cannot be modified once in the container (the elements are always const), but they - * can be inserted or removed from the
+ *In a {@link TreeMultiSet}, the value of an element also identifies it (the value is itself + * the key, of type T). The value of the elements in a {@link TreeMultiSet} cannot + * be modified once in the container (the elements are always const), but they can be inserted or removed + * from the
* - *Internally, the elements in a {@link TreeSet} are always sorted following a specific strict weak - * ordering criterion indicated by its internal comparison method (of {@link less}).
+ *Internally, the elements in a {@link TreeMultiSet TreeMultiSets} are always sorted following a strict + * weak ordering criterion indicated by its internal comparison method (of {@link IComparable.less less}).
* - *{@link TreeSet} containers are generally slower than {@link HashSet} containers to access - * individual elements by their key, but they allow the direct iteration on subsets based on their - * order.
+ *{@link TreeMultiSet} containers are generally slower than {@link HashMultiSet} containers + * to access individual elements by their key, but they allow the direct iteration on subsets based on + * their order.
* - *{@link TreeSet}s are typically implemented as binary search trees.
+ *{@link TreeMultiSet TreeMultiSets} are typically implemented as binary search trees.
* - * + * * *Tree-structured multiple-key set.
+ * Tree-structured set, std::set
of STL.
{@link TreeMultiSet TreeMultiSets} are containers that store elements following a specific order, and - * where multiple elements can have equivalent values.
+ *{@link TreeSet}s are containers that store unique elements following a specific order.
* - *In a {@link TreeMultiSet}, the value of an element also identifies it (the value is itself - * the key, of type T). The value of the elements in a {@link TreeMultiSet} cannot - * be modified once in the container (the elements are always const), but they can be inserted or removed - * from the
+ *In a {@link TreeSet}, the value of an element also identifies it (the value is itself the + * key, of type T), and each value must be unique. The value of the elements in a + * {@link TreeSet} cannot be modified once in the container (the elements are always const), but they + * can be inserted or removed from the
* - *Internally, the elements in a {@link TreeMultiSet TreeMultiSets} are always sorted following a strict - * weak ordering criterion indicated by its internal comparison method (of {@link IComparable.less less}).
+ *Internally, the elements in a {@link TreeSet} are always sorted following a specific strict weak + * ordering criterion indicated by its internal comparison method (of {@link less}).
* - *{@link TreeMultiSet} containers are generally slower than {@link HashMultiSet} containers - * to access individual elements by their key, but they allow the direct iteration on subsets based on - * their order.
+ *{@link TreeSet} containers are generally slower than {@link HashSet} containers to access + * individual elements by their key, but they allow the direct iteration on subsets based on their + * order.
* - *{@link TreeMultiSet TreeMultiSets} are typically implemented as binary search trees.
+ *{@link TreeSet}s are typically implemented as binary search trees.
* - * + * * *
- * An iterator of Vector.
- * A reverse-iterator of Vector.
- * Hash buckets storing {@link MapIterator MapIterators}.
- *
+ * Hash buckets storing {@link SetIterator SetIterators}.
- *
+ * These constraints enforce a critical property of red-black trees: the path from the root to the farthest
@@ -9867,7 +9883,7 @@ var std;
* the only loop, and any rotations occur after this loop, this proves that a constant number of rotations
* occur. {@link XTreeNode.sibling S} is red. In this case we reverse the colors of {@link XTreeNode.parent P} and
@@ -10168,7 +10184,7 @@ var std;
* {@link XTreeNode.parent P}, {@link XTreeNode.sibling S}, and {@link XTreeNode.sibling
* S}'s children are black. In this case, we simply repaint {@link XTreeNode.sibling S} red. The
@@ -10202,7 +10218,7 @@ var std;
* {@link XTreeNode.sibling S} and {@link XTreeNode.sibling S}'s children are
* black, but {@link XTreeNode.parent P} is red. In this case, we simply exchange the colors of {@link XTreeNode.sibling S} and
@@ -10230,7 +10246,7 @@ var std;
* left child is red, {@link XTreeNode.sibling S}'s right child is
* black, and N is the left child of its parent. In this case we rotate right at {@link XTreeNode.sibling S}, so that
@@ -10288,7 +10304,7 @@ var std;
* Thus, the paths passing through N pass through one additional
* black node. Meanwhile, if a path does not go through N, then there are two possibilities: A red-black tree storing {@link MapIterator MapIterators}. A red-black Tree storing {@link SetIterator SetIterators}. Red-black Tree. A red-black tree is a kind of self-balancing
- * binary search tree. Each node of the binary tree has an extra bit, and that bit is often interpreted as the
- * color (red or black) of the node. These color bits
- * are used to ensure the tree remains approximately balanced during insertions and deletions. Balance is preserved by painting each node of the tree with one of two colors (typically called
- * 'red' and 'black') in a way that satisfies certain
- * properties, which collectively constrain how unbalanced the tree can become in the worst case. When the tree
- * is modified, the new tree is subsequently rearranged and repainted to restore the coloring properties. The
- * properties are designed in such a way that this rearranging and recoloring can be performed efficiently. The balancing of the tree is not perfect but it is good enough to allow it to guarantee searching in
- * O(log n) time, where n is the total number of elements in the tree. The insertion and deletion operations,
- * along with the tree rearrangement and recoloring, are also performed in O(log n) time. Tracking the color of each node requires only 1 bit of information per node because there are only two
- * colors. The tree does not contain any other data specific to its being a
- * red-black tree so its memory footprint is almost
- * identical to a classic (uncolored) binary search tree. In many cases the additional bit of information can
- * be stored at no additional memory cost. Static class holding enumeration codes of color of Red-black tree. In addition to the requirements imposed on a binary search tree the following must be satisfied by a
- * red-black tree: Color codes imposed to nodes of RB-Tree are following those rules: Code of color black. Code of color red. An abstract container. These constraints enforce a critical property of red-black trees: the path from the root to the farthest
- * leaf is no more than twice as long as the path from the root to the nearest leaf. The result is that the tree
- * is roughly height-balanced. Since operations such as inserting, deleting, and finding values require
- * worst-case time proportional to the height of the tree, this theoretical upper bound on the height allows
- * red-black trees to be efficient in the worst case, unlike ordinary binary search trees. To see why this is guaranteed, it suffices to consider the effect of properties 4 and 5 together. For a
- * red-black tree T, let B be the number of black nodes in property 5. Let the
- * shortest possible path from the root of T to any leaf consist of B black nodes.
- * Longer possible paths may be constructed by inserting red nodes. However, property 4
- * makes it impossible to insert more than one consecutive red node. Therefore,
- * ignoring any black NIL leaves, the longest possible path consists of 2*B nodes,
- * alternating black and red (this is the worst case).
- * Counting the black NIL leaves, the longest possible path consists of 2*B-1
- * nodes. The shortest possible path has all black nodes, and the longest possible
- * path alternates between red and black nodes. Since all
- * maximal paths have the same number of black nodes, by property 5, this shows
- * that no path is more than twice as long as any other path. An abstract error instance. {@link ErrorInstance} is an abstract class of {@link ErrorCode} and {@link ErrorCondition}
+ * holding an error instance's identifier {@link value}, associated with a {@link category}. The operating system and other low-level applications and libraries generate numerical error codes to
+ * represent possible results. These numerical values may carry essential information for a specific platform,
+ * but be non-portable from one platform to another. Objects of this class associate such numerical codes to {@link ErrorCategory error categories},
+ * so that they can be interpreted when needed as more abstract (and portable)
+ * {@link ErrorCondition error conditions}. Assign error instance. Assigns the {@link ErrorCode} object a value of val associated with the {@link ErrorCategory}. Clear error instance. Clears the value in the {@link ErrorCode} object so that it is set to a value of 0 of the
+ * {@link ErrorCategory.systemCategory ErrorCategory.systemCategory()} (indicating no error). Insert an element with a new node. Get category. Insertion begins by adding the node as any binary search tree insertion does and by coloring it
- * red. Whereas in the binary search tree, we always add a leaf, in the red-black
- * tree, leaves contain no information, so instead we add a red interior node, with
- * two black leaves, in place of an existing
- * black leaf. Returns a reference to the {@link ErrorCategory} associated with the {@link ErrorCode} object. What happens next depends on the color of other nearby nodes. The term uncle node will be used to
- * refer to the sibling of a node's parent, as in human family trees. Note that: There are several cases of red-black tree insertion to handle: Note that inserting is actually in-place, since all the calls above use tail recursion. In the algorithm above, all cases are chained in order, except in insert case 3 where it can recurse
- * to case 1 back to the grandparent node: this is the only case where an iterative implementation will
- * effectively loop. Because the problem of repair is escalated to the next higher level but one, it takes
- * maximally h⁄2 iterations to repair the tree (where h is the height of the tree). Because the probability
- * for escalation decreases exponentially with each iteration the average insertion cost is constant. N is the root node, i.e., first node of red-black tree. The current node N is at the {@link root_ root} of the tree. Error value. In this case, it is repainted black to satisfy property 2 (the root is
- * black). Since this adds one black node to
- * every path at once, property 5 (all paths from any given node to its leaf nodes contain the same number
- * of black nodes) is not violated. Returns the error value associated with the {@link ErrorCode} object. N's parent ({@link XTreeNode.parent P}) is black. Get message. The current node's parent {@link XTreeNode.parent P} is black,
- * so property 4 (both children of every red node are
- * black) is not invalidated. Returns the message associated with the error instance. In this case, the tree is still valid. Property 5 (all paths from any given node to its leaf nodes
- * contain the same number of black nodes) is not threatened, because the
- * current node N has two black leaf children, but because
- * N is red, the paths through each of its children have the same
- * number of black nodes as the path through the leaf it replaced, which was
- * black, and so this property remains satisfied. Error messages are defined by the {@link category} the error instance belongs to. This function returns the same as if the following member was called: N's parent ({@link XTreeNode.parent P}) and uncle
- * ({@link XTreeNode.uncle U}) are red. If both the parent {@link XTreeNode.parent P} and the uncle {@link XTreeNode.uncle U}
- * are red, then both of them can be repainted black
- * and the grandparent {@link XTreeNode.grand_parent G} becomes red (to
- * maintain property 5 (all paths from any given node to its leaf nodes contain the same number of
- * black nodes)). Default error condition. Now, the current red node N has a
- * black parent. Since any path through the parent or uncle must pass through
- * the grandparent, the number of black nodes on these paths has not changed.
+ * Returns the default {@link ErrorCondition}object associated with the {@link ErrorCode} object. However, the grandparent {@link XTreeNode.grand_parent G} may now violate properties 2 (The
- * root is black) or 4 (Both children of every red
- * node are black) (property 4 possibly being violated since
- * {@link XTreeNode.grand_parent G} may have a red parent). This function returns the same as if the following member was called: To fix this, the entire procedure is recursively performed on {@link XTreeNode.grand_parent G}
- * from case 1. Note that this is a tail-recursive call, so it could be rewritten as a loop; since this is
- * the only loop, and any rotations occur after this loop, this proves that a constant number of rotations
- * occur. {@link ErrorCategory.default_error_condition ErrorCategory.default_error_condition()}
+ * is a virtual member function, that can operate differently for each category. N is added to right of left child of grandparent, or N is added to left
- * of right child of grandparent ({@link XTreeNode.parent P} is red and
- * {@link XTreeNode.uncle U} is black). Convert to bool. The parent {@link XTreeNode.parent P} is red but the uncle
- * {@link XTreeNode.uncle U} is black; also, the current node
- * N is the right child of {@link XTreeNode.parent P}, and
- * {@link XTreeNode.parent P} in turn is the left child of its parent
- * {@link XTreeNode.grand_parent G}. Returns whether the error instance has a numerical {@link value} other than 0. In this case, a left rotation on {@link XTreeNode.parent P} that switches the roles of the
- * current node N and its parent {@link XTreeNode.parent P} can be performed; then,
- * the former parent node {@link XTreeNode.parent P} is dealt with using case 5
- * (relabeling N and {@link XTreeNode.parent P}) because property 4 (both children of
- * every red node are black) is still violated. If it is zero (which is generally used to represent no error), the function returns false, otherwise it returns true. The rotation causes some paths (those in the sub-tree labelled "1") to pass through the node
- * N where they did not before. It also causes some paths (those in the sub-tree labelled "3")
- * not to pass through the node {@link XTreeNode.parent P} where they did before. However, both of
- * these nodes are red, so property 5 (all paths from any given node to its leaf
- * nodes contain the same number of black nodes) is not violated by the
- * rotation. Hask buckets. Reconstruction of hash table. After this case has been completed, property 4 (both children of every red
- * node are black) is still violated, but now we can resolve this by
- * continuing to case 5. All the elements in the hash buckets are rearranged according to their hash value into the new set of
+ * buckets. This may alter the order of iteration of elements within the container. Notice that {@link rehash rehashes} are automatically performed whenever its number of elements is going
+ * to greater than its own {@link capacity}. N is added to left of left child of grandparent, or N is added to right
- * of right child of grandparent ({@link XTreeNode.parent P} is red and
- * {@link XTreeNode.uncle U} is black). The parent {@link XTreeNode.parent P} is red but the uncle
- * {@link XTreeNode.uncle U} is black, the current node N
- * is the left child of {@link XTreeNode.parent P}, and {@link XTreeNode.parent P} is the left
- * child of its parent {@link XTreeNode.grand_parent G}. In this case, a right rotation on {@link XTreeNode.grand_parent G} is performed; the result is a
- * tree where the former parent {@link XTreeNode.parent P} is now the parent of both the current node
- * N and the former grandparent {@link XTreeNode.grand_parent G}. {@link XTreeNode.grand_parent G} is known to be black, since its
- * former child {@link XTreeNode.parent P} could not have been red otherwise
- * (without violating property 4). Then, the colors of {@link XTreeNode.parent P} and
- * {@link XTreeNode.grand_parent G} are switched, and the resulting tree satisfies property 4 (both
- * children of every red node are black). Property 5
- * (all paths from any given node to its leaf nodes contain the same number of
- * black nodes) also remains satisfied, since all paths that went through any
- * of these three nodes went through {@link XTreeNode.grand_parent G} before, and now they all go
- * through {@link XTreeNode.parent P}. In each case, this is the only
- * black node of the three. Erase an element with its node. In a regular binary search tree when deleting a node with two non-leaf children, we find either the
- * maximum element in its left subtree (which is the in-order predecessor) or the minimum element in its
- * right subtree (which is the in-order successor) and move its value into the node being deleted (as shown
- * here). We then delete the node we copied the value from, which must have fewer than two non-leaf children.
- * (Non-leaf children, rather than all children, are specified here because unlike normal binary search
- * trees, red-black trees can have leaf nodes anywhere, so that all nodes are either internal nodes with
- * two children or leaf nodes with, by definition, zero children. In effect, internal nodes having two leaf
- * children in a red-black tree are like the leaf nodes in a regular binary search tree.) Because merely
- * copying a value does not violate any red-black properties, this reduces to the problem of deleting a node
- * with at most one non-leaf child. Once we have solved that problem, the solution applies equally to the
- * case where the node we originally want to delete has at most one non-leaf child as to the case just
- * considered where it has two non-leaf children. Therefore, for the remainder of this discussion we address the deletion of a node with at most one
- * non-leaf child. We use the label M to denote the node to be deleted; C will denote a
- * selected child of M, which we will also call "its child". If M does have a non-leaf child,
- * call that its child, C; otherwise, choose either leaf as its child, C. If M is a red node, we simply replace it with its child C,
- * which must be black by property 4. (This can only occur when M has
- * two leaf children, because if the red node M had a
- * black non-leaf child on one side but just a leaf child on the other side,
- * then the count of black nodes on both sides would be different, thus the
- * tree would violate property 5.) All paths through the deleted node will simply pass through one fewer
- * red node, and both the deleted node's parent and child must be
- * black, so property 3 (all leaves are black)
- * and property 4 (both children of every red node are
- * black) still hold. Another simple case is when M is black and C is
- * red. Simply removing a black node could break
- * Properties 4 (“Both children of every red node are
- * black”) and 5 (“All paths from any given node to its leaf nodes contain the
- * same number of black nodes”), but if we repaint C
- * black, both of these properties are preserved. The complex case is when both M and C are black. (This
- * can only occur when deleting a black node which has two leaf children,
- * because if the black node M had a black
- * non-leaf child on one side but just a leaf child on the other side, then the count of
- * black nodes on both sides would be different, thus the tree would have been
- * an invalid red-black tree by violation of property 5.) We begin by replacing M with its child
- * C. We will relabel this child C (in its new position) N, and its sibling (its
- * new parent's other child) {@link XTreeNode.sibling S}. ({@link XTreeNode.sibling S} was
- * previously the sibling of M.) In the diagrams below, we will also use {@link XTreeNode.parent P} for N's new
- * parent (M's old parent), SL for {@link XTreeNode.sibling S}'s left child, and
- * SR for {@link XTreeNode.sibling S}'s right child ({@link XTreeNode.sibling S} cannot
- * be a leaf because if M and C were black, then
- * {@link XTreeNode.parent P}'s one subtree which included M counted two
- * black-height and thus {@link XTreeNode.parent P}'s other subtree
- * which includes {@link XTreeNode.sibling S} must also count two
- * black-height, which cannot be the case if {@link XTreeNode.sibling S}
- * is a leaf node). If both N and its original parent are black, then
- * deleting this original parent causes paths which proceed through N to have one fewer
- * black node than paths that do not. As this violates property 5 (all paths
- * from any given node to its leaf nodes contain the same number of black
- * nodes), the tree must be rebalanced. There are several cases to consider: Again, the function calls all use tail recursion, so the algorithm is in-place. In the algorithm above, all cases are chained in order, except in delete case 3 where it can recurse
- * to case 1 back to the parent node: this is the only case where an iterative implementation will
- * effectively loop. No more than h loops back to case 1 will occur (where h is the height of the tree).
- * And because the probability for escalation decreases exponentially with each iteration the average
- * removal cost is constant. Additionally, no tail recursion ever occurs on a child node, so the tail recursion loop can only
- * move from a child back to its successive ancestors. If a rotation occurs in case 2 (which is the only
- * possibility of rotation within the loop of cases 1–3), then the parent of the node N
- * becomes red after the rotation and we will exit the loop. Therefore, at most one
- * rotation will occur within this loop. Since no more than two additional rotations will occur after
- * exiting the loop, at most three rotations occur in total. N is the new root. In this case, we are done. We removed one black node from every path,
- * and the new root is black, so the properties are preserved. In cases 2, 5, and 6, we assume N is the left child of its parent
- * {@link XTreeNode.parent P}. If it is the right child, left and right should be reversed throughout
- * these three cases. Again, the code examples take both cases into account. {@link XTreeNode.sibling S} is red. In this case we reverse the colors of {@link XTreeNode.parent P} and
- * {@link XTreeNode.sibling S}, and then rotate left at {@link XTreeNode.parent P}, turning
- * {@link XTreeNode.sibling S} into N's grandparent. Note that {@link XTreeNode.parent P} has to be black as it had a
- * red child. The resulting subtree has a path short one
- * black node so we are not done. Now N has a
- * black sibling and a red parent, so we can proceed
- * to step 4, 5, or 6. (Its new sibling is black because it was once the child
- * of the red {@link XTreeNode.sibling S}.) In later cases, we will re-label
- * N's new sibling as {@link XTreeNode.sibling S}. {@link XTreeNode.parent P}, {@link XTreeNode.sibling S}, and {@link XTreeNode.sibling
- * S}'s children are black. In this case, we simply repaint {@link XTreeNode.sibling S} red. The
- * result is that all paths passing through {@link XTreeNode.sibling S}, which are precisely those
- * paths not passing through N, have one less black node.
- * Because deleting N's original parent made all paths passing through N have
- * one less black node, this evens things up. However, all paths through {@link XTreeNode.parent P} now have one fewer
- * black node than paths that do not pass through
- * {@link XTreeNode.parent P}, so property 5 (all paths from any given node to its leaf nodes contain
- * the same number of black nodes) is still violated. To correct this, we perform the rebalancing procedure on {@link XTreeNode.parent P}, starting
- * at case 1. {@link XTreeNode.sibling S} and {@link XTreeNode.sibling S}'s children are
- * black, but {@link XTreeNode.parent P} is red. In this case, we simply exchange the colors of {@link XTreeNode.sibling S} and
- * {@link XTreeNode.parent P}. This does not affect the number of black
- * nodes on paths going through {@link XTreeNode.sibling S}, but it does add one to the number of
- * black nodes on paths going through N, making up for the
- * deleted black node on those paths. {@link XTreeNode.sibling S} is black, {@link XTreeNode.sibling S}'s
- * left child is red, {@link XTreeNode.sibling S}'s right child is
- * black, and N is the left child of its parent. In this case we rotate right at {@link XTreeNode.sibling S}, so that
- * {@link XTreeNode.sibling S}'s left child becomes {@link XTreeNode.sibling S}'s parent and
- * N's new sibling. We then exchange the colors of {@link XTreeNode.sibling S} and its
- * new parent. All paths still have the same number of black nodes, but now
- * N has a black sibling whose right child is
- * red, so we fall into case 6. Neither N nor its parent are affected
- * by this transformation. (Again, for case 6, we relabel N's new sibling as
- * {@link XTreeNode.sibling S}.) {@link XTreeNode.sibling S} is black,
- * {@link XTreeNode.sibling S}'s right child is red, and N is
- * the left child of its parent {@link XTreeNode.parent P}. In this case we rotate left at {@link XTreeNode.parent P}, so that
- * {@link XTreeNode.sibling S} becomes the parent of {@link XTreeNode.parent P} and
- * {@link XTreeNode.sibling S}'s right child. We then exchange the colors of
- * {@link XTreeNode.parent P} and {@link XTreeNode.sibling S}, and make
- * {@link XTreeNode.sibling S}'s right child black. The subtree still has the same color at its root, so Properties 4 (Both children of every
- * red node are black) and 5 (All paths from any
- * given node to its leaf nodes contain the same number of black nodes) are
- * not violated. However, N now has one additional black
- * ancestor: either {@link XTreeNode.parent P} has become black, or it
- * was black and {@link XTreeNode.sibling S} was added as a
- * black grandparent. Thus, the paths passing through N pass through one additional
- * black node. Meanwhile, if a path does not go through N, then there are two possibilities: Either way, the number of black nodes on these paths does not change.
- * Thus, we have restored Properties 4 (Both children of every red node are
- * black) and 5 (All paths from any given node to its leaf nodes contain the
- * same number of black nodes). The white node in the diagram can be either
- * red or black, but must refer to the same color
- * both before and after the transformation. A red-black Tree storing {@link SetIterator SetIterators}. Return iterator to lower bound. Returns an iterator pointing to the first element in the container which is not considered to
- * go before val (i.e., either it is equivalent or goes after). The function uses its internal comparison object (key_comp) to determine this, returning an
- * iterator to the first element for which key_comp(element,val) would return false. If the {@link ITreeSet} class is instantiated with the default comparison type ({@link less}),
- * the function returns an iterator to the first element that is not less than val. A similar member function, {@link upper_bound}, has the same behavior as {@link lower_bound}, except
- * in the case that the {@link ITreeSet} contains elements equivalent to val: In this case
- * {@link lower_bound} returns an iterator pointing to the first of such elements, whereas
- * {@link upper_bound} returns an iterator pointing to the element following the last. Return iterator to upper bound. Returns an iterator pointing to the first element in the container which is considered to go after
- * val. The function uses its internal comparison object (key_comp) to determine this, returning an
- * iterator to the first element for which key_comp(val,element) would return true. If the {@code ITreeSet} class is instantiated with the default comparison type (less), the
- * function returns an iterator to the first element that is greater than val. A similar member function, {@link lower_bound}, has the same behavior as {@link upper_bound}, except
- * in the case that the {@ITreeSet} contains elements equivalent to val: In this case
- * {@link lower_bound} returns an iterator pointing to the first of such elements, whereas
- * {@link upper_bound} returns an iterator pointing to the element following the last. Get range of equal elements. Returns the bounds of a range that includes all the elements in the container that are equivalent
- * to val. If no matches are found, the range returned has a length of zero, with both iterators pointing to
- * the first element that is considered to go after val according to the container's
- * internal comparison object (key_comp). Two elements of a multiset are considered equivalent if the container's comparison object returns
- * false reflexively (i.e., no matter the order in which the elements are passed as arguments). Return comparison function. Returns a copy of the comparison function used by the container. By default, this is a {@link less} object, which returns the same as operator<. This object determines the order of the elements in the container: it is a function pointer or a function
- * object that takes two arguments of the same type as the container elements, and returns Two elements of a {@link ITreeSet} are considered equivalent if {@link key_comp} returns In {@link ITreeSet} containers, the keys to sort the elements are the values (T) themselves,
- * therefore {@link key_comp} and its sibling member function {@link value_comp} are equivalent. Return comparison function. Returns a copy of the comparison function used by the container. By default, this is a {@link less} object, which returns the same as operator<. This object determines the order of the elements in the container: it is a function pointer or a function
- * object that takes two arguments of the same type as the container elements, and returns Two elements of a {@link ITreeSet} are considered equivalent if {@link key_comp} returns In {@link ITreeSet} containers, the keys to sort the elements are the values (T) themselves,
- * therefore {@link key_comp} and its sibling member function {@link value_comp} are equivalent. Hash buckets storing {@link MapIterator MapIterators}.
+ * Static class holding enumeration codes of color of Red-black tree. Hash buckets storing {@link SetIterator SetIterators}.
+ * Bi-directional iterator. {@link Iterator Bidirectional iterators} are iterators that can be used to access the sequence of elements
+ * in a range in both directions (towards the end and towards the beginning). All {@link IArrayIterator random-access iterators} are also valid {@link Iterrator bidirectional iterators}.
+ * There is not a single type of {@link Iterator bidirectional iterator}: {@link IContainer Each container}
+ * may define its own specific iterator type able to iterate through it and access its elements.
+ * Whether an iterator is equal with the iterator. Color codes imposed to nodes of RB-Tree are following those rules: Compare two iterators and returns whether they are equal or not. Iterator's equal_to() only compare souce container and index number. Although elements in a pair, key and value are equal_to, if the source map or
+ * index number is different, then the {@link equal_to equal_to()} will return false. If you want to
+ * compare the elements of a pair, compare them directly by yourself. Code of color black. Get value of the iterator is pointing. Code of color red. This class reverses the direction in which a bidirectional or random-access iterator iterates through a range.
+ * A copy of the original iterator (the {@link Iterator base iterator}) is kept internally and used to reflect
+ * the operations performed on the {@link ReverseIterator}: whenever the {@link ReverseIterator} is incremented, its
+ * {@link Iterator base iterator} is decreased, and vice versa. A copy of the {@link Iterator base iterator} with the
+ * current state can be obtained at any time by calling member {@link base}. Notice however that when an iterator is reversed, the reversed version does not point to the same element in
+ * the range, but to the one preceding it. This is so, in order to arrange for the past-the-end element of a
+ * range: An iterator pointing to a past-the-end element in a range, when reversed, is pointing to the last element
+ * (not past it) of the range (this would be the first element of the reversed range). And if an iterator to the
+ * first element in a range is reversed, the reversed iterator points to the element before the first element (this
+ * would be the past-the-end element of the reversed range).
+ * Return distance between {@link Iterator iterators}. Calculates the number of elements between first and last. If it is a {@link IArrayIterator random-access iterator}, the function uses operator- to calculate this.
+ * Otherwise, the function uses the increase operator {@link Iterator.next next()} repeatedly. Advance iterator. Advances the iterator it by n elements positions. Get iterator to previous element. Returns an iterator pointing to the element that it would be pointing to if advanced -n positions. Get iterator to next element. Returns an iterator pointing to the element that it would be pointing to if advanced n positions. An abstract container. An abstract map. {@link MapContainer MapContainers} are associative containers that store elements formed by a combination
+ * of a key value (Key) and a mapped value (T), and which allows for fast retrieval
+ * of individual elements based on their keys. In a {@link MapContainer}, the key values are generally used to identify the elements, while the
+ * mapped values store the content associated to this key. The types of key and
+ * mapped value may differ, and are grouped together in member type value_type, which is a
+ * {@link Pair} type combining both: {@link MapContainer} stores elements, keeps sequence and enables indexing by inserting elements into a
+ * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index
+ * table like {@link RBTree tree} or {@link HashBuckets hash-table}. An abstract error instance. {@link ErrorInstance} is an abstract class of {@link ErrorCode} and {@link ErrorCondition}
- * holding an error instance's identifier {@link value}, associated with a {@link category}. The operating system and other low-level applications and libraries generate numerical error codes to
- * represent possible results. These numerical values may carry essential information for a specific platform,
- * but be non-portable from one platform to another. Objects of this class associate such numerical codes to {@link ErrorCategory error categories},
- * so that they can be interpreted when needed as more abstract (and portable)
- * {@link ErrorCondition error conditions}. Assign error instance. Assigns the {@link ErrorCode} object a value of val associated with the {@link ErrorCategory}. Clear error instance. Clears the value in the {@link ErrorCode} object so that it is set to a value of 0 of the
- * {@link ErrorCategory.systemCategory ErrorCategory.systemCategory()} (indicating no error). Get category. Returns a reference to the {@link ErrorCategory} associated with the {@link ErrorCode} object. Error value. Return iterator to beginning. Returns the error value associated with the {@link ErrorCode} object. Returns an iterator referring the first element in the If the container is {@link empty}, the returned iterator is same with {@link end end()}. Get message. Return iterator to end. Returns an iterator referring to the past-the-end element in the Returns the message associated with the error instance. The past-the-end element is the theoretical element that would follow the last element in the
+ * It does not point to any element, and thus shall not be dereferenced. Error messages are defined by the {@link category} the error instance belongs to. Because the ranges used by functions of the container do not include the element reference by their
+ * closing iterator, this function is often used in combination with {@link MapContainer}.{@link begin} to
+ * specify a range including all the elements in the This function returns the same as if the following member was called: Returned iterator from {@link MapContainer}.{@link end} does not refer any element. Trying to accessing
+ * element by the iterator will cause throwing exception ({@link OutOfRange}). If the container is {@link empty}, this function returns the same as {@link begin}. Default error condition. Return {@link MapReverseIterator reverse iterator} to reverse beginning. Returns the default {@link ErrorCondition}object associated with the {@link ErrorCode} object. Returns a {@link MapReverseIterator reverse iterator} pointing to the last element in the container
+ * (i.e., its reverse beginning). This function returns the same as if the following member was called:
+ *
*
*
Container properties
@@ -9152,8 +9168,8 @@ var std;
/**
*
+ *
*
* @param
+ *
*
* @param
+ *
*
+ *
*
???.insert(...)
- // list.insert(list.end(), 5, 1)
- var fn = std.bind(std.List.prototype.insert);
- fn(list, list.end(), 5, 1);
- debug_list();
- var fn2 = std.bind(std.List.prototype.clear);
- fn2(list);
- debug_list();
- //
???.insert(_1, _2, 5, _3)
- // list.insert(list.end(), 5, 2)
- var fn3 = std.bind(list.insert, std.placeholders._1, std.placeholders._2, 5, std.placeholders._3);
- fn3(list, list.end(), 2);
- debug_list();
- function debug_list() {
- console.log("#" + list.size());
- for (var it = list.begin(); !it.equal_to(list.end()); it = it.next())
- console.log(it.value);
- console.log("----------------------------------------------------------");
- }
- }
- example.test_bind = test_bind;
- })(example = std.example || (std.example = {}));
-})(std || (std = {}));
-///
Properties
- *
*
*
- * null
) are black.
+ *
+ */
+ Color[Color["BLACK"] = 0] = "BLACK";
+ /**
+ * Container properties
+ *
+ *
*
* @param
- *
- *
- * Notes
- *
- *
- *
- *
- *
- *
- * Note
- * category().message(value())
category().default_error_condition(value())
true
if the error's numerical value is not zero.
+ * false
otherwise.
+ */
+ ErrorInstance.prototype.to_bool = function () {
+ return this.value_ != 0;
+ };
+ return ErrorInstance;
+ }());
+ base.ErrorInstance = ErrorInstance;
+ })(base = std.base || (std.base = {}));
+})(std || (std = {}));
+///
Notes
- *
- *
- *
- *
- *
- *
- * Note
- *
- *
- *
- * true
if
- * the first argument is considered to go before the second in the strict weak ordering it
- * defines, and false
otherwise. false
- * reflexively (i.e., no matter the order in which the elements are passed as arguments). true
if
- * the first argument is considered to go before the second in the strict weak ordering it
- * defines, and false
otherwise. false
- * reflexively (i.e., no matter the order in which the elements are passed as arguments).
+ *
+ *
+ *
- *
+ * null
) are black. Note
+ *
- *
- */
- Color[Color["BLACK"] = 0] = "BLACK";
- /**
- *
+ *
typedef pair
Container properties
*
- *
*
- * @param Note
+ * Note
+ * category().message(value())
category().default_error_condition(value())
{@link rbegin} points to the element preceding the one that would be pointed to by member {@link end}. + *
* - *{@link ErrorCategory.default_error_condition ErrorCategory.default_error_condition()} - * is a virtual member function, that can operate differently for each category.
+ * @return A {@link MapReverseIterator reverse iterator} to the reverse beginning of the sequence * - * @return An {@link ErrorCondition}object that corresponds to the {@link ErrorCode} object. */ - ErrorInstance.prototype.default_error_condition = function () { - if (this.category_ == null || this.value_ == 0) - return null; - else - return this.category_.default_error_condition(this.value_); + MapContainer.prototype.rbegin = function () { + return new std.MapReverseIterator(this.end()); }; - /* --------------------------------------------------------- - OPERATORS - --------------------------------------------------------- */ /** - *Convert to bool.
+ *Return {@link MapReverseIterator reverse iterator} to reverse end.
* - *Returns whether the error instance has a numerical {@link value} other than 0.
+ *Returns a {@link MapReverseIterator reverse iterator} pointing to the theoretical element right before + * the first element in the {@link MapContainer map container} (which is considered its reverse end). + *
* - *If it is zero (which is generally used to represent no error), the function returns false, otherwise it returns true.
+ *The range between {@link MapContainer}.{@link rbegin} and {@link MapContainer}.{@link rend} contains + * all the elements of the container (in reverse order).
* - * @returntrue
if the error's numerical value is not zero.
- * false
otherwise.
+ * @return A {@link MapReverseIterator reverse iterator} to the reverse end of the sequence
*/
- ErrorInstance.prototype.to_bool = function () {
- return this.value_ != 0;
- };
- return ErrorInstance;
- }());
- base.ErrorInstance = ErrorInstance;
- })(base = std.base || (std.base = {}));
-})(std || (std = {}));
-/// Hask buckets.
- * - * @author Jeongho NamReconstruction of hash table.
+ *Whether have the item or not.
* - *All the elements in the hash buckets are rearranged according to their hash value into the new set of - * buckets. This may alter the order of iteration of elements within the container.
+ *Indicates whether a map has an item having the specified identifier.
* - *Notice that {@link rehash rehashes} are automatically performed whenever its number of elements is going - * to greater than its own {@link capacity}.
+ * @param key Key value of the element whose mapped value is accessed. * - * @param size Number of bucket size to rehash. + * @return Whether the map has an item having the specified identifier. */ - HashBuckets.prototype.rehash = function (size) { - if (size < Hash.MIN_SIZE) - size = Hash.MIN_SIZE; - var prev_matrix = this.buckets_; - this.buckets_ = new std.Vector(); - for (var i = 0; i < size; i++) - this.buckets_.push_back(new std.Vector()); - for (var i = 0; i < prev_matrix.size(); i++) - for (var j = 0; j < prev_matrix.at(i).size(); j++) { - var val = prev_matrix.at(i).at(j); - var bucket = this.buckets_.at(this.hash_index(val)); - bucket.push_back(val); - this.item_size_++; - } - }; - HashBuckets.prototype.clear = function () { - this.buckets_ = new std.Vector(); - this.item_size_ = 0; - for (var i = 0; i < Hash.MIN_SIZE; i++) - this.buckets_.push_back(new std.Vector()); + MapContainer.prototype.has = function (key) { + return !this.find(key).equal_to(this.end()); }; - /* --------------------------------------------------------- - ACCESSORS - --------------------------------------------------------- */ - HashBuckets.prototype.size = function () { - return this.buckets_.size(); + /** + * Return the number of elements in the map. + */ + MapContainer.prototype.size = function () { + return this.data_.size(); }; - HashBuckets.prototype.item_size = function () { - return this.item_size_; + MapContainer.prototype.push = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + // TO BE ABSTRACT + for (var i = 0; i < args.length; i++) + if (args[i] instanceof std.Pair) + this.insert_by_pair(args[i]); + else if (args[i] instanceof Array) + this.insert_by_tuple(args[i]); + return this.size(); }; - HashBuckets.prototype.capacity = function () { - return this.buckets_.size() * Hash.MAX_RATIO; + MapContainer.prototype.insert = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + if (args.length == 1 && args[0] instanceof std.Pair) { + return this.insert_by_pair(args[0]); + } + else if (args.length == 1 && args[0] instanceof Array) { + return this.insert_by_tuple(args[0]); + } + else if (args.length == 2 && args[0] instanceof std.Iterator && args[1] instanceof std.Iterator) { + return this.insert_by_range(args[0], args[1]); + } + else { + var ret = void 0; + var is_reverse_iterator = false; + // REVERSE_ITERATOR TO ITERATOR + if (args[0] instanceof std.MapReverseIterator) { + is_reverse_iterator = true; + args[0] = args[0].base().prev(); + } + // INSERT AN ELEMENT + if (args[1] instanceof std.Pair) + ret = this.insert_by_hint(args[0], args[1]); + else + ret = this.insert_by_hint_with_tuple(args[0], args[1]); + // RETURN BRANCHES + if (is_reverse_iterator == true) + return new std.MapReverseIterator(ret.next()); + else + return ret; + } }; - HashBuckets.prototype.at = function (index) { - return this.buckets_.at(index); + /** + * @hidden + */ + MapContainer.prototype.insert_by_tuple = function (tuple) { + return this.insert_by_pair(new std.Pair(tuple[0], tuple[1])); }; - HashBuckets.prototype.hash_index = function (val) { - return std.hash(val) % this.buckets_.size(); + /** + * @hidden + */ + MapContainer.prototype.insert_by_hint_with_tuple = function (hint, tuple) { + return this.insert_by_hint(hint, std.make_pair(tuple[0], tuple[1])); }; - /* --------------------------------------------------------- - ELEMENTS I/O - --------------------------------------------------------- */ - HashBuckets.prototype.insert = function (val) { - this.buckets_.at(this.hash_index(val)).push_back(val); - if (++this.item_size_ > this.capacity()) - this.rehash(this.item_size_ * Hash.RATIO); + MapContainer.prototype.erase = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + if (args.length == 1 && (args[0] instanceof std.Iterator == false || args[0].get_source() != this)) + return this.erase_by_key(args[0]); + else if (args.length == 1) + return this.erase_by_iterator(args[0]); + else + return this.erase_by_iterator(args[0], args[1]); }; - HashBuckets.prototype.erase = function (val) { - var bucket = this.buckets_.at(this.hash_index(val)); - for (var i = 0; i < bucket.size(); i++) - if (bucket.at(i) == val) { - bucket.splice(i, 1); - this.item_size_--; - break; - } + /** + * @hidden + */ + MapContainer.prototype.erase_by_key = function (key) { + var it = this.find(key); + if (it.equal_to(this.end()) == true) + return 0; + this.erase_by_iterator(it); + return 1; + }; + /** + * @hidden + */ + MapContainer.prototype.erase_by_iterator = function (first, last) { + if (last === void 0) { last = first.next(); } + var ret; + var is_reverse_iterator = false; + // REVERSE ITERATOR TO ITERATOR + if (first instanceof std.MapReverseIterator) { + is_reverse_iterator = true; + var first_it = last.base(); + var last_it = first.base(); + first = first_it; + last = last_it; + } + // ERASE ELEMENTS + ret = this.erase_by_range(first, last); + // RETURN BRANCHES + if (is_reverse_iterator == true) + return new std.MapReverseIterator(ret.next()); + else + return ret; }; - return HashBuckets; - }()); - base.HashBuckets = HashBuckets; - })(base = std.base || (std.base = {})); -})(std || (std = {})); -///Bi-directional iterator.
- * - *{@link Iterator Bidirectional iterators} are iterators that can be used to access the sequence of elements - * in a range in both directions (towards the end and towards the beginning).
- * - *All {@link IArrayIterator random-access iterators} are also valid {@link Iterrator bidirectional iterators}. - *
- * - *There is not a single type of {@link Iterator bidirectional iterator}: {@link IContainer Each container} - * may define its own specific iterator type able to iterate through it and access its elements.
- * - *
- *
- *
Whether an iterator is equal with the iterator.
- * - *Compare two iterators and returns whether they are equal or not.
- * - *Iterator's equal_to() only compare souce container and index number.
- * - *Although elements in a pair, key and value are equal_to, if the source map or - * index number is different, then the {@link equal_to equal_to()} will return false. If you want to - * compare the elements of a pair, compare them directly by yourself.
- * - * @param obj An iterator to compare - * @return Indicates whether equal or not. - */ - Iterator.prototype.equal_to = function (obj) { - return this.source_ == obj.source_; - }; - Object.defineProperty(Iterator.prototype, "value", { /** - *Get value of the iterator is pointing.
- * - * @return A value of the iterator. + * @hidden */ - get: function () { - throw new std.LogicError("Have to be overriden."); - }, - enumerable: true, - configurable: true - }); - return Iterator; - }()); - std.Iterator = Iterator; + MapContainer.prototype.erase_by_range = function (begin, end) { + // ERASE + var listIterator = this.data_.erase(begin.get_list_iterator(), end.get_list_iterator()); + // POST-PROCESS + this.handle_erase(begin, end); + return new std.MapIterator(this, listIterator); + }; + return MapContainer; + }(base.Container)); + base.MapContainer = MapContainer; + })(base = std.base || (std.base = {})); })(std || (std = {})); var std; (function (std) { /** - *This class reverses the direction in which a bidirectional or random-access iterator iterates through a range. - *
- * - *A copy of the original iterator (the {@link Iterator base iterator}) is kept internally and used to reflect - * the operations performed on the {@link ReverseIterator}: whenever the {@link ReverseIterator} is incremented, its - * {@link Iterator base iterator} is decreased, and vice versa. A copy of the {@link Iterator base iterator} with the - * current state can be obtained at any time by calling member {@link base}.
- * - *Notice however that when an iterator is reversed, the reversed version does not point to the same element in - * the range, but to the one preceding it. This is so, in order to arrange for the past-the-end element of a - * range: An iterator pointing to a past-the-end element in a range, when reversed, is pointing to the last element - * (not past it) of the range (this would be the first element of the reversed range). And if an iterator to the - * first element in a range is reversed, the reversed iterator points to the element before the first element (this - * would be the past-the-end element of the reversed range).
+ *An iterator of {@link MapContainer map container}.
* - *
- *
- *
Return distance between {@link Iterator iterators}.
- * - *Calculates the number of elements between first and last.
- * - *If it is a {@link IArrayIterator random-access iterator}, the function uses operator- to calculate this. - * Otherwise, the function uses the increase operator {@link Iterator.next next()} repeatedly.
- * - * @param first Iterator pointing to the initial element. - * @param last Iterator pointing to the final element. This must be reachable from first. - * - * @return The number of elements between first and last. - */ - function distance(first, last) { - if (first.index != undefined) { - // WHEN IARRAY_ITERATOR - // ABS FOR REVERSE_ITERATOR - return Math.abs(last.index - first.index); - } - var length = 0; - for (; !first.equal_to(last); first = first.next()) - length++; - return length; - } - std.distance = distance; - /** - *Advance iterator.
- * - *Advances the iterator it by n elements positions.
- * - * @param it Iterator to be advanced. - * @param n Number of element positions to advance. - * - * @return An iterator to the element n positions before it. - */ - function advance(it, n) { - return it.advance(n); - } - std.advance = advance; - /** - *Get iterator to previous element.
- * - *Returns an iterator pointing to the element that it would be pointing to if advanced -n positions.
- * - * @param it Iterator to base position. - * @param n Number of element positions offset (1 by default). - * - * @return An iterator to the element n positions before it. - */ - function prev(it, n) { - if (n === void 0) { n = 1; } - return it.advance(n); - } - std.prev = prev; + *Whether an iterator is equal with the iterator.
+ * + *Compare two iterators and returns whether they are equal or not.
+ * + * @param obj An iterator to compare + * @return Indicates whether equal or not. + */ + MapIterator.prototype.equal_to = function (obj) { + return this.source_ == obj.source_ && this.list_iterator_.equal_to(obj.list_iterator_); + }; + MapIterator.prototype.less = function (obj) { + return std.less(this.first, obj.first); + }; + MapIterator.prototype.hash = function () { + return std.hash(this.first); + }; + MapIterator.prototype.swap = function (obj) { + this.list_iterator_.swap(obj.list_iterator_); + }; + return MapIterator; + }(std.Iterator)); + std.MapIterator = MapIterator; /** - *Get iterator to next element.
- * - *Returns an iterator pointing to the element that it would be pointing to if advanced n positions.
+ *A reverse-iterator of {@link MapContainer map container}.
* - * @param it Iterator to base position. - * @param n Number of element positions offset (1 by default). + * * - * @return An iterator to the element n positions away from it. + * @author Jeongho NamAn abstract map.
+ *An abstract multi-map.
* - *{@link MapContainer MapContainers} are associative containers that store elements formed by a combination - * of a key value (Key) and a mapped value (T), and which allows for fast retrieval - * of individual elements based on their keys.
+ *{@link MultiMap MultiMaps} are associative containers that store elements formed by a combination of a + * key value (Key) and a mapped value (T), and which allows for fast retrieval of + * individual elements based on their keys.
* *In a {@link MapContainer}, the key values are generally used to identify the elements, while the - * mapped values store the content associated to this key. The types of key and + * mapped values store the content associated to this key. The types of key and * mapped value may differ, and are grouped together in member type value_type, which is a * {@link Pair} type combining both:
* * typedef pair
{@link MapContainer} stores elements, keeps sequence and enables indexing by inserting elements into a + *
{@link UniqueMap} stores elements, keeps sequence and enables indexing by inserting elements into a * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index * table like {@link RBTree tree} or {@link HashBuckets hash-table}.
* - * + * * *Swap content.
+ * + *Exchanges the content of the container by the content of obj, which is another + * {@link UniqueMap map} of the same type. Sizes abd container type may differ.
+ * + *After the call to this member function, the elements in this container are those which were + * in obj before the call, and the elements of obj are those which were in this. All + * iterators, references and pointers remain valid for the swapped objects.
+ * + *Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that + * algorithm with an optimization that behaves like this member function.
+ * + * @param obj Another {@link MultiMap map container} of the same type of elements as this (i.e., + * with the same template parameters, Key and T) whose content is swapped + * with that of this {@link MultiMap container}. + */ + MultiMap.prototype.swap = function (obj) { + var vec = new std.Vector(this.begin(), this.end()); + this.assign(obj.begin(), obj.end()); + obj.assign(vec.begin(), vec.end()); + }; + return MultiMap; + }(base.MapContainer)); + base.MultiMap = MultiMap; + })(base = std.base || (std.base = {})); +})(std || (std = {})); +///An abstract set.
+ * + *{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of + * individual elements based on their value.
+ * + *In an {@link SetContainer}, the value of an element is at the same time its key, used to + * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be + * modified once in the container - they can be inserted and removed, though.
+ * + *{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a + * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index + * table like {@link RBTree tree} or {@link HashBuckets hash-table}.
+ * + * + * + *Return iterator to beginning.
- * - *Returns an iterator referring the first element in the
- * - *If the container is {@link empty}, the returned iterator is same with {@link end end()}.
- * - * @return An iterator to the first element in the The iterator containes the first element's value. + * @inheritdoc */ - MapContainer.prototype.begin = function () { - return new std.MapIterator(this, this.data_.begin()); + SetContainer.prototype.begin = function () { + return new std.SetIterator(this, this.data_.begin()); }; /** - *Return iterator to end.
- *Returns an iterator referring to the past-the-end element in the
- * - *The past-the-end element is the theoretical element that would follow the last element in the - * It does not point to any element, and thus shall not be dereferenced.
- * - *Because the ranges used by functions of the container do not include the element reference by their - * closing iterator, this function is often used in combination with {@link MapContainer}.{@link begin} to - * specify a range including all the elements in the
- * - *Returned iterator from {@link MapContainer}.{@link end} does not refer any element. Trying to accessing - * element by the iterator will cause throwing exception ({@link OutOfRange}).
- * - *If the container is {@link empty}, this function returns the same as {@link begin}.
- * - * @return An iterator to the end element in the + * @inheritdoc */ - MapContainer.prototype.end = function () { - return new std.MapIterator(this, this.data_.end()); - }; - /** - *Return {@link MapReverseIterator reverse iterator} to reverse beginning.
- * - *Returns a {@link MapReverseIterator reverse iterator} pointing to the last element in the container - * (i.e., its reverse beginning).
- * - * {@link MapReverseIterator Reverse iterators} iterate backwards: increasing them moves them towards the - * beginning of the container. - * - *{@link rbegin} points to the element preceding the one that would be pointed to by member {@link end}. - *
- * - * @return A {@link MapReverseIterator reverse iterator} to the reverse beginning of the sequence - * + SetContainer.prototype.end = function () { + return new std.SetIterator(this, this.data_.end()); + }; + /** + * @inheritdoc */ - MapContainer.prototype.rbegin = function () { - return new std.MapReverseIterator(this.end()); + SetContainer.prototype.rbegin = function () { + return new std.SetReverseIterator(this.end()); }; /** - *Return {@link MapReverseIterator reverse iterator} to reverse end.
- * - *Returns a {@link MapReverseIterator reverse iterator} pointing to the theoretical element right before - * the first element in the {@link MapContainer map container} (which is considered its reverse end). - *
- * - *The range between {@link MapContainer}.{@link rbegin} and {@link MapContainer}.{@link rend} contains - * all the elements of the container (in reverse order).
- * - * @return A {@link MapReverseIterator reverse iterator} to the reverse end of the sequence + * @inheritdoc */ - MapContainer.prototype.rend = function () { - return new std.MapReverseIterator(this.begin()); + SetContainer.prototype.rend = function () { + return new std.SetReverseIterator(this.begin()); }; /* --------------------------------------------------------- ELEMENTS @@ -3746,87 +3292,80 @@ var std; /** *Whether have the item or not.
* - *Indicates whether a map has an item having the specified identifier.
+ *Indicates whether a set has an item having the specified identifier.
* * @param key Key value of the element whose mapped value is accessed. * - * @return Whether the map has an item having the specified identifier. + * @return Whether the set has an item having the specified identifier. */ - MapContainer.prototype.has = function (key) { - return !this.find(key).equal_to(this.end()); + SetContainer.prototype.has = function (val) { + return !this.find(val).equal_to(this.end()); }; /** - * Return the number of elements in the map. + * @inheritdoc */ - MapContainer.prototype.size = function () { + SetContainer.prototype.size = function () { return this.data_.size(); }; - MapContainer.prototype.push = function () { + /* ========================================================= + ELEMENTS I/O + - INSERT + - ERASE + - POST-PROCESS + ============================================================ + INSERT + --------------------------------------------------------- */ + /** + * @inheritdoc + */ + SetContainer.prototype.push = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i - 0] = arguments[_i]; } // TO BE ABSTRACT for (var i = 0; i < args.length; i++) - if (args[i] instanceof std.Pair) - this.insert_by_pair(args[i]); - else if (args[i] instanceof Array) - this.insert_by_tuple(args[i]); + this.insert_by_val(args[i]); return this.size(); }; - MapContainer.prototype.insert = function () { + SetContainer.prototype.insert = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i - 0] = arguments[_i]; } - if (args.length == 1 && args[0] instanceof std.Pair) { - return this.insert_by_pair(args[0]); - } - else if (args.length == 1 && args[0] instanceof Array) { - return this.insert_by_tuple(args[0]); - } - else if (args.length == 2 && args[0] instanceof std.Iterator && args[1] instanceof std.Iterator) { - return this.insert_by_range(args[0], args[1]); - } - else { - var ret = void 0; - var is_reverse_iterator = false; - // REVERSE_ITERATOR TO ITERATOR - if (args[0] instanceof std.MapReverseIterator) { - is_reverse_iterator = true; - args[0] = args[0].base().prev(); + if (args.length == 1) + return this.insert_by_val(args[0]); + else if (args.length == 2 && args[0] instanceof std.Iterator) { + if (args[1] instanceof std.Iterator && args[0].get_source() != this && args[1].get_source() != this) { + // IT DOESN'T CONTAIN POSITION + // RANGES TO INSERT ONLY + return this.insert_by_range(args[0], args[1]); } - // INSERT AN ELEMENT - if (args[1] instanceof std.Pair) + else { + var ret = void 0; + var is_reverse_iterator = false; + // REVERSE_ITERATOR TO ITERATOR + if (args[0] instanceof std.SetReverseIterator) { + is_reverse_iterator = true; + args[0] = args[0].base().prev(); + } + // INSERT AN ELEMENT ret = this.insert_by_hint(args[0], args[1]); - else - ret = this.insert_by_hint_with_tuple(args[0], args[1]); - // RETURN BRANCHES - if (is_reverse_iterator == true) - return new std.MapReverseIterator(ret.next()); - else - return ret; + // RETURN BRANCHES + if (is_reverse_iterator == true) + return new std.SetReverseIterator(ret.next()); + else + return ret; + } } }; - /** - * @hidden - */ - MapContainer.prototype.insert_by_tuple = function (tuple) { - return this.insert_by_pair(new std.Pair(tuple[0], tuple[1])); - }; - /** - * @hidden - */ - MapContainer.prototype.insert_by_hint_with_tuple = function (hint, tuple) { - return this.insert_by_hint(hint, std.make_pair(tuple[0], tuple[1])); - }; - MapContainer.prototype.erase = function () { + SetContainer.prototype.erase = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i - 0] = arguments[_i]; } if (args.length == 1 && (args[0] instanceof std.Iterator == false || args[0].get_source() != this)) - return this.erase_by_key(args[0]); + return this.erase_by_val(args[0]); else if (args.length == 1) return this.erase_by_iterator(args[0]); else @@ -3835,22 +3374,12 @@ var std; /** * @hidden */ - MapContainer.prototype.erase_by_key = function (key) { - var it = this.find(key); - if (it.equal_to(this.end()) == true) - return 0; - this.erase_by_iterator(it); - return 1; - }; - /** - * @hidden - */ - MapContainer.prototype.erase_by_iterator = function (first, last) { + SetContainer.prototype.erase_by_iterator = function (first, last) { if (last === void 0) { last = first.next(); } var ret; var is_reverse_iterator = false; // REVERSE ITERATOR TO ITERATOR - if (first instanceof std.MapReverseIterator) { + if (first instanceof std.SetReverseIterator) { is_reverse_iterator = true; var first_it = last.base(); var last_it = first.base(); @@ -3861,75 +3390,85 @@ var std; ret = this.erase_by_range(first, last); // RETURN BRANCHES if (is_reverse_iterator == true) - return new std.MapReverseIterator(ret.next()); + return new std.SetReverseIterator(ret.next()); else return ret; }; /** * @hidden */ - MapContainer.prototype.erase_by_range = function (begin, end) { + SetContainer.prototype.erase_by_val = function (val) { + // TEST WHETHER EXISTS + var it = this.find(val); + if (it.equal_to(this.end()) == true) + return 0; // ERASE - var listIterator = this.data_.erase(begin.get_list_iterator(), end.get_list_iterator()); + this.erase_by_iterator(it); + return 1; + }; + /** + * @hidden + */ + SetContainer.prototype.erase_by_range = function (begin, end) { + // ERASE + var list_iterator = this.data_.erase(begin.get_list_iterator(), end.get_list_iterator()); // POST-PROCESS this.handle_erase(begin, end); - return new std.MapIterator(this, listIterator); + return new std.SetIterator(this, list_iterator); //begin.prev(); }; - return MapContainer; + return SetContainer; }(base.Container)); - base.MapContainer = MapContainer; + base.SetContainer = SetContainer; })(base = std.base || (std.base = {})); })(std || (std = {})); var std; (function (std) { /** - *An iterator of {@link MapContainer map container}.
+ *An iterator of a Set.
* - * + * * * @author Jeongho NamConstruct from source and index number.
* - * @param source The source {@link MapContainer}. - * @param list_iterator A {@link ListIterator} pointing {@link Pair} of key and value. + *Do not create iterator directly.
+ *Use begin(), find() or end() in Map instead.
+ * + * @param map The source Set to reference. + * @param index Sequence number of the element in the source Set. */ - function MapIterator(source, list_iterator) { + function SetIterator(source, it) { _super.call(this, source); - this.list_iterator_ = list_iterator; + this.list_iterator_ = it; } /* --------------------------------------------------------- MOVERS --------------------------------------------------------- */ /** - * Get iterator to previous element. + * @inheritdoc */ - MapIterator.prototype.prev = function () { - return new MapIterator(this.map, this.list_iterator_.prev()); + SetIterator.prototype.prev = function () { + return new SetIterator(this.set, this.list_iterator_.prev()); }; /** - * Get iterator to next element. + * @inheritdoc */ - MapIterator.prototype.next = function () { - return new MapIterator(this.map, this.list_iterator_.next()); + SetIterator.prototype.next = function () { + return new SetIterator(this.set, this.list_iterator_.next()); }; /** - * Advances the Iterator by n element positions. - * - * @param step Number of element positions to advance. - * @return An advanced Iterator. + * @inheritdoc */ - MapIterator.prototype.advance = function (step) { - return new MapIterator(this.map, this.list_iterator_.advance(step)); + SetIterator.prototype.advance = function (size) { + return new SetIterator(this.set, this.list_iterator_.advance(size)); }; - Object.defineProperty(MapIterator.prototype, "map", { + Object.defineProperty(SetIterator.prototype, "set", { /* --------------------------------------------------------- ACCESSORS --------------------------------------------------------- */ @@ -3942,13 +3481,10 @@ var std; enumerable: true, configurable: true }); - /** - * Get ListIterator. - */ - MapIterator.prototype.get_list_iterator = function () { + SetIterator.prototype.get_list_iterator = function () { return this.list_iterator_; }; - Object.defineProperty(MapIterator.prototype, "value", { + Object.defineProperty(SetIterator.prototype, "value", { /** * @inheritdoc */ @@ -3958,698 +3494,980 @@ var std; enumerable: true, configurable: true }); - Object.defineProperty(MapIterator.prototype, "first", { - /** - * Get first, key element. - */ - get: function () { - return this.list_iterator_.value.first; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(MapIterator.prototype, "second", { - /** - * Get second, value element. - */ - get: function () { - return this.list_iterator_.value.second; - }, - /** - * Set second value. - */ - set: function (val) { - this.list_iterator_.value.second = val; - }, - enumerable: true, - configurable: true - }); /* --------------------------------------------------------- COMPARISONS --------------------------------------------------------- */ /** - *Whether an iterator is equal with the iterator.
- * - *Compare two iterators and returns whether they are equal or not.
- * - * @param obj An iterator to compare - * @return Indicates whether equal or not. + * @inheritdoc */ - MapIterator.prototype.equal_to = function (obj) { - return this.source_ == obj.source_ && this.list_iterator_.equal_to(obj.list_iterator_); + SetIterator.prototype.equal_to = function (obj) { + return _super.prototype.equal_to.call(this, obj) && this.list_iterator_ == obj.list_iterator_; }; - MapIterator.prototype.less = function (obj) { - return std.less(this.first, obj.first); + /** + * @inheritdoc + */ + SetIterator.prototype.less = function (obj) { + return std.less(this.value, obj.value); }; - MapIterator.prototype.hash = function () { - return std.hash(this.first); + /** + * @inheritdoc + */ + SetIterator.prototype.hash = function () { + return std.hash(this.value); }; - MapIterator.prototype.swap = function (obj) { + /** + * @inheritdoc + */ + SetIterator.prototype.swap = function (obj) { this.list_iterator_.swap(obj.list_iterator_); }; - return MapIterator; + return SetIterator; }(std.Iterator)); - std.MapIterator = MapIterator; + std.SetIterator = SetIterator; /** - *A reverse-iterator of {@link MapContainer map container}.
+ *A reverse-iterator of Set.
* - * + * + * + * @paramHash buckets storing {@link MapIterator MapIterators}.
- * - *
- *
- *
An abstract multi-map.
- * - *{@link MultiMap MultiMaps} are associative containers that store elements formed by a combination of a - * key value (Key) and a mapped value (T), and which allows for fast retrieval of - * individual elements based on their keys.
+ *An abstract set.
* - *In a {@link MapContainer}, the key values are generally used to identify the elements, while the - * mapped values store the content associated to this key. The types of key and - * mapped value may differ, and are grouped together in member type value_type, which is a - * {@link Pair} type combining both:
+ *{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of + * individual elements based on their value.
* - * typedef pair
In an {@link SetContainer}, the value of an element is at the same time its key, used to + * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be + * modified once in the container - they can be inserted and removed, though.
* - *{@link UniqueMap} stores elements, keeps sequence and enables indexing by inserting elements into a + *
{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index * table like {@link RBTree tree} or {@link HashBuckets hash-table}.
* - * + * * *Swap content.
- * - *Exchanges the content of the container by the content of obj, which is another - * {@link UniqueMap map} of the same type. Sizes abd container type may differ.
- * - *After the call to this member function, the elements in this container are those which were - * in obj before the call, and the elements of obj are those which were in this. All - * iterators, references and pointers remain valid for the swapped objects.
- * - *Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.
- * - * @param obj Another {@link MultiMap map container} of the same type of elements as this (i.e., - * with the same template parameters, Key and T) whose content is swapped - * with that of this {@link MultiMap container}. + * @inheritdoc */ - MultiMap.prototype.swap = function (obj) { + MultiSet.prototype.swap = function (obj) { var vec = new std.Vector(this.begin(), this.end()); this.assign(obj.begin(), obj.end()); obj.assign(vec.begin(), vec.end()); }; - return MultiMap; - }(base.MapContainer)); - base.MultiMap = MultiMap; + return MultiSet; + }(base.SetContainer)); + base.MultiSet = MultiSet; })(base = std.base || (std.base = {})); })(std || (std = {})); ///An abstract set.
+ *Red-black Tree.
* - *{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of - * individual elements based on their value.
+ *A red-black tree is a kind of self-balancing + * binary search tree. Each node of the binary tree has an extra bit, and that bit is often interpreted as the + * color (red or black) of the node. These color bits + * are used to ensure the tree remains approximately balanced during insertions and deletions.
* - *In an {@link SetContainer}, the value of an element is at the same time its key, used to - * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be - * modified once in the container - they can be inserted and removed, though.
+ *Balance is preserved by painting each node of the tree with one of two colors (typically called + * 'red' and 'black') in a way that satisfies certain + * properties, which collectively constrain how unbalanced the tree can become in the worst case. When the tree + * is modified, the new tree is subsequently rearranged and repainted to restore the coloring properties. The + * properties are designed in such a way that this rearranging and recoloring can be performed efficiently.
* - *{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a - * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index - * table like {@link RBTree tree} or {@link HashBuckets hash-table}.
+ *The balancing of the tree is not perfect but it is good enough to allow it to guarantee searching in + * O(log n) time, where n is the total number of elements in the tree. The insertion and deletion operations, + * along with the tree rearrangement and recoloring, are also performed in O(log n) time.
+ * + *Tracking the color of each node requires only 1 bit of information per node because there are only two + * colors. The tree does not contain any other data specific to its being a + * red-black tree so its memory footprint is almost + * identical to a classic (uncolored) binary search tree. In many cases the additional bit of information can + * be stored at no additional memory cost.
* - * + *In addition to the requirements imposed on a binary search tree the following must be satisfied by a + * red-black tree:
* - *null
) are black.
These constraints enforce a critical property of red-black trees: the path from the root to the farthest + * leaf is no more than twice as long as the path from the root to the nearest leaf. The result is that the tree + * is roughly height-balanced. Since operations such as inserting, deleting, and finding values require + * worst-case time proportional to the height of the tree, this theoretical upper bound on the height allows + * red-black trees to be efficient in the worst case, unlike ordinary binary search trees.
* - * @author Jeongho NamTo see why this is guaranteed, it suffices to consider the effect of properties 4 and 5 together. For a + * red-black tree T, let B be the number of black nodes in property 5. Let the + * shortest possible path from the root of T to any leaf consist of B black nodes. + * Longer possible paths may be constructed by inserting red nodes. However, property 4 + * makes it impossible to insert more than one consecutive red node. Therefore, + * ignoring any black NIL leaves, the longest possible path consists of 2*B nodes, + * alternating black and red (this is the worst case). + * Counting the black NIL leaves, the longest possible path consists of 2*B-1 + * nodes.
+ * + *The shortest possible path has all black nodes, and the longest possible + * path alternates between red and black nodes. Since all + * maximal paths have the same number of black nodes, by property 5, this shows + * that no path is more than twice as long as any other path.
+ * + * @paramInsert an element with a new node.
+ * + *Insertion begins by adding the node as any binary search tree insertion does and by coloring it + * red. Whereas in the binary search tree, we always add a leaf, in the red-black + * tree, leaves contain no information, so instead we add a red interior node, with + * two black leaves, in place of an existing + * black leaf.
+ * + *What happens next depends on the color of other nearby nodes. The term uncle node will be used to + * refer to the sibling of a node's parent, as in human family trees. Note that:
+ * + *There are several cases of red-black tree insertion to handle:
+ * + *Note that inserting is actually in-place, since all the calls above use tail recursion.
+ * + *In the algorithm above, all cases are chained in order, except in insert case 3 where it can recurse + * to case 1 back to the grandparent node: this is the only case where an iterative implementation will + * effectively loop. Because the problem of repair is escalated to the next higher level but one, it takes + * maximally h⁄2 iterations to repair the tree (where h is the height of the tree). Because the probability + * for escalation decreases exponentially with each iteration the average insertion cost is constant.
+ * + * @param val An element to insert. */ - SetContainer.prototype.construct_from_container = function (container) { - this.construct_from_range(container.begin(), container.end()); + XTree.prototype.insert = function (val) { + var parent = this.find(val); + var node = new base.XTreeNode(val, base.Color.RED); + if (parent == null) + this.root_ = node; + else { + node.parent = parent; + if (this.is_less(node.value, parent.value)) + parent.left = node; + else + parent.right = node; + } + this.insert_case1(node); }; /** - * @hidden + *N is the root node, i.e., first node of red-black tree.
+ * + *The current node N is at the {@link root_ root} of the tree.
+ * + *In this case, it is repainted black to satisfy property 2 (the root is + * black). Since this adds one black node to + * every path at once, property 5 (all paths from any given node to its leaf nodes contain the same number + * of black nodes) is not violated.
+ * + * @param N A node to be inserted or swapped. */ - SetContainer.prototype.construct_from_range = function (begin, end) { - this.assign(begin, end); + XTree.prototype.insert_case1 = function (N) { + if (N.parent == null) + N.color = base.Color.BLACK; + else + this.insert_case2(N); }; - /* --------------------------------------------------------- - ASSIGN & CLEAR - --------------------------------------------------------- */ /** - * @inheritdoc + *N's parent ({@link XTreeNode.parent P}) is black.
+ * + *The current node's parent {@link XTreeNode.parent P} is black, + * so property 4 (both children of every red node are + * black) is not invalidated.
+ * + *In this case, the tree is still valid. Property 5 (all paths from any given node to its leaf nodes + * contain the same number of black nodes) is not threatened, because the + * current node N has two black leaf children, but because + * N is red, the paths through each of its children have the same + * number of black nodes as the path through the leaf it replaced, which was + * black, and so this property remains satisfied.
+ * + * @param N A node to be inserted or swapped. + */ + XTree.prototype.insert_case2 = function (N) { + if (this.fetch_color(N.parent) == base.Color.BLACK) + return; + else + this.insert_case3(N); + }; + /** + *N's parent ({@link XTreeNode.parent P}) and uncle + * ({@link XTreeNode.uncle U}) are red.
+ * + *If both the parent {@link XTreeNode.parent P} and the uncle {@link XTreeNode.uncle U} + * are red, then both of them can be repainted black + * and the grandparent {@link XTreeNode.grand_parent G} becomes red (to + * maintain property 5 (all paths from any given node to its leaf nodes contain the same number of + * black nodes)).
+ * + *Now, the current red node N has a + * black parent. Since any path through the parent or uncle must pass through + * the grandparent, the number of black nodes on these paths has not changed. + * + *
However, the grandparent {@link XTreeNode.grand_parent G} may now violate properties 2 (The + * root is black) or 4 (Both children of every red + * node are black) (property 4 possibly being violated since + * {@link XTreeNode.grand_parent G} may have a red parent).
+ * + *To fix this, the entire procedure is recursively performed on {@link XTreeNode.grand_parent G} + * from case 1. Note that this is a tail-recursive call, so it could be rewritten as a loop; since this is + * the only loop, and any rotations occur after this loop, this proves that a constant number of rotations + * occur.
+ * + *
N is added to right of left child of grandparent, or N is added to left + * of right child of grandparent ({@link XTreeNode.parent P} is red and + * {@link XTreeNode.uncle U} is black).
+ * + *The parent {@link XTreeNode.parent P} is red but the uncle + * {@link XTreeNode.uncle U} is black; also, the current node + * N is the right child of {@link XTreeNode.parent P}, and + * {@link XTreeNode.parent P} in turn is the left child of its parent + * {@link XTreeNode.grand_parent G}.
+ * + *In this case, a left rotation on {@link XTreeNode.parent P} that switches the roles of the + * current node N and its parent {@link XTreeNode.parent P} can be performed; then, + * the former parent node {@link XTreeNode.parent P} is dealt with using case 5 + * (relabeling N and {@link XTreeNode.parent P}) because property 4 (both children of + * every red node are black) is still violated.
+ * + *The rotation causes some paths (those in the sub-tree labelled "1") to pass through the node + * N where they did not before. It also causes some paths (those in the sub-tree labelled "3") + * not to pass through the node {@link XTreeNode.parent P} where they did before. However, both of + * these nodes are red, so property 5 (all paths from any given node to its leaf + * nodes contain the same number of black nodes) is not violated by the + * rotation.
+ * + *After this case has been completed, property 4 (both children of every red + * node are black) is still violated, but now we can resolve this by + * continuing to case 5.
+ * + *
N is added to left of left child of grandparent, or N is added to right + * of right child of grandparent ({@link XTreeNode.parent P} is red and + * {@link XTreeNode.uncle U} is black).
+ * + *The parent {@link XTreeNode.parent P} is red but the uncle + * {@link XTreeNode.uncle U} is black, the current node N + * is the left child of {@link XTreeNode.parent P}, and {@link XTreeNode.parent P} is the left + * child of its parent {@link XTreeNode.grand_parent G}.
+ * + *In this case, a right rotation on {@link XTreeNode.grand_parent G} is performed; the result is a + * tree where the former parent {@link XTreeNode.parent P} is now the parent of both the current node + * N and the former grandparent {@link XTreeNode.grand_parent G}.
+ * + *{@link XTreeNode.grand_parent G} is known to be black, since its + * former child {@link XTreeNode.parent P} could not have been red otherwise + * (without violating property 4). Then, the colors of {@link XTreeNode.parent P} and + * {@link XTreeNode.grand_parent G} are switched, and the resulting tree satisfies property 4 (both + * children of every red node are black). Property 5 + * (all paths from any given node to its leaf nodes contain the same number of + * black nodes) also remains satisfied, since all paths that went through any + * of these three nodes went through {@link XTreeNode.grand_parent G} before, and now they all go + * through {@link XTreeNode.parent P}. In each case, this is the only + * black node of the three.
+ * + *
Erase an element with its node.
+ * + *In a regular binary search tree when deleting a node with two non-leaf children, we find either the + * maximum element in its left subtree (which is the in-order predecessor) or the minimum element in its + * right subtree (which is the in-order successor) and move its value into the node being deleted (as shown + * here). We then delete the node we copied the value from, which must have fewer than two non-leaf children. + * (Non-leaf children, rather than all children, are specified here because unlike normal binary search + * trees, red-black trees can have leaf nodes anywhere, so that all nodes are either internal nodes with + * two children or leaf nodes with, by definition, zero children. In effect, internal nodes having two leaf + * children in a red-black tree are like the leaf nodes in a regular binary search tree.) Because merely + * copying a value does not violate any red-black properties, this reduces to the problem of deleting a node + * with at most one non-leaf child. Once we have solved that problem, the solution applies equally to the + * case where the node we originally want to delete has at most one non-leaf child as to the case just + * considered where it has two non-leaf children.
+ * + *Therefore, for the remainder of this discussion we address the deletion of a node with at most one + * non-leaf child. We use the label M to denote the node to be deleted; C will denote a + * selected child of M, which we will also call "its child". If M does have a non-leaf child, + * call that its child, C; otherwise, choose either leaf as its child, C.
+ * + *If M is a red node, we simply replace it with its child C, + * which must be black by property 4. (This can only occur when M has + * two leaf children, because if the red node M had a + * black non-leaf child on one side but just a leaf child on the other side, + * then the count of black nodes on both sides would be different, thus the + * tree would violate property 5.) All paths through the deleted node will simply pass through one fewer + * red node, and both the deleted node's parent and child must be + * black, so property 3 (all leaves are black) + * and property 4 (both children of every red node are + * black) still hold.
+ * + *Another simple case is when M is black and C is + * red. Simply removing a black node could break + * Properties 4 (“Both children of every red node are + * black”) and 5 (“All paths from any given node to its leaf nodes contain the + * same number of black nodes”), but if we repaint C + * black, both of these properties are preserved.
+ * + *The complex case is when both M and C are black. (This + * can only occur when deleting a black node which has two leaf children, + * because if the black node M had a black + * non-leaf child on one side but just a leaf child on the other side, then the count of + * black nodes on both sides would be different, thus the tree would have been + * an invalid red-black tree by violation of property 5.) We begin by replacing M with its child + * C. We will relabel this child C (in its new position) N, and its sibling (its + * new parent's other child) {@link XTreeNode.sibling S}. ({@link XTreeNode.sibling S} was + * previously the sibling of M.)
+ * + *In the diagrams below, we will also use {@link XTreeNode.parent P} for N's new + * parent (M's old parent), SL for {@link XTreeNode.sibling S}'s left child, and + * SR for {@link XTreeNode.sibling S}'s right child ({@link XTreeNode.sibling S} cannot + * be a leaf because if M and C were black, then + * {@link XTreeNode.parent P}'s one subtree which included M counted two + * black-height and thus {@link XTreeNode.parent P}'s other subtree + * which includes {@link XTreeNode.sibling S} must also count two + * black-height, which cannot be the case if {@link XTreeNode.sibling S} + * is a leaf node).
+ * + *If both N and its original parent are black, then + * deleting this original parent causes paths which proceed through N to have one fewer + * black node than paths that do not. As this violates property 5 (all paths + * from any given node to its leaf nodes contain the same number of black + * nodes), the tree must be rebalanced. There are several cases to consider:
+ * + *Again, the function calls all use tail recursion, so the algorithm is in-place.
+ * + *In the algorithm above, all cases are chained in order, except in delete case 3 where it can recurse + * to case 1 back to the parent node: this is the only case where an iterative implementation will + * effectively loop. No more than h loops back to case 1 will occur (where h is the height of the tree). + * And because the probability for escalation decreases exponentially with each iteration the average + * removal cost is constant.
+ * + *Additionally, no tail recursion ever occurs on a child node, so the tail recursion loop can only + * move from a child back to its successive ancestors. If a rotation occurs in case 2 (which is the only + * possibility of rotation within the loop of cases 1–3), then the parent of the node N + * becomes red after the rotation and we will exit the loop. Therefore, at most one + * rotation will occur within this loop. Since no more than two additional rotations will occur after + * exiting the loop, at most three rotations occur in total.
+ * + * @param val An element to erase. */ - SetContainer.prototype.end = function () { - return new std.SetIterator(this, this.data_.end()); + XTree.prototype.erase = function (val) { + var node = this.find(val); + if (node == null || this.is_equal_to(val, node.value) == false) + return; + if (node.left != null && node.right != null) { + var pred = this.fetch_maximum(node.left); + node.value = pred.value; + node = pred; + } + var child = (node.right == null) ? node.left : node.right; + if (this.fetch_color(node) == base.Color.BLACK) { + node.color = this.fetch_color(child); + this.erase_case1(node); + } + this.replace_node(node, child); }; /** - * @inheritdoc + *N is the new root.
+ * + *In this case, we are done. We removed one black node from every path, + * and the new root is black, so the properties are preserved.
+ * + *In cases 2, 5, and 6, we assume N is the left child of its parent + * {@link XTreeNode.parent P}. If it is the right child, left and right should be reversed throughout + * these three cases. Again, the code examples take both cases into account.
+ * + * @param N A node to be erased or swapped. */ - SetContainer.prototype.rbegin = function () { - return new std.SetReverseIterator(this.end()); + XTree.prototype.erase_case1 = function (N) { + if (N.parent == null) + return; + else + this.erase_case2(N); }; /** - * @inheritdoc + *{@link XTreeNode.sibling S} is red.
+ * + *
In this case we reverse the colors of {@link XTreeNode.parent P} and + * {@link XTreeNode.sibling S}, and then rotate left at {@link XTreeNode.parent P}, turning + * {@link XTreeNode.sibling S} into N's grandparent.
+ * + *Note that {@link XTreeNode.parent P} has to be black as it had a + * red child. The resulting subtree has a path short one + * black node so we are not done. Now N has a + * black sibling and a red parent, so we can proceed + * to step 4, 5, or 6. (Its new sibling is black because it was once the child + * of the red {@link XTreeNode.sibling S}.) In later cases, we will re-label + * N's new sibling as {@link XTreeNode.sibling S}.
+ * + * @param N A node to be erased or swapped. */ - SetContainer.prototype.rend = function () { - return new std.SetReverseIterator(this.begin()); + XTree.prototype.erase_case2 = function (N) { + if (this.fetch_color(N.sibling) == base.Color.RED) { + N.parent.color = base.Color.RED; + N.sibling.color = base.Color.BLACK; + if (N == N.parent.left) + this.rotate_left(N.parent); + else + this.rotate_right(N.parent); + } + this.erase_case3(N); }; - /* --------------------------------------------------------- - ELEMENTS - --------------------------------------------------------- */ /** - *Whether have the item or not.
+ *{@link XTreeNode.parent P}, {@link XTreeNode.sibling S}, and {@link XTreeNode.sibling + * S}'s children are black.
* - *Indicates whether a set has an item having the specified identifier.
+ *
In this case, we simply repaint {@link XTreeNode.sibling S} red. The + * result is that all paths passing through {@link XTreeNode.sibling S}, which are precisely those + * paths not passing through N, have one less black node. + * Because deleting N's original parent made all paths passing through N have + * one less black node, this evens things up.
* - * @return Whether the set has an item having the specified identifier. + *However, all paths through {@link XTreeNode.parent P} now have one fewer + * black node than paths that do not pass through + * {@link XTreeNode.parent P}, so property 5 (all paths from any given node to its leaf nodes contain + * the same number of black nodes) is still violated.
+ * + *To correct this, we perform the rebalancing procedure on {@link XTreeNode.parent P}, starting + * at case 1.
+ * + * @param N A node to be erased or swapped. */ - SetContainer.prototype.has = function (val) { - return !this.find(val).equal_to(this.end()); + XTree.prototype.erase_case3 = function (N) { + if (this.fetch_color(N.parent) == base.Color.BLACK && + this.fetch_color(N.sibling) == base.Color.BLACK && + this.fetch_color(N.sibling.left) == base.Color.BLACK && + this.fetch_color(N.sibling.right) == base.Color.BLACK) { + N.sibling.color = base.Color.RED; + this.erase_case1(N.parent); + } + else + this.erase_case4(N); }; /** - * @inheritdoc + *{@link XTreeNode.sibling S} and {@link XTreeNode.sibling S}'s children are + * black, but {@link XTreeNode.parent P} is red.
+ * + *
In this case, we simply exchange the colors of {@link XTreeNode.sibling S} and + * {@link XTreeNode.parent P}. This does not affect the number of black + * nodes on paths going through {@link XTreeNode.sibling S}, but it does add one to the number of + * black nodes on paths going through N, making up for the + * deleted black node on those paths.
+ * + * @param N A node to be erased or swapped. */ - SetContainer.prototype.size = function () { - return this.data_.size(); + XTree.prototype.erase_case4 = function (N) { + if (this.fetch_color(N.parent) == base.Color.RED && + N.sibling != null && + this.fetch_color(N.sibling) == base.Color.BLACK && + this.fetch_color(N.sibling.left) == base.Color.BLACK && + this.fetch_color(N.sibling.right) == base.Color.BLACK) { + N.sibling.color = base.Color.RED; + N.parent.color = base.Color.BLACK; + } + else + this.erase_case5(N); }; - /* ========================================================= - ELEMENTS I/O - - INSERT - - ERASE - - POST-PROCESS - ============================================================ - INSERT - --------------------------------------------------------- */ /** - * @inheritdoc + *{@link XTreeNode.sibling S} is black, {@link XTreeNode.sibling S}'s + * left child is red, {@link XTreeNode.sibling S}'s right child is + * black, and N is the left child of its parent.
+ * + *
In this case we rotate right at {@link XTreeNode.sibling S}, so that + * {@link XTreeNode.sibling S}'s left child becomes {@link XTreeNode.sibling S}'s parent and + * N's new sibling. We then exchange the colors of {@link XTreeNode.sibling S} and its + * new parent.
+ * + *All paths still have the same number of black nodes, but now + * N has a black sibling whose right child is + * red, so we fall into case 6. Neither N nor its parent are affected + * by this transformation. (Again, for case 6, we relabel N's new sibling as + * {@link XTreeNode.sibling S}.)
+ * + * @param N A node to be erased or swapped. */ - SetContainer.prototype.push = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; - } - // TO BE ABSTRACT - for (var i = 0; i < args.length; i++) - this.insert_by_val(args[i]); - return this.size(); - }; - SetContainer.prototype.insert = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; - } - if (args.length == 1) - return this.insert_by_val(args[0]); - else if (args.length == 2 && args[0] instanceof std.Iterator) { - if (args[1] instanceof std.Iterator && args[0].get_source() != this && args[1].get_source() != this) { - // IT DOESN'T CONTAIN POSITION - // RANGES TO INSERT ONLY - return this.insert_by_range(args[0], args[1]); - } - else { - var ret = void 0; - var is_reverse_iterator = false; - // REVERSE_ITERATOR TO ITERATOR - if (args[0] instanceof std.SetReverseIterator) { - is_reverse_iterator = true; - args[0] = args[0].base().prev(); - } - // INSERT AN ELEMENT - ret = this.insert_by_hint(args[0], args[1]); - // RETURN BRANCHES - if (is_reverse_iterator == true) - return new std.SetReverseIterator(ret.next()); - else - return ret; - } + XTree.prototype.erase_case5 = function (N) { + if (N == N.parent.left && + N.sibling != null && + this.fetch_color(N.sibling) == base.Color.BLACK && + this.fetch_color(N.sibling.left) == base.Color.RED && + this.fetch_color(N.sibling.right) == base.Color.BLACK) { + N.sibling.color = base.Color.RED; + N.sibling.left.color = base.Color.BLACK; + this.rotate_right(N.sibling); } - }; - SetContainer.prototype.erase = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + else if (N == N.parent.right && + N.sibling != null && + this.fetch_color(N.sibling) == base.Color.BLACK && + this.fetch_color(N.sibling.left) == base.Color.BLACK && + this.fetch_color(N.sibling.right) == base.Color.RED) { + N.sibling.color = base.Color.RED; + N.sibling.right.color = base.Color.BLACK; + this.rotate_left(N.sibling); } - if (args.length == 1 && (args[0] instanceof std.Iterator == false || args[0].get_source() != this)) - return this.erase_by_val(args[0]); - else if (args.length == 1) - return this.erase_by_iterator(args[0]); - else - return this.erase_by_iterator(args[0], args[1]); }; /** - * @hidden - */ - SetContainer.prototype.erase_by_iterator = function (first, last) { - if (last === void 0) { last = first.next(); } - var ret; - var is_reverse_iterator = false; - // REVERSE ITERATOR TO ITERATOR - if (first instanceof std.SetReverseIterator) { - is_reverse_iterator = true; - var first_it = last.base(); - var last_it = first.base(); - first = first_it; - last = last_it; + *{@link XTreeNode.sibling S} is black, + * {@link XTreeNode.sibling S}'s right child is red, and N is + * the left child of its parent {@link XTreeNode.parent P}.
+ * + *In this case we rotate left at {@link XTreeNode.parent P}, so that + * {@link XTreeNode.sibling S} becomes the parent of {@link XTreeNode.parent P} and + * {@link XTreeNode.sibling S}'s right child. We then exchange the colors of + * {@link XTreeNode.parent P} and {@link XTreeNode.sibling S}, and make + * {@link XTreeNode.sibling S}'s right child black.
+ * + *The subtree still has the same color at its root, so Properties 4 (Both children of every + * red node are black) and 5 (All paths from any + * given node to its leaf nodes contain the same number of black nodes) are + * not violated. However, N now has one additional black + * ancestor: either {@link XTreeNode.parent P} has become black, or it + * was black and {@link XTreeNode.sibling S} was added as a + * black grandparent.
+ * + *Thus, the paths passing through N pass through one additional + * black node.
+ * + *
Meanwhile, if a path does not go through N, then there are two possibilities:
+ *Either way, the number of black nodes on these paths does not change. + * Thus, we have restored Properties 4 (Both children of every red node are + * black) and 5 (All paths from any given node to its leaf nodes contain the + * same number of black nodes). The white node in the diagram can be either + * red or black, but must refer to the same color + * both before and after the transformation.
+ * + * @param N A node to be erased or swapped. + */ + XTree.prototype.erase_case6 = function (node) { + node.sibling.color = this.fetch_color(node.parent); + node.parent.color = base.Color.BLACK; + if (node == node.parent.left) { + node.sibling.right.color = base.Color.BLACK; + this.rotate_left(node.parent); + } + else { + node.sibling.left.color = base.Color.BLACK; + this.rotate_right(node.parent); } - // ERASE ELEMENTS - ret = this.erase_by_range(first, last); - // RETURN BRANCHES - if (is_reverse_iterator == true) - return new std.SetReverseIterator(ret.next()); - else - return ret; }; + /* --------------------------------------------------------- + ROTATION + --------------------------------------------------------- */ /** - * @hidden + * Rotate a node left. + * + * @param node Node to rotate left. */ - SetContainer.prototype.erase_by_val = function (val) { - // TEST WHETHER EXISTS - var it = this.find(val); - if (it.equal_to(this.end()) == true) - return 0; - // ERASE - this.erase_by_iterator(it); - return 1; + XTree.prototype.rotate_left = function (node) { + var right = node.right; + this.replace_node(node, right); + node.right = right.left; + if (right.left != null) + right.left.parent = node; + right.left = node; + node.parent = right; }; /** - * @hidden + * Rotate a node to right. + * + * @param node A node to rotate right. */ - SetContainer.prototype.erase_by_range = function (begin, end) { - // ERASE - var list_iterator = this.data_.erase(begin.get_list_iterator(), end.get_list_iterator()); - // POST-PROCESS - this.handle_erase(begin, end); - return new std.SetIterator(this, list_iterator); //begin.prev(); + XTree.prototype.rotate_right = function (node) { + var left = node.left; + this.replace_node(node, left); + node.left = left.right; + if (left.right != null) + left.right.parent = node; + left.right = node; + node.parent = left; }; - return SetContainer; - }(base.Container)); - base.SetContainer = SetContainer; - })(base = std.base || (std.base = {})); -})(std || (std = {})); -var std; -(function (std) { - /** - *An iterator of a Set.
- * - * - * - * @author Jeongho NamConstruct from source and index number.
- * - *Do not create iterator directly.
- *Use begin(), find() or end() in Map instead.
- * - * @param map The source Set to reference. - * @param index Sequence number of the element in the source Set. - */ - function SetIterator(source, it) { - _super.call(this, source); - this.list_iterator_ = it; - } - /* --------------------------------------------------------- - MOVERS - --------------------------------------------------------- */ - /** - * @inheritdoc - */ - SetIterator.prototype.prev = function () { - return new SetIterator(this.set, this.list_iterator_.prev()); - }; - /** - * @inheritdoc - */ - SetIterator.prototype.next = function () { - return new SetIterator(this.set, this.list_iterator_.next()); - }; - /** - * @inheritdoc - */ - SetIterator.prototype.advance = function (size) { - return new SetIterator(this.set, this.list_iterator_.advance(size)); - }; - Object.defineProperty(SetIterator.prototype, "set", { - /* --------------------------------------------------------- - ACCESSORS - --------------------------------------------------------- */ - /** - * @hidden - */ - get: function () { - return this.source_; - }, - enumerable: true, - configurable: true - }); - SetIterator.prototype.get_list_iterator = function () { - return this.list_iterator_; - }; - Object.defineProperty(SetIterator.prototype, "value", { /** - * @inheritdoc + * Replace a node. + * + * @param oldNode Ordinary node to be replaced. + * @param newNode Target node to replace. */ - get: function () { - return this.list_iterator_.value; - }, - enumerable: true, - configurable: true - }); - /* --------------------------------------------------------- - COMPARISONS - --------------------------------------------------------- */ - /** - * @inheritdoc - */ - SetIterator.prototype.equal_to = function (obj) { - return _super.prototype.equal_to.call(this, obj) && this.list_iterator_ == obj.list_iterator_; - }; - /** - * @inheritdoc - */ - SetIterator.prototype.less = function (obj) { - return std.less(this.value, obj.value); - }; - /** - * @inheritdoc - */ - SetIterator.prototype.hash = function () { - return std.hash(this.value); - }; - /** - * @inheritdoc - */ - SetIterator.prototype.swap = function (obj) { - this.list_iterator_.swap(obj.list_iterator_); - }; - return SetIterator; - }(std.Iterator)); - std.SetIterator = SetIterator; - /** - *A reverse-iterator of Set.
- * - * - * - * @paramAn abstract set.
- * - *{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of - * individual elements based on their value.
- * - *In an {@link SetContainer}, the value of an element is at the same time its key, used to - * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be - * modified once in the container - they can be inserted and removed, though.
- * - *{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a - * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index - * table like {@link RBTree tree} or {@link HashBuckets hash-table}.
- * - * - * - *A red-black tree storing {@link MapIterator MapIterators}.
* - * + * * * @author Jeongho NamHash buckets storing {@link SetIterator SetIterators}.
+ *A red-black Tree storing {@link SetIterator SetIterators}.
* - *
- *
- *
Return iterator to lower bound.
+ * + *Returns an iterator pointing to the first element in the container which is not considered to + * go before val (i.e., either it is equivalent or goes after).
+ * + *The function uses its internal comparison object (key_comp) to determine this, returning an + * iterator to the first element for which key_comp(element,val) would return false.
+ * + *If the {@link ITreeSet} class is instantiated with the default comparison type ({@link less}), + * the function returns an iterator to the first element that is not less than val.
+ + *A similar member function, {@link upper_bound}, has the same behavior as {@link lower_bound}, except + * in the case that the {@link ITreeSet} contains elements equivalent to val: In this case + * {@link lower_bound} returns an iterator pointing to the first of such elements, whereas + * {@link upper_bound} returns an iterator pointing to the element following the last.
+ * + * @param val Value to compare. + * + * @return An iterator to the the first element in the container which is not considered to go before + * val, or {@link ITreeSet.end} if all elements are considered to go before val. + */ + AtomicTree.prototype.lower_bound = function (val) { + var node = this.find(val); + if (node == null) + return this.set_.end(); + else if (std.equal_to(node.value.value, val)) + return node.value; + else { + var it = node.value; + while (!std.equal_to(it, this.set_.end()) && std.less(it.value, val)) + it = it.next(); + return it; + } + }; + /** + *Return iterator to upper bound.
+ * + *Returns an iterator pointing to the first element in the container which is considered to go after + * val.
+ + *The function uses its internal comparison object (key_comp) to determine this, returning an + * iterator to the first element for which key_comp(val,element) would return true.
+ + *If the {@code ITreeSet} class is instantiated with the default comparison type (less), the + * function returns an iterator to the first element that is greater than val.
+ * + *A similar member function, {@link lower_bound}, has the same behavior as {@link upper_bound}, except + * in the case that the {@ITreeSet} contains elements equivalent to val: In this case + * {@link lower_bound} returns an iterator pointing to the first of such elements, whereas + * {@link upper_bound} returns an iterator pointing to the element following the last.
+ * + * @param val Value to compare. + * + * @return An iterator to the the first element in the container which is considered to go after + * val, or {@link TreeSet.end end} if no elements are considered to go after val. + */ + AtomicTree.prototype.upper_bound = function (val) { + var node = this.find(val); + if (node == null) + return this.set_.end(); + else { + var it = node.value; + while (!std.equal_to(it, this.set_.end()) && (std.equal_to(it.value, val) || std.less(it.value, val))) + it = it.next(); + return it; + } + }; + /** + *Get range of equal elements.
+ * + *Returns the bounds of a range that includes all the elements in the container that are equivalent + * to val.
+ * + *If no matches are found, the range returned has a length of zero, with both iterators pointing to + * the first element that is considered to go after val according to the container's + * internal comparison object (key_comp).
+ * + *Two elements of a multiset are considered equivalent if the container's comparison object returns + * false reflexively (i.e., no matter the order in which the elements are passed as arguments).
+ * + * @param key Value to search for. + * + * @return The function returns a {@link Pair}, whose member {@link Pair.first} is the lower bound of + * the range (the same as {@link lower_bound}), and {@link Pair.second} is the upper bound + * (the same as {@link upper_bound}). + */ + AtomicTree.prototype.equal_range = function (val) { + return std.make_pair(this.lower_bound(val), this.upper_bound(val)); + }; + /* --------------------------------------------------------- + COMPARISON + --------------------------------------------------------- */ + /** + *Return comparison function.
+ * + *Returns a copy of the comparison function used by the container.
+ * + *By default, this is a {@link less} object, which returns the same as operator<.
+ * + * This object determines the order of the elements in the container: it is a function pointer or a function
+ * object that takes two arguments of the same type as the container elements, and returns true
if
+ * the first argument is considered to go before the second in the strict weak ordering it
+ * defines, and false
otherwise.
Two elements of a {@link ITreeSet} are considered equivalent if {@link key_comp} returns false
+ * reflexively (i.e., no matter the order in which the elements are passed as arguments).
In {@link ITreeSet} containers, the keys to sort the elements are the values (T) themselves, + * therefore {@link key_comp} and its sibling member function {@link value_comp} are equivalent.
+ * + * @return The comparison function. + */ + AtomicTree.prototype.key_comp = function () { + return this.compare_; + }; + /** + *Return comparison function.
+ * + *Returns a copy of the comparison function used by the container.
+ * + *By default, this is a {@link less} object, which returns the same as operator<.
+ * + * This object determines the order of the elements in the container: it is a function pointer or a function
+ * object that takes two arguments of the same type as the container elements, and returns true
if
+ * the first argument is considered to go before the second in the strict weak ordering it
+ * defines, and false
otherwise.
Two elements of a {@link ITreeSet} are considered equivalent if {@link key_comp} returns false
+ * reflexively (i.e., no matter the order in which the elements are passed as arguments).
In {@link ITreeSet} containers, the keys to sort the elements are the values (T) themselves, + * therefore {@link key_comp} and its sibling member function {@link value_comp} are equivalent.
+ * + * @return The comparison function. + */ + AtomicTree.prototype.value_comp = function () { + return this.compare_; + }; + /** + * @inheritdoc + */ + AtomicTree.prototype.is_equal_to = function (left, right) { + return std.equal_to(left, right); + }; + /** + * @inheritdoc + */ + AtomicTree.prototype.is_less = function (left, right) { + return this.compare_(left.value, right.value); + }; + return AtomicTree; + }(base.XTree)); + base.AtomicTree = AtomicTree; })(base = std.base || (std.base = {})); })(std || (std = {})); ///
- *
+ *
+ *
*
Row size of the {@link matrix_ matrix} which contains elements.
- * - *Note that the {@link ROW} affects on time complexity of accessing and inserting element. - * Accessing element is {@link ROW} times slower than ordinary {@link Vector} and inserting element - * in middle position is {@link ROW} times faster than ordinary {@link Vector}.
- * - *When the {@link ROW} returns 8, time complexity of accessing element is O(8) and inserting - * element in middle position is O(N/8). ({@link Vector}'s time complexity of accessement is O(1) - * and inserting element is O(N)).
+ * @hidden */ get: function () { return 8; }, enumerable: true, configurable: true }); Object.defineProperty(Deque, "MIN_CAPACITY", { + /// + // Minimum {@link capacity}. + // + // Although a {@link Deque} has few elements, even no element is belonged to, the {@link Deque} + // keeps the minimum {@link capacity} at least. /** - *Minimum {@link capacity}.
- * - *Although a {@link Deque} has few elements, even no element is belonged to, the {@link Deque} - * keeps the minimum {@link capacity} at least.
+ * @hidden */ get: function () { return 100; }, enumerable: true, configurable: true }); + // Get column size; {@link capacity_ capacity} / {@link ROW row}. /** - * Get column size; {@link capacity_ capacity} / {@link ROW row}. + * @hidden */ Deque.prototype.get_col_size = function () { return Math.floor(this.capacity_ / Deque.ROW); @@ -5836,8 +5841,8 @@ var std; /** *An iterator of {@link Deque}.
* - *
- *
+ *
+ *
*
A reverse-iterator of Deque.
* - *
- *
+ *
+ *
*
- *
+ *
+ *
*
An iterator, node of a List.
* - *
- *
+ *
+ *
*
A reverse-iterator of List.
* - *
- *
+ *
+ *
*
All objects thrown by components of the standard library are derived from this class. * Therefore, all standard exceptions can be caught by catching this type by reference.
* - * + * * * @reference http://www.cplusplus.com/reference/exception/exception * @author Jeongho NamIt is used as a base class for several logical error exceptions.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/logic_error * @author Jeongho NamNo component of the standard library throws exceptions of this type. It is designed as a standard * exception to be thrown by programs.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/domain_error * @author Jeongho NamIt is a standard exception that can be thrown by programs. Some components of the standard library * also throw exceptions of this type to signal invalid arguments.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/invalid_argument * @author Jeongho NamIt is a standard exception that can be thrown by programs. Some components of the standard library, * such as vector and string also throw exceptions of this type to signal errors resizing.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/length_error * @author Jeongho NamIt is used as a base class for several runtime error exceptions.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/runtime_error * @author Jeongho NamIt is a standard exception that can be thrown by programs. Some components of the standard library * also throw exceptions of this type to signal range errors.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/overflow_error * @author Jeongho NamNo component of the standard library throws exceptions of this type. It is designed as a standard * exception to be thrown by programs.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/underflow_error * @author Jeongho NamIt is a standard exception that can be thrown by programs. Some components of the standard library * also throw exceptions of this type to signal range errors.
* - * + * * * @reference http://www.cplusplus.com/reference/stdexcept/range_error * @author Jeongho Nam{@link HashMap} containers are faster than {@link TreeMap} containers to access individual elements by their * key, although they are generally less efficient for range iteration through a subset of their elements.
* - *
- *
+ *
+ *
*
Elements with equivalent keys are grouped together in the same bucket and in such a way that * an iterator can iterate through all of them. Iterators in the container are doubly linked iterators.
* - *
- *
+ *
+ *
*
Hashed, unordered set.
- * - *{@link HashSet}s are containers that store unique elements in no particular order, and which - * allow for fast retrieval of individual elements based on their value.
+ *Hashed, unordered Multiset.
* - *In an {@link HashSet}, the value of an element is at the same time its key, that - * identifies it uniquely. Keys are immutable, therefore, the elements in an {@link HashSet} cannot be + *
{@link HashMultiSet HashMultiSets} are containers that store elements in no particular order, allowing fast + * retrieval of individual elements based on their value, much like {@link HashSet} containers, + * but allowing different elements to have equivalent values.
+ * + *In an {@link HashMultiSet}, the value of an element is at the same time its key, used to + * identify it. Keys are immutable, therefore, the elements in an {@link HashMultiSet} cannot be * modified once in the container - they can be inserted and removed, though.
* - *Internally, the elements in the {@link HashSet} are not sorted in any particular order, but - * organized into buckets depending on their hash values to allow for fast access to individual elements - * directly by their values (with a constant average time complexity on average).
+ *Internally, the elements in the {@link HashMultiSet} are not sorted in any particular, but + * organized into buckets depending on their hash values to allow for fast access to individual + * elements directly by their values (with a constant average time complexity on average).
* - *{@link HashSet} containers are faster than {@link TreeSet} containers to access individual - * elements by their key, although they are generally less efficient for range iteration through a - * subset of their elements.
+ *Elements with equivalent values are grouped together in the same bucket and in such a way that an + * iterator can iterate through all of them. Iterators in the container are doubly linked iterators.
* - * + * * *Hashed, unordered Multiset.
+ *Hashed, unordered set.
* - *{@link HashMultiSet HashMultiSets} are containers that store elements in no particular order, allowing fast - * retrieval of individual elements based on their value, much like {@link HashSet} containers, - * but allowing different elements to have equivalent values.
+ *{@link HashSet}s are containers that store unique elements in no particular order, and which + * allow for fast retrieval of individual elements based on their value.
* - *In an {@link HashMultiSet}, the value of an element is at the same time its key, used to - * identify it. Keys are immutable, therefore, the elements in an {@link HashMultiSet} cannot be + *
In an {@link HashSet}, the value of an element is at the same time its key, that + * identifies it uniquely. Keys are immutable, therefore, the elements in an {@link HashSet} cannot be * modified once in the container - they can be inserted and removed, though.
* - *Internally, the elements in the {@link HashMultiSet} are not sorted in any particular, but - * organized into buckets depending on their hash values to allow for fast access to individual - * elements directly by their values (with a constant average time complexity on average).
+ *Internally, the elements in the {@link HashSet} are not sorted in any particular order, but + * organized into buckets depending on their hash values to allow for fast access to individual elements + * directly by their values (with a constant average time complexity on average).
* - *Elements with equivalent values are grouped together in the same bucket and in such a way that an - * iterator can iterate through all of them. Iterators in the container are doubly linked iterators.
+ *{@link HashSet} containers are faster than {@link TreeSet} containers to access individual + * elements by their key, although they are generally less efficient for range iteration through a + * subset of their elements.
* - * + * * *
- * An iterator of Vector.
- * A reverse-iterator of Vector.
- *
+ *
- *
+ * {@link TreeSet}s are typically implemented as binary search trees. Tree-structured map, {@link TreeMap TreeMaps} are associative containers that store elements formed by a combination of a
+ * key value (Key) and a mapped value (T), following order. In a {@link TreeMap}, the key values are generally used to sort and uniquely identify the elements,
+ * while the mapped values store the content associated to this key. The types of key and
+ * mapped value may differ, and are grouped together in member type value_type, which is a {@link Pair}
+ * type combining both: Internally, the elements in a {@link TreeMap} are always sorted by its key following a
+ * strict weak ordering criterion indicated by its internal comparison method {@link less}.
+ *
+ * {@link TreeMap} containers are generally slower than {@link HashMap HashMap} containers to access individual
+ * elements by their key, but they allow the direct iteration on subsets based on their order. {@link TreeMap}s are typically implemented as binary search trees. {@link TreeMultiSet TreeMultiSets} are typically implemented as binary search trees. Tree-structured map, {@link TreeMap TreeMaps} are associative containers that store elements formed by a combination of a
- * key value (Key) and a mapped value (T), following order. In a {@link TreeMap}, the key values are generally used to sort and uniquely identify the elements,
- * while the mapped values store the content associated to this key. The types of key and
- * mapped value may differ, and are grouped together in member type value_type, which is a {@link Pair}
- * type combining both: Internally, the elements in a {@link TreeMap} are always sorted by its key following a
- * strict weak ordering criterion indicated by its internal comparison method {@link less}.
- *
- * {@link TreeMap} containers are generally slower than {@link HashMap HashMap} containers to access individual
- * elements by their key, but they allow the direct iteration on subsets based on their order. {@link TreeMap}s are typically implemented as binary search trees. Tree-structured multiple-key map. {@link TreeMultiMap TreeMultiMaps} are typically implemented as binary search trees. The class inherits from {@link RuntimeError}, to which it adds an {@link ErrorCode} as
* member code (and defines a specialized what member).
+ *
*
*
Container properties
@@ -9180,8 +9194,8 @@ var std;
/**
*
+ *
*
* @param
+ *
*
+ *
*
Container properties
*
@@ -10081,15 +10094,263 @@ var std;
/**
* @hidden
*/
- TreeSet.prototype.swap_tree_set = function (obj) {
+ TreeSet.prototype.swap_tree_set = function (obj) {
+ _a = [obj.data_, this.data_], this.data_ = _a[0], obj.data_ = _a[1];
+ _b = [obj.tree_, this.tree_], this.tree_ = _b[0], obj.tree_ = _b[1];
+ var _a, _b;
+ };
+ return TreeSet;
+ }(std.base.UniqueSet));
+ std.TreeSet = TreeSet;
+})(std || (std = {}));
+///
std::map
of STL. typedef Pair
Container properties
+ *
+ *
+ *
+ * @param Container properties
*
@@ -10351,253 +10612,8 @@ var std;
std.TreeMultiSet = TreeMultiSet;
})(std || (std = {}));
///
std::map
of STL. typedef Pair
Container properties
- *
- *
- *
- * @param Container properties
*
@@ -10877,8 +10893,8 @@ var std;
*