diff --git a/src/main/java/baritone/builder/utils/com/github/btrekkie/README.md b/src/main/java/baritone/builder/utils/com/github/btrekkie/README.md
index fc8e9ce94..a8428f292 100644
--- a/src/main/java/baritone/builder/utils/com/github/btrekkie/README.md
+++ b/src/main/java/baritone/builder/utils/com/github/btrekkie/README.md
@@ -8,4 +8,8 @@ This code in this folder was written under the MIT license (see the LICENSE file
per https://directory.fsf.org/wiki/License:Expat https://www.gnu.org/licenses/license-list.en.html#Expat
The new license for this modified version (the combined work including my modifications) is still the Baritone license,
-which is LGPL.
\ No newline at end of file
+which is LGPL.
+
+The git histories of both repos https://github.com/btrekkie/dynamic-connectivity/ and its
+dependency https://github.com/btrekkie/RedBlackNode/ have been included by using git's "merge unrelated histories"
+feature, so the git blame is accurate for giving credit, I think.
diff --git a/src/main/java/com/github/btrekkie/red_black_node/RedBlackNode.java b/src/main/java/baritone/builder/utils/com/github/btrekkie/red_black_node/RedBlackNode.java
similarity index 93%
rename from src/main/java/com/github/btrekkie/red_black_node/RedBlackNode.java
rename to src/main/java/baritone/builder/utils/com/github/btrekkie/red_black_node/RedBlackNode.java
index 7777b7361..b495f6f9d 100644
--- a/src/main/java/com/github/btrekkie/red_black_node/RedBlackNode.java
+++ b/src/main/java/baritone/builder/utils/com/github/btrekkie/red_black_node/RedBlackNode.java
@@ -1,11 +1,12 @@
-package com.github.btrekkie.red_black_node;
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
+package baritone.builder.utils.com.github.btrekkie.red_black_node;
import java.lang.reflect.Array;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
+import java.util.*;
/**
* A node in a red-black tree ( https://en.wikipedia.org/wiki/Red%E2%80%93black_tree ). Compared to a class like Java's
@@ -13,20 +14,20 @@ import java.util.Set;
* clients to directly observe and manipulate the structure of the tree. This gives clients flexibility, although it
* also enables them to violate the red-black or BST properties. The RedBlackNode class provides methods for performing
* various standard operations, such as insertion and removal.
- *
+ *
* Unlike most implementations of binary search trees, RedBlackNode supports arbitrary augmentation. By subclassing
* RedBlackNode, clients can add arbitrary data and augmentation information to each node. For example, if we were to
* use a RedBlackNode subclass to implement a sorted set, the subclass would have a field storing an element in the set.
* If we wanted to keep track of the number of non-leaf nodes in each subtree, we would store this as a "size" field and
* override augment() to update this field. All RedBlackNode methods (such as "insert" and remove()) call augment() as
* necessary to correctly maintain the augmentation information, unless otherwise indicated.
- *
+ *
* The values of the tree are stored in the non-leaf nodes. RedBlackNode does not support use cases where values must be
* stored in the leaf nodes. It is recommended that all of the leaf nodes in a given tree be the same (black)
* RedBlackNode instance, to save space. The root of an empty tree is a leaf node, as opposed to null.
- *
+ *
* For reference, a red-black tree is a binary search tree satisfying the following properties:
- *
+ *
* - Every node is colored red or black.
* - The leaf nodes, which are dummy nodes that do not store any values, are colored black.
* - The root is black.
@@ -34,11 +35,13 @@ import java.util.Set;
* - Every path from the root to a leaf contains the same number of black nodes.
*
* @param The type of node in the tree. For example, we might have
- * "class FooNode extends RedBlackNode>".
+ * "class FooNode extends RedBlackNode>".
* @author Bill Jacobs
*/
public abstract class RedBlackNode> implements Comparable {
- /** A Comparator that compares Comparable elements using their natural order. */
+ /**
+ * A Comparator that compares Comparable elements using their natural order.
+ */
private static final Comparator> NATURAL_ORDER = new Comparator>() {
@Override
public int compare(Comparable value1, Comparable value2) {
@@ -46,16 +49,24 @@ public abstract class RedBlackNode> implements Compara
}
};
- /** The parent of this node, if any. "parent" is null if this is a leaf node. */
+ /**
+ * The parent of this node, if any. "parent" is null if this is a leaf node.
+ */
public N parent;
- /** The left child of this node. "left" is null if this is a leaf node. */
+ /**
+ * The left child of this node. "left" is null if this is a leaf node.
+ */
public N left;
- /** The right child of this node. "right" is null if this is a leaf node. */
+ /**
+ * The right child of this node. "right" is null if this is a leaf node.
+ */
public N right;
- /** Whether the node is colored red, as opposed to black. */
+ /**
+ * Whether the node is colored red, as opposed to black.
+ */
public boolean isRed;
/**
@@ -63,12 +74,12 @@ public abstract class RedBlackNode> implements Compara
* example, if we augment each node by subtree size (the number of non-leaf nodes in the subtree), this method would
* set the size field of this node to be equal to the size field of the left child plus the size field of the right
* child plus one.
- *
+ *
* "Augmentation information" is information that we can compute about a subtree rooted at some node, preferably
* based only on the augmentation information in the node's two children and the information in the node. Examples
* of augmentation information are the sum of the values in a subtree and the number of non-leaf nodes in a subtree.
* Augmentation information may not depend on the colors of the nodes.
- *
+ *
* This method returns whether the augmentation information in any of the ancestors of this node might have been
* affected by changes in this subtree since the last call to augment(). In the usual case, where the augmentation
* information depends only on the information in this node and the augmentation information in its immediate
@@ -77,7 +88,7 @@ public abstract class RedBlackNode> implements Compara
* calling augment() differed from the size field of the left child plus the size field of the right child plus one.
* False positives are permitted. The return value is unspecified if we have not called augment() on this node
* before.
- *
+ *
* This method may assume that this is not a leaf node. It may not assume that the augmentation information stored
* in any of the tree's nodes is correct. However, if the augmentation information stored in all of the node's
* descendants is correct, then the augmentation information stored in this node must be correct after calling
@@ -92,7 +103,7 @@ public abstract class RedBlackNode> implements Compara
* of RedBlackNode. For example, if this stores the size of the subtree rooted at this node, this should throw a
* RuntimeException if the size field of this is not equal to the size field of the left child plus the size field
* of the right child plus one. Note that we may call this on a leaf node.
- *
+ *
* assertSubtreeIsValid() calls assertNodeIsValid() on each node, or at least starts to do so until it detects a
* problem. assertNodeIsValid() should assume the node is in a tree that satisfies all properties common to all
* red-black trees, as assertSubtreeIsValid() is responsible for such checks. assertNodeIsValid() should be
@@ -105,58 +116,68 @@ public abstract class RedBlackNode> implements Compara
}
- /** Returns whether this is a leaf node. */
+ /**
+ * Returns whether this is a leaf node.
+ */
public boolean isLeaf() {
return left == null;
}
- /** Returns the root of the tree that contains this node. */
+ /**
+ * Returns the root of the tree that contains this node.
+ */
public N root() {
@SuppressWarnings("unchecked")
- N node = (N)this;
+ N node = (N) this;
while (node.parent != null) {
node = node.parent;
}
return node;
}
- /** Returns the first node in the subtree rooted at this node, if any. */
+ /**
+ * Returns the first node in the subtree rooted at this node, if any.
+ */
public N min() {
if (isLeaf()) {
return null;
}
@SuppressWarnings("unchecked")
- N node = (N)this;
+ N node = (N) this;
while (!node.left.isLeaf()) {
node = node.left;
}
return node;
}
- /** Returns the last node in the subtree rooted at this node, if any. */
+ /**
+ * Returns the last node in the subtree rooted at this node, if any.
+ */
public N max() {
if (isLeaf()) {
return null;
}
@SuppressWarnings("unchecked")
- N node = (N)this;
+ N node = (N) this;
while (!node.right.isLeaf()) {
node = node.right;
}
return node;
}
- /** Returns the node immediately before this in the tree that contains this node, if any. */
+ /**
+ * Returns the node immediately before this in the tree that contains this node, if any.
+ */
public N predecessor() {
if (!left.isLeaf()) {
N node;
- for (node = left; !node.right.isLeaf(); node = node.right);
+ for (node = left; !node.right.isLeaf(); node = node.right) ;
return node;
} else if (parent == null) {
return null;
} else {
@SuppressWarnings("unchecked")
- N node = (N)this;
+ N node = (N) this;
while (node.parent != null && node.parent.left == node) {
node = node.parent;
}
@@ -164,17 +185,19 @@ public abstract class RedBlackNode> implements Compara
}
}
- /** Returns the node immediately after this in the tree that contains this node, if any. */
+ /**
+ * Returns the node immediately after this in the tree that contains this node, if any.
+ */
public N successor() {
if (!right.isLeaf()) {
N node;
- for (node = right; !node.left.isLeaf(); node = node.left);
+ for (node = right; !node.left.isLeaf(); node = node.left) ;
return node;
} else if (parent == null) {
return null;
} else {
@SuppressWarnings("unchecked")
- N node = (N)this;
+ N node = (N) this;
while (node.parent != null && node.parent.right == node) {
node = node.parent;
}
@@ -186,6 +209,7 @@ public abstract class RedBlackNode> implements Compara
* Performs a left rotation about this node. This method assumes that !isLeaf() && !right.isLeaf(). It calls
* augment() on this node and on its resulting parent. However, it does not call augment() on any of the resulting
* parent's ancestors, because that is normally the responsibility of the caller.
+ *
* @return The return value from calling augment() on the resulting parent.
*/
public boolean rotateLeft() {
@@ -195,7 +219,7 @@ public abstract class RedBlackNode> implements Compara
N newParent = right;
right = newParent.left;
@SuppressWarnings("unchecked")
- N nThis = (N)this;
+ N nThis = (N) this;
if (!right.isLeaf()) {
right.parent = nThis;
}
@@ -217,6 +241,7 @@ public abstract class RedBlackNode> implements Compara
* Performs a right rotation about this node. This method assumes that !isLeaf() && !left.isLeaf(). It calls
* augment() on this node and on its resulting parent. However, it does not call augment() on any of the resulting
* parent's ancestors, because that is normally the responsibility of the caller.
+ *
* @return The return value from calling augment() on the resulting parent.
*/
public boolean rotateRight() {
@@ -226,7 +251,7 @@ public abstract class RedBlackNode> implements Compara
N newParent = left;
left = newParent.right;
@SuppressWarnings("unchecked")
- N nThis = (N)this;
+ N nThis = (N) this;
if (!left.isLeaf()) {
left.parent = nThis;
}
@@ -250,6 +275,7 @@ public abstract class RedBlackNode> implements Compara
* red. node.isRed must initially be true. This method assumes that this is not a leaf node. The method performs
* any rotations by calling rotateLeft() and rotateRight(). This method is more efficient than fixInsertion if
* "augment" is false or augment() might return false.
+ *
* @param augment Whether to set the augmentation information for "node" and its ancestors, by calling augment().
*/
public void fixInsertionWithoutGettingRoot(boolean augment) {
@@ -337,6 +363,7 @@ public abstract class RedBlackNode> implements Compara
* of red-black trees, except that this may be a red child of a red node, and if this is the root, the root may be
* red. node.isRed must initially be true. This method assumes that this is not a leaf node. The method performs
* any rotations by calling rotateLeft() and rotateRight().
+ *
* @param augment Whether to set the augmentation information for "node" and its ancestors, by calling augment().
* @return The root of the resulting tree.
*/
@@ -350,6 +377,7 @@ public abstract class RedBlackNode> implements Compara
* of red-black trees, except that this may be a red child of a red node, and if this is the root, the root may be
* red. node.isRed must initially be true. This method assumes that this is not a leaf node. The method performs
* any rotations by calling rotateLeft() and rotateRight().
+ *
* @return The root of the resulting tree.
*/
public N fixInsertion() {
@@ -357,27 +385,29 @@ public abstract class RedBlackNode> implements Compara
return root();
}
- /** Returns a Comparator that compares instances of N using their natural order, as in N.compareTo. */
+ /**
+ * Returns a Comparator that compares instances of N using their natural order, as in N.compareTo.
+ */
@SuppressWarnings({"rawtypes", "unchecked"})
private Comparator naturalOrder() {
- Comparator comparator = (Comparator)NATURAL_ORDER;
- return (Comparator)comparator;
+ Comparator comparator = (Comparator) NATURAL_ORDER;
+ return (Comparator) comparator;
}
/**
* Inserts the specified node into the tree rooted at this node. Assumes this is the root. We treat newNode as a
* solitary node that does not belong to any tree, and we ignore its initial "parent", "left", "right", and isRed
* fields.
- *
+ *
* If it is not efficient or convenient to find the location for a node using a Comparator, then you should manually
* add the node to the appropriate location, color it red, and call fixInsertion().
*
- * @param newNode The node to insert.
+ * @param newNode The node to insert.
* @param allowDuplicates Whether to insert newNode if there is an equal node in the tree. To check whether we
- * inserted newNode, check whether newNode.parent is null and the return value differs from newNode.
- * @param comparator A comparator indicating where to put the node. If this is null, we use the nodes' natural
- * order, as in N.compareTo. If you are passing null, then you must override the compareTo method, because the
- * default implementation requires the nodes to already be in the same tree.
+ * inserted newNode, check whether newNode.parent is null and the return value differs from newNode.
+ * @param comparator A comparator indicating where to put the node. If this is null, we use the nodes' natural
+ * order, as in N.compareTo. If you are passing null, then you must override the compareTo method, because the
+ * default implementation requires the nodes to already be in the same tree.
* @return The root of the resulting tree.
*/
public N insert(N newNode, boolean allowDuplicates, Comparator super N> comparator) {
@@ -385,7 +415,7 @@ public abstract class RedBlackNode> implements Compara
throw new IllegalArgumentException("This is not the root of a tree");
}
@SuppressWarnings("unchecked")
- N nThis = (N)this;
+ N nThis = (N) this;
if (isLeaf()) {
newNode.isRed = false;
newNode.left = nThis;
@@ -434,6 +464,7 @@ public abstract class RedBlackNode> implements Compara
/**
* Moves this node to its successor's former position in the tree and vice versa, i.e. sets the "left", "right",
* "parent", and isRed fields of each. This method assumes that this is not a leaf node.
+ *
* @return The node with which we swapped.
*/
private N swapWithSuccessor() {
@@ -456,7 +487,7 @@ public abstract class RedBlackNode> implements Compara
}
@SuppressWarnings("unchecked")
- N nThis = (N)this;
+ N nThis = (N) this;
isRed = oldReplacementIsRed;
left = oldReplacementLeft;
right = oldReplacementRight;
@@ -573,7 +604,7 @@ public abstract class RedBlackNode> implements Compara
* Removes this node from the tree that contains it. The effect of this method on the fields of this node is
* unspecified. This method assumes that this is not a leaf node. This method is more efficient than remove() if
* augment() might return false.
- *
+ *
* If the node has two children, we begin by moving the node's successor to its former position, by changing the
* successor's "left", "right", "parent", and isRed fields.
*/
@@ -663,7 +694,7 @@ public abstract class RedBlackNode> implements Compara
/**
* Removes this node from the tree that contains it. The effect of this method on the fields of this node is
* unspecified. This method assumes that this is not a leaf node.
- *
+ *
* If the node has two children, we begin by moving the node's successor to its former position, by changing the
* successor's "left", "right", "parent", and isRed fields.
*
@@ -695,13 +726,14 @@ public abstract class RedBlackNode> implements Compara
* "iterator", in iteration order. This method is responsible for setting the "left", "right", "parent", and isRed
* fields of the nodes, and calling augment() as appropriate. It ignores the initial values of the "left", "right",
* "parent", and isRed fields.
+ *
* @param iterator The nodes.
- * @param size The number of nodes.
- * @param height The "height" of the subtree's root node above the deepest leaf in the tree that contains it. Since
- * insertion fixup is slow if there are too many red nodes and deleteion fixup is slow if there are too few red
- * nodes, we compromise and have red nodes at every fourth level. We color a node red iff its "height" is equal
- * to 1 mod 4.
- * @param leaf The leaf node.
+ * @param size The number of nodes.
+ * @param height The "height" of the subtree's root node above the deepest leaf in the tree that contains it. Since
+ * insertion fixup is slow if there are too many red nodes and deleteion fixup is slow if there are too few red
+ * nodes, we compromise and have red nodes at every fourth level. We color a node red iff its "height" is equal
+ * to 1 mod 4.
+ * @param leaf The leaf node.
* @return The root of the subtree.
*/
private static > N createTree(
@@ -733,8 +765,9 @@ public abstract class RedBlackNode> implements Compara
* method is responsible for setting the "left", "right", "parent", and isRed fields of the nodes (excluding
* "leaf"), and calling augment() as appropriate. It ignores the initial values of the "left", "right", "parent",
* and isRed fields.
+ *
* @param nodes The nodes.
- * @param leaf The leaf node.
+ * @param leaf The leaf node.
* @return The root of the tree.
*/
public static > N createTree(Collection extends N> nodes, N leaf) {
@@ -760,7 +793,7 @@ public abstract class RedBlackNode> implements Compara
* all of these nodes. This method destroys the trees rooted at "this" and "last". We treat "pivot" as a solitary
* node that does not belong to any tree, and we ignore its initial "parent", "left", "right", and isRed fields.
* This method assumes that this node and "last" are the roots of their respective trees.
- *
+ *
* This method takes O(log N) time. It is more efficient than inserting "pivot" and then calling concatenate(last).
* It is considerably more efficient than inserting "pivot" and all of the nodes in "last".
*/
@@ -781,7 +814,7 @@ public abstract class RedBlackNode> implements Compara
// Compute the black height of the trees
int firstBlackHeight = 0;
@SuppressWarnings("unchecked")
- N first = (N)this;
+ N first = (N) this;
for (N node = first; node != null; node = node.right) {
if (!node.isRed) {
firstBlackHeight++;
@@ -866,7 +899,7 @@ public abstract class RedBlackNode> implements Compara
return last;
} else if (last.isLeaf()) {
@SuppressWarnings("unchecked")
- N nThis = (N)this;
+ N nThis = (N) this;
return nThis;
} else {
N node = last.min();
@@ -882,6 +915,7 @@ public abstract class RedBlackNode> implements Compara
* destructive, meaning it does not preserve the original tree. It assumes that this node is the root and is in the
* same tree as splitNode. It takes O(log N) time. It is considerably more efficient than removing all of the
* nodes at or after splitNode and then creating a new tree from those nodes.
+ *
* @param The node at which to split the tree.
* @return An array consisting of the resulting trees.
*/
@@ -927,7 +961,7 @@ public abstract class RedBlackNode> implements Compara
}
@SuppressWarnings("unchecked")
- N node = (N)this;
+ N node = (N) this;
N first = null;
N firstParent = null;
N last = null;
@@ -1080,7 +1114,7 @@ public abstract class RedBlackNode> implements Compara
last.augment();
@SuppressWarnings("unchecked")
- N[] result = (N[])Array.newInstance(getClass(), 2);
+ N[] result = (N[]) Array.newInstance(getClass(), 2);
result[0] = first;
result[1] = last;
return result;
@@ -1090,7 +1124,7 @@ public abstract class RedBlackNode> implements Compara
* Returns the lowest common ancestor of this node and "other" - the node that is an ancestor of both and is not the
* parent of a node that is an ancestor of both. Assumes that this is in the same tree as "other". Assumes that
* neither "this" nor "other" is a leaf node. This method may return "this" or "other".
- *
+ *
* Note that while it is possible to compute the lowest common ancestor in O(P) time, where P is the length of the
* path from this node to "other", the "lca" method is not guaranteed to take O(P) time. If your application
* requires this, then you should write your own lowest common ancestor method.
@@ -1112,7 +1146,7 @@ public abstract class RedBlackNode> implements Compara
// Go up to nodes of the same depth
@SuppressWarnings("unchecked")
- N parent = (N)this;
+ N parent = (N) this;
N otherParent = other;
if (depth <= otherDepth) {
for (int i = otherDepth; i > depth; i--) {
@@ -1140,10 +1174,10 @@ public abstract class RedBlackNode> implements Compara
* Returns an integer comparing the position of this node in the tree that contains it with that of "other". Returns
* a negative number if this is earlier, a positive number if this is later, and 0 if this is at the same position.
* Assumes that this is in the same tree as "other". Assumes that neither "this" nor "other" is a leaf node.
- *
+ *
* The base class's implementation takes O(log N) time. If a RedBlackNode subclass stores a value used to order the
* nodes, then it could override compareTo to compare the nodes' values, which would take O(1) time.
- *
+ *
* Note that while it is possible to compare the positions of two nodes in O(P) time, where P is the length of the
* path from this node to "other", the default implementation of compareTo is not guaranteed to take O(P) time. If
* your application requires this, then you should write your own comparison method.
@@ -1222,7 +1256,9 @@ public abstract class RedBlackNode> implements Compara
}
}
- /** Throws a RuntimeException if the RedBlackNode fields of this are not correct for a leaf node. */
+ /**
+ * Throws a RuntimeException if the RedBlackNode fields of this are not correct for a leaf node.
+ */
private void assertIsValidLeaf() {
if (left != null || right != null || parent != null || isRed) {
throw new RuntimeException("A leaf node's \"left\", \"right\", \"parent\", or isRed field is incorrect");
@@ -1232,14 +1268,15 @@ public abstract class RedBlackNode> implements Compara
/**
* Throws a RuntimeException if the subtree rooted at this node does not satisfy the red-black properties, excluding
* the requirement that the root be black, or it contains a repeated node other than a leaf node.
+ *
* @param blackHeight The required number of black nodes in each path from this to a leaf node, including this and
- * the leaf node.
- * @param visited The nodes we have reached thus far, other than leaf nodes. This method adds the non-leaf nodes in
- * the subtree rooted at this node to "visited".
+ * the leaf node.
+ * @param visited The nodes we have reached thus far, other than leaf nodes. This method adds the non-leaf nodes in
+ * the subtree rooted at this node to "visited".
*/
private void assertSubtreeIsValidRedBlack(int blackHeight, Set> visited) {
@SuppressWarnings("unchecked")
- N nThis = (N)this;
+ N nThis = (N) this;
if (left == null || right == null) {
assertIsValidLeaf();
if (blackHeight != 1) {
@@ -1274,7 +1311,9 @@ public abstract class RedBlackNode> implements Compara
}
}
- /** Calls assertNodeIsValid() on every node in the subtree rooted at this node. */
+ /**
+ * Calls assertNodeIsValid() on every node in the subtree rooted at this node.
+ */
private void assertNodesAreValid() {
assertNodeIsValid();
if (left != null) {
@@ -1302,7 +1341,7 @@ public abstract class RedBlackNode> implements Compara
Set> nodes = new HashSet>();
int blackHeight = 0;
@SuppressWarnings("unchecked")
- N node = (N)this;
+ N node = (N) this;
while (node != null) {
if (!nodes.add(new Reference(node))) {
throw new RuntimeException("The tree contains a repeated non-leaf node");
@@ -1331,14 +1370,15 @@ public abstract class RedBlackNode> implements Compara
* Throws a RuntimeException if the nodes in the subtree rooted at this node are not in the specified order or they
* do not lie in the specified range. Assumes that the subtree rooted at this node is a valid binary tree, i.e. it
* has no repeated nodes other than leaf nodes.
+ *
* @param comparator A comparator indicating how the nodes should be ordered.
- * @param start The lower limit for nodes in the subtree, if any.
- * @param end The upper limit for nodes in the subtree, if any.
+ * @param start The lower limit for nodes in the subtree, if any.
+ * @param end The upper limit for nodes in the subtree, if any.
*/
private void assertOrderIsValid(Comparator super N> comparator, N start, N end) {
if (!isLeaf()) {
@SuppressWarnings("unchecked")
- N nThis = (N)this;
+ N nThis = (N) this;
if (start != null && comparator.compare(nThis, start) < 0) {
throw new RuntimeException("The nodes are not ordered correctly");
}
@@ -1357,8 +1397,9 @@ public abstract class RedBlackNode> implements Compara
* Assumes that this is a valid binary tree, i.e. there are no repeated nodes other than leaf nodes. This method is
* useful for debugging. RedBlackNode subclasses may want to override assertSubtreeIsValid() to call
* assertOrderIsValid.
+ *
* @param comparator A comparator indicating how the nodes should be ordered. If this is null, we use the nodes'
- * natural order, as in N.compareTo.
+ * natural order, as in N.compareTo.
*/
public void assertOrderIsValid(Comparator super N> comparator) {
if (comparator == null) {
diff --git a/src/main/java/com/github/btrekkie/red_black_node/Reference.java b/src/main/java/baritone/builder/utils/com/github/btrekkie/red_black_node/Reference.java
similarity index 61%
rename from src/main/java/com/github/btrekkie/red_black_node/Reference.java
rename to src/main/java/baritone/builder/utils/com/github/btrekkie/red_black_node/Reference.java
index 843053820..10e8caa67 100644
--- a/src/main/java/com/github/btrekkie/red_black_node/Reference.java
+++ b/src/main/java/baritone/builder/utils/com/github/btrekkie/red_black_node/Reference.java
@@ -1,12 +1,20 @@
-package com.github.btrekkie.red_black_node;
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
+package baritone.builder.utils.com.github.btrekkie.red_black_node;
/**
* Wraps a value using reference equality. In other words, two references are equal only if their values are the same
* object instance, as in ==.
+ *
* @param The type of value.
*/
class Reference {
- /** The value this wraps. */
+ /**
+ * The value this wraps.
+ */
private final T value;
public Reference(T value) {
@@ -17,7 +25,7 @@ class Reference {
if (!(obj instanceof Reference)) {
return false;
}
- Reference> reference = (Reference>)obj;
+ Reference> reference = (Reference>) obj;
return value == reference.value;
}
diff --git a/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderCollection.java b/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderCollection.java
index 8b5102471..298040ef1 100644
--- a/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderCollection.java
+++ b/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderCollection.java
@@ -1,3 +1,8 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.arbitrary_order_collection;
import java.util.Comparator;
@@ -11,7 +16,9 @@ import java.util.Comparator;
/* We implement an ArbitraryOrderCollection using a red-black tree. We order the nodes arbitrarily.
*/
public class ArbitraryOrderCollection {
- /** The Comparator for ordering ArbitraryOrderNodes. */
+ /**
+ * The Comparator for ordering ArbitraryOrderNodes.
+ */
private static final Comparator NODE_COMPARATOR = new Comparator() {
@Override
public int compare(ArbitraryOrderNode node1, ArbitraryOrderNode node2) {
@@ -19,10 +26,14 @@ public class ArbitraryOrderCollection {
}
};
- /** The root node of the tree. */
+ /**
+ * The root node of the tree.
+ */
private ArbitraryOrderNode root = new ArbitraryOrderNode();
- /** Adds and returns a new value for ordering. */
+ /**
+ * Adds and returns a new value for ordering.
+ */
public ArbitraryOrderValue createValue() {
ArbitraryOrderNode node = new ArbitraryOrderNode();
root = root.insert(node, true, NODE_COMPARATOR);
diff --git a/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderNode.java b/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderNode.java
index b5d28d9be..e905ea9ba 100644
--- a/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderNode.java
+++ b/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderNode.java
@@ -1,8 +1,15 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.arbitrary_order_collection;
-import com.github.btrekkie.red_black_node.RedBlackNode;
+import baritone.builder.utils.com.github.btrekkie.red_black_node.RedBlackNode;
-/** A node in an ArbitraryOrderCollection tree. See ArbitraryOrderCollection. */
+/**
+ * A node in an ArbitraryOrderCollection tree. See ArbitraryOrderCollection.
+ */
class ArbitraryOrderNode extends RedBlackNode {
}
diff --git a/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderValue.java b/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderValue.java
index c12b995ad..15e892ce0 100644
--- a/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderValue.java
+++ b/src/test/java/com/github/btrekkie/arbitrary_order_collection/ArbitraryOrderValue.java
@@ -1,3 +1,8 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.arbitrary_order_collection;
/**
@@ -5,7 +10,9 @@ package com.github.btrekkie.arbitrary_order_collection;
* compareTo.
*/
public class ArbitraryOrderValue implements Comparable {
- /** The node that establishes this value's relative position. */
+ /**
+ * The node that establishes this value's relative position.
+ */
final ArbitraryOrderNode node;
ArbitraryOrderValue(ArbitraryOrderNode node) {
diff --git a/src/test/java/com/github/btrekkie/arbitrary_order_collection/test/ArbitraryOrderCollectionTest.java b/src/test/java/com/github/btrekkie/arbitrary_order_collection/test/ArbitraryOrderCollectionTest.java
index 9d855d17d..f4d83f05e 100644
--- a/src/test/java/com/github/btrekkie/arbitrary_order_collection/test/ArbitraryOrderCollectionTest.java
+++ b/src/test/java/com/github/btrekkie/arbitrary_order_collection/test/ArbitraryOrderCollectionTest.java
@@ -1,19 +1,25 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.arbitrary_order_collection.test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import com.github.btrekkie.arbitrary_order_collection.ArbitraryOrderCollection;
+import com.github.btrekkie.arbitrary_order_collection.ArbitraryOrderValue;
+import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.junit.Test;
-
-import com.github.btrekkie.arbitrary_order_collection.ArbitraryOrderCollection;
-import com.github.btrekkie.arbitrary_order_collection.ArbitraryOrderValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
public class ArbitraryOrderCollectionTest {
- /** Tests ArbitraryOrderCollection. */
+ /**
+ * Tests ArbitraryOrderCollection.
+ */
@Test
public void test() {
ArbitraryOrderCollection collection = new ArbitraryOrderCollection();
diff --git a/src/test/java/com/github/btrekkie/connectivity/test/ConnGraphTest.java b/src/test/java/com/github/btrekkie/connectivity/test/ConnGraphTest.java
index dbec3a5ae..64e9f53c4 100644
--- a/src/test/java/com/github/btrekkie/connectivity/test/ConnGraphTest.java
+++ b/src/test/java/com/github/btrekkie/connectivity/test/ConnGraphTest.java
@@ -1,3 +1,8 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/dynamic-connectivity/
+ */
+
package com.github.btrekkie.connectivity.test;
import baritone.builder.EulerTourForest;
diff --git a/src/test/java/com/github/btrekkie/connectivity/test/SumAndMax.java b/src/test/java/com/github/btrekkie/connectivity/test/SumAndMax.java
index a6cc46020..6da752a89 100644
--- a/src/test/java/com/github/btrekkie/connectivity/test/SumAndMax.java
+++ b/src/test/java/com/github/btrekkie/connectivity/test/SumAndMax.java
@@ -1,3 +1,8 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/dynamic-connectivity/
+ */
+
package com.github.btrekkie.connectivity.test;
import baritone.builder.utils.com.github.btrekkie.connectivity.Augmentation;
diff --git a/src/test/java/com/github/btrekkie/interval_tree/IntervalTree.java b/src/test/java/com/github/btrekkie/interval_tree/IntervalTree.java
index d5e88624e..33362eb1e 100644
--- a/src/test/java/com/github/btrekkie/interval_tree/IntervalTree.java
+++ b/src/test/java/com/github/btrekkie/interval_tree/IntervalTree.java
@@ -1,3 +1,8 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.interval_tree;
/**
@@ -8,16 +13,21 @@ package com.github.btrekkie.interval_tree;
* interval. Each node is augmented with the maximum ending value of an interval in the subtree rooted at the node.
*/
public class IntervalTree {
- /** The root node of the tree. */
+ /**
+ * The root node of the tree.
+ */
private IntervalTreeNode root = IntervalTreeNode.LEAF;
- /** Adds the specified interval to this. */
+ /**
+ * Adds the specified interval to this.
+ */
public void addInterval(IntervalTreeInterval interval) {
root = root.insert(new IntervalTreeNode(interval), true, null);
}
/**
* Removes the specified interval from this, if it is present.
+ *
* @param interval The interval.
* @return Whether the interval was present.
*/
diff --git a/src/test/java/com/github/btrekkie/interval_tree/IntervalTreeInterval.java b/src/test/java/com/github/btrekkie/interval_tree/IntervalTreeInterval.java
index e9f38b9d9..3abb79c87 100644
--- a/src/test/java/com/github/btrekkie/interval_tree/IntervalTreeInterval.java
+++ b/src/test/java/com/github/btrekkie/interval_tree/IntervalTreeInterval.java
@@ -1,13 +1,22 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.interval_tree;
/**
* An inclusive range of values [start, end]. Two intervals are equal if they have the same starting and ending values.
*/
public class IntervalTreeInterval {
- /** The smallest value in the range. */
+ /**
+ * The smallest value in the range.
+ */
public final double start;
- /** The largest value in the range. */
+ /**
+ * The largest value in the range.
+ */
public final double end;
public IntervalTreeInterval(double start, double end) {
@@ -22,7 +31,7 @@ public class IntervalTreeInterval {
if (!(obj instanceof IntervalTreeInterval)) {
return false;
}
- IntervalTreeInterval interval = (IntervalTreeInterval)obj;
+ IntervalTreeInterval interval = (IntervalTreeInterval) obj;
return start == interval.start && end == interval.end;
}
}
diff --git a/src/test/java/com/github/btrekkie/interval_tree/IntervalTreeNode.java b/src/test/java/com/github/btrekkie/interval_tree/IntervalTreeNode.java
index d75004e77..afc71bf61 100644
--- a/src/test/java/com/github/btrekkie/interval_tree/IntervalTreeNode.java
+++ b/src/test/java/com/github/btrekkie/interval_tree/IntervalTreeNode.java
@@ -1,19 +1,30 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.interval_tree;
-import com.github.btrekkie.red_black_node.RedBlackNode;
+import baritone.builder.utils.com.github.btrekkie.red_black_node.RedBlackNode;
/**
* A node in an IntervalTree. See the comments for the implementation of IntervalTree. Its compareTo method orders
* nodes as suggested in the comments for the implementation of IntervalTree.
*/
class IntervalTreeNode extends RedBlackNode {
- /** The dummy leaf node. */
+ /**
+ * The dummy leaf node.
+ */
public static final IntervalTreeNode LEAF = new IntervalTreeNode();
- /** The interval stored in this node. */
+ /**
+ * The interval stored in this node.
+ */
public IntervalTreeInterval interval;
- /** The maximum ending value of an interval in the subtree rooted at this node. */
+ /**
+ * The maximum ending value of an interval in the subtree rooted at this node.
+ */
public double maxEnd;
public IntervalTreeNode(IntervalTreeInterval interval) {
@@ -21,7 +32,9 @@ class IntervalTreeNode extends RedBlackNode {
maxEnd = interval.end;
}
- /** Constructs a new dummy leaf node. */
+ /**
+ * Constructs a new dummy leaf node.
+ */
private IntervalTreeNode() {
interval = null;
maxEnd = Double.NEGATIVE_INFINITY;
diff --git a/src/test/java/com/github/btrekkie/interval_tree/test/IntervalTreeTest.java b/src/test/java/com/github/btrekkie/interval_tree/test/IntervalTreeTest.java
index cf0dbdfa6..f13279aee 100644
--- a/src/test/java/com/github/btrekkie/interval_tree/test/IntervalTreeTest.java
+++ b/src/test/java/com/github/btrekkie/interval_tree/test/IntervalTreeTest.java
@@ -1,17 +1,20 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.interval_tree.test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
import com.github.btrekkie.interval_tree.IntervalTree;
import com.github.btrekkie.interval_tree.IntervalTreeInterval;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
public class IntervalTreeTest {
- /** Tests IntervalTree. */
+ /**
+ * Tests IntervalTree.
+ */
@Test
public void test() {
IntervalTree tree = new IntervalTree();
diff --git a/src/test/java/com/github/btrekkie/red_black_node/test/RedBlackNodeTest.java b/src/test/java/com/github/btrekkie/red_black_node/test/RedBlackNodeTest.java
index 4d571aeb1..fa799cab5 100644
--- a/src/test/java/com/github/btrekkie/red_black_node/test/RedBlackNodeTest.java
+++ b/src/test/java/com/github/btrekkie/red_black_node/test/RedBlackNodeTest.java
@@ -1,11 +1,16 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.red_black_node.test;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import org.junit.Test;
import java.util.Comparator;
-import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* Tests RedBlackNode. Most of the testing for RedBlackNode takes place in TreeListTest, IntervalTreeTest,
@@ -30,8 +35,9 @@ public class RedBlackNodeTest {
/**
* Returns whether the nodes in the subtree rooted at the specified node are ordered correctly, as in
* TestRedBlackNode.assertOrderIsValid.
+ *
* @param comparator A comparator indicating how the nodes should be ordered. If this is null, we use the nodes'
- * natural ordering, as in TestRedBlackNode.compare.
+ * natural ordering, as in TestRedBlackNode.compare.
*/
private boolean isOrderValid(TestRedBlackNode node, Comparator comparator) {
try {
@@ -42,7 +48,9 @@ public class RedBlackNodeTest {
}
}
- /** Tests RedBlackNode.assertSubtreeIsValid() and RedBlackNode.assertOrderIsValid. */
+ /**
+ * Tests RedBlackNode.assertSubtreeIsValid() and RedBlackNode.assertOrderIsValid.
+ */
@Test
public void testAssertIsValid() {
// Create a perfectly balanced tree of height 3
@@ -129,12 +137,12 @@ public class RedBlackNodeTest {
node2.value = 3;
assertFalse(isOrderValid(node3, null));
assertFalse(
- isOrderValid(node3, new Comparator() {
- @Override
- public int compare(TestRedBlackNode node1, TestRedBlackNode node2) {
- return node1.value - node2.value;
- }
- }));
+ isOrderValid(node3, new Comparator() {
+ @Override
+ public int compare(TestRedBlackNode node1, TestRedBlackNode node2) {
+ return node1.value - node2.value;
+ }
+ }));
node3.value = 3;
node2.value = 2;
@@ -161,11 +169,11 @@ public class RedBlackNodeTest {
assertTrue(isOrderValid(node0, null));
assertTrue(isOrderValid(TestRedBlackNode.LEAF, null));
assertTrue(
- isOrderValid(node3, new Comparator() {
- @Override
- public int compare(TestRedBlackNode node1, TestRedBlackNode node2) {
- return node1.value - node2.value;
- }
- }));
+ isOrderValid(node3, new Comparator() {
+ @Override
+ public int compare(TestRedBlackNode node1, TestRedBlackNode node2) {
+ return node1.value - node2.value;
+ }
+ }));
}
}
diff --git a/src/test/java/com/github/btrekkie/red_black_node/test/TestRedBlackNode.java b/src/test/java/com/github/btrekkie/red_black_node/test/TestRedBlackNode.java
index 8e3b78cd8..bae4f2571 100644
--- a/src/test/java/com/github/btrekkie/red_black_node/test/TestRedBlackNode.java
+++ b/src/test/java/com/github/btrekkie/red_black_node/test/TestRedBlackNode.java
@@ -1,23 +1,38 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.red_black_node.test;
-import com.github.btrekkie.red_black_node.RedBlackNode;
+import baritone.builder.utils.com.github.btrekkie.red_black_node.RedBlackNode;
-/** A RedBlackNode for RedBlackNodeTest. */
+/**
+ * A RedBlackNode for RedBlackNodeTest.
+ */
class TestRedBlackNode extends RedBlackNode {
- /** The dummy leaf node. */
+ /**
+ * The dummy leaf node.
+ */
public static final TestRedBlackNode LEAF = new TestRedBlackNode();
- /** The value stored in this node. "value" is unspecified if this is a leaf node. */
+ /**
+ * The value stored in this node. "value" is unspecified if this is a leaf node.
+ */
public int value;
- /** Whether this node is considered valid, as in assertNodeIsValid(). */
+ /**
+ * Whether this node is considered valid, as in assertNodeIsValid().
+ */
public boolean isValid = true;
public TestRedBlackNode(int value) {
this.value = value;
}
- /** Constructs a new dummy leaf node. */
+ /**
+ * Constructs a new dummy leaf node.
+ */
private TestRedBlackNode() {
}
diff --git a/src/test/java/com/github/btrekkie/sub_array_min/SubArrayMin.java b/src/test/java/com/github/btrekkie/sub_array_min/SubArrayMin.java
index 63634c9f8..ff44f0f3c 100644
--- a/src/test/java/com/github/btrekkie/sub_array_min/SubArrayMin.java
+++ b/src/test/java/com/github/btrekkie/sub_array_min/SubArrayMin.java
@@ -1,14 +1,25 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.sub_array_min;
-/** A list of integers. SubArrayMin provides the ability to quickly determine the minimum value in a given sublist. */
+/**
+ * A list of integers. SubArrayMin provides the ability to quickly determine the minimum value in a given sublist.
+ */
/* We implement SubArrayMin using a red-black tree augmented by subtree size and minimum value. Using the subtree size
* augmentation, we can find the node at a given index.
*/
public class SubArrayMin {
- /** The root node. */
+ /**
+ * The root node.
+ */
private SubArrayMinNode root = SubArrayMinNode.LEAF;
- /** Appends the specified value to the end of the list. */
+ /**
+ * Appends the specified value to the end of the list.
+ */
public void add(int value) {
SubArrayMinNode newNode = new SubArrayMinNode(value);
newNode.left = SubArrayMinNode.LEAF;
@@ -25,7 +36,9 @@ public class SubArrayMin {
}
}
- /** Returns the node for the element with the specified index. Assumes "index" is in the range [0, root.size). */
+ /**
+ * Returns the node for the element with the specified index. Assumes "index" is in the range [0, root.size).
+ */
private SubArrayMinNode getNode(int index) {
if (index < 0 || index >= root.size) {
throw new IndexOutOfBoundsException("Index " + index + " is not in the range [0, " + root.size + ")");
diff --git a/src/test/java/com/github/btrekkie/sub_array_min/SubArrayMinNode.java b/src/test/java/com/github/btrekkie/sub_array_min/SubArrayMinNode.java
index 1839b7220..eeb10f695 100644
--- a/src/test/java/com/github/btrekkie/sub_array_min/SubArrayMinNode.java
+++ b/src/test/java/com/github/btrekkie/sub_array_min/SubArrayMinNode.java
@@ -1,19 +1,34 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.sub_array_min;
-import com.github.btrekkie.red_black_node.RedBlackNode;
+import baritone.builder.utils.com.github.btrekkie.red_black_node.RedBlackNode;
-/** A node in a SubArrayMin object. See the comments for the implementation of that class. */
+/**
+ * A node in a SubArrayMin object. See the comments for the implementation of that class.
+ */
class SubArrayMinNode extends RedBlackNode {
- /** The dummy leaf node. */
+ /**
+ * The dummy leaf node.
+ */
public static final SubArrayMinNode LEAF = new SubArrayMinNode();
- /** The element stored in the node. The value is unspecified if this is a leaf node. */
+ /**
+ * The element stored in the node. The value is unspecified if this is a leaf node.
+ */
public final int value;
- /** The number of elements in the subtree rooted at this node. */
+ /**
+ * The number of elements in the subtree rooted at this node.
+ */
public int size;
- /** The minimum element in the subtree rooted at this node. This is Integer.MAX_VALUE if this is a leaf node. */
+ /**
+ * The minimum element in the subtree rooted at this node. This is Integer.MAX_VALUE if this is a leaf node.
+ */
public int min;
public SubArrayMinNode(int value) {
diff --git a/src/test/java/com/github/btrekkie/sub_array_min/test/SubArrayMinTest.java b/src/test/java/com/github/btrekkie/sub_array_min/test/SubArrayMinTest.java
index 5daa7e053..d4350c224 100644
--- a/src/test/java/com/github/btrekkie/sub_array_min/test/SubArrayMinTest.java
+++ b/src/test/java/com/github/btrekkie/sub_array_min/test/SubArrayMinTest.java
@@ -1,13 +1,19 @@
+/*
+ * This file was originally written by btrekkie under the MIT license, which is compatible with the LGPL license for this usage within Baritone
+ * https://github.com/btrekkie/RedBlackNode/
+ */
+
package com.github.btrekkie.sub_array_min.test;
+import com.github.btrekkie.sub_array_min.SubArrayMin;
+import org.junit.Test;
+
import static org.junit.Assert.assertEquals;
-import org.junit.Test;
-
-import com.github.btrekkie.sub_array_min.SubArrayMin;
-
public class SubArrayMinTest {
- /** Tests SubArrayMin. */
+ /**
+ * Tests SubArrayMin.
+ */
@Test
public void test() {
SubArrayMin sam = new SubArrayMin();