mirror of https://github.com/cabaletta/baritone
trimmed for merge
This commit is contained in:
parent
1c8ccd4646
commit
8812f3027b
28
.classpath
28
.classpath
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -1,15 +0,0 @@
|
|||
*.class
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
.DS_Store
|
||||
target/**
|
||||
!target/RedBlackNode*.jar
|
23
.project
23
.project
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>RedBlackNode</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,13 +0,0 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -1,60 +0,0 @@
|
|||
eclipse.preferences.version=1
|
||||
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
|
||||
sp_cleanup.add_default_serial_version_id=true
|
||||
sp_cleanup.add_generated_serial_version_id=false
|
||||
sp_cleanup.add_missing_annotations=false
|
||||
sp_cleanup.add_missing_deprecated_annotations=true
|
||||
sp_cleanup.add_missing_methods=false
|
||||
sp_cleanup.add_missing_nls_tags=false
|
||||
sp_cleanup.add_missing_override_annotations=true
|
||||
sp_cleanup.add_missing_override_annotations_interface_methods=true
|
||||
sp_cleanup.add_serial_version_id=false
|
||||
sp_cleanup.always_use_blocks=true
|
||||
sp_cleanup.always_use_parentheses_in_expressions=false
|
||||
sp_cleanup.always_use_this_for_non_static_field_access=false
|
||||
sp_cleanup.always_use_this_for_non_static_method_access=false
|
||||
sp_cleanup.convert_functional_interfaces=false
|
||||
sp_cleanup.convert_to_enhanced_for_loop=false
|
||||
sp_cleanup.correct_indentation=false
|
||||
sp_cleanup.format_source_code=false
|
||||
sp_cleanup.format_source_code_changes_only=false
|
||||
sp_cleanup.insert_inferred_type_arguments=false
|
||||
sp_cleanup.make_local_variable_final=true
|
||||
sp_cleanup.make_parameters_final=false
|
||||
sp_cleanup.make_private_fields_final=true
|
||||
sp_cleanup.make_type_abstract_if_missing_method=false
|
||||
sp_cleanup.make_variable_declarations_final=false
|
||||
sp_cleanup.never_use_blocks=false
|
||||
sp_cleanup.never_use_parentheses_in_expressions=true
|
||||
sp_cleanup.on_save_use_additional_actions=true
|
||||
sp_cleanup.organize_imports=false
|
||||
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
|
||||
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
|
||||
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
|
||||
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
|
||||
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
|
||||
sp_cleanup.remove_private_constructors=true
|
||||
sp_cleanup.remove_redundant_type_arguments=true
|
||||
sp_cleanup.remove_trailing_whitespaces=true
|
||||
sp_cleanup.remove_trailing_whitespaces_all=true
|
||||
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
|
||||
sp_cleanup.remove_unnecessary_casts=false
|
||||
sp_cleanup.remove_unnecessary_nls_tags=false
|
||||
sp_cleanup.remove_unused_imports=false
|
||||
sp_cleanup.remove_unused_local_variables=false
|
||||
sp_cleanup.remove_unused_private_fields=true
|
||||
sp_cleanup.remove_unused_private_members=false
|
||||
sp_cleanup.remove_unused_private_methods=true
|
||||
sp_cleanup.remove_unused_private_types=true
|
||||
sp_cleanup.sort_members=false
|
||||
sp_cleanup.sort_members_all=false
|
||||
sp_cleanup.use_anonymous_class_creation=false
|
||||
sp_cleanup.use_blocks=false
|
||||
sp_cleanup.use_blocks_only_for_return_and_throw=false
|
||||
sp_cleanup.use_lambda=true
|
||||
sp_cleanup.use_parentheses_in_expressions=false
|
||||
sp_cleanup.use_this_for_non_static_field_access=false
|
||||
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
|
||||
sp_cleanup.use_this_for_non_static_method_access=false
|
||||
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
|
||||
sp_cleanup.use_type_arguments=false
|
|
@ -1,4 +0,0 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
21
LICENSE
21
LICENSE
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 btrekkie
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
141
README.md
141
README.md
|
@ -1,141 +0,0 @@
|
|||
# Description
|
||||
`RedBlackNode` is a Java implementation of red-black trees. Compared to a class
|
||||
like Java's `TreeMap`, `RedBlackNode` is a low-level data structure. The
|
||||
internals of each node are exposed as public fields, allowing 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.
|
||||
|
||||
# Features
|
||||
* Supports min, max, root, predecessor, successor, insert, remove, rotate,
|
||||
split, concatenate, create balanced tree, LCA, and compare operations. The
|
||||
running time of each operation has optimal big O bounds.
|
||||
* Supports arbitrary augmentation by overriding `augment()`. Examples of
|
||||
augmentation are the number of non-leaf nodes in a subtree and the sum of the
|
||||
values in a subtree. All `RedBlackNode` methods (such as `insert` and
|
||||
`remove()`) call `augment()` as necessary to correctly maintain the
|
||||
augmentation information, unless otherwise indicated in their comments.
|
||||
* The parent and child links and the color are public fields. This gives clients
|
||||
flexibility, although it also enables them to violate the red-black or BST
|
||||
properties.
|
||||
* "Assert is valid" methods allow clients to check for errors in the structure
|
||||
or contents of a red-black tree. This is useful for debugging.
|
||||
* As a bonus (a proof of concept and a test case), this includes the `TreeList`
|
||||
class, a `List` implementation backed by a red-black tree augmented by subtree
|
||||
size.
|
||||
* Compatible with Java 6.0 and above.
|
||||
|
||||
# Limitations
|
||||
* The values of the tree must be stored in the non-leaf nodes. `RedBlackNode`
|
||||
does not support use cases where the values must be stored in the leaf nodes.
|
||||
(Note that many data structures can be implemented with either approach.)
|
||||
* Augmentations that depend on information stored in a node's ancestors are not
|
||||
(easily) supported. For example, augmenting each node with the number of nodes
|
||||
in the left subtree is not (easily and efficiently) supported, because in
|
||||
order to perform a right rotation, we would need to use the parent's
|
||||
augmentation information. However, `RedBlackNode` supports augmenting each
|
||||
node with the number of nodes in the subtree, which is basically equivalent.
|
||||
* The running time of each operation has optimal big O bounds. However, beyond
|
||||
this, no special effort has been made to optimize performance.
|
||||
|
||||
# Example usage
|
||||
```java
|
||||
class Node<T> extends RedBlackNode<Node<T>> {
|
||||
/** The value we are storing in the node. */
|
||||
public final T value;
|
||||
|
||||
/** The number of nodes in this subtree. */
|
||||
public int size;
|
||||
|
||||
public Node(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean augment() {
|
||||
int newSize = left.size + right.size + 1;
|
||||
if (newSize == size) {
|
||||
return false;
|
||||
} else {
|
||||
size = newSize;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```java
|
||||
/** Stores a set of distinct values. */
|
||||
public class Tree<T extends Comparable<? super T>> {
|
||||
/** The dummy leaf node. */
|
||||
private final Node<T> leaf = new Node<T>(null);
|
||||
|
||||
private Node<T> root = leaf;
|
||||
|
||||
public void add(T value) {
|
||||
// A comparator telling "insert" where to put the new node
|
||||
Comparator<Node<T>> comparator = new Comparator<Node<T>>() {
|
||||
public int compare(Node<T> node1, Node<T> node2) {
|
||||
return node1.value.compareTo(node2.value);
|
||||
}
|
||||
};
|
||||
|
||||
Node<T> newNode = new Node<T>(value);
|
||||
root = root.insert(newNode, false, comparator);
|
||||
}
|
||||
|
||||
/** Returns the node containing the specified value, if any. */
|
||||
private Node<T> find(T value) {
|
||||
Node<T> node = root;
|
||||
while (!node.isLeaf()) {
|
||||
int c = value.compareTo(node.value);
|
||||
if (c == 0) {
|
||||
return node;
|
||||
} else if (c < 0) {
|
||||
node = node.left;
|
||||
} else {
|
||||
node = node.right;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean contains(T value) {
|
||||
return find(value) != null;
|
||||
}
|
||||
|
||||
public void remove(T value) {
|
||||
Node<T> node = find(value);
|
||||
if (node != null) {
|
||||
root = node.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the (rank + 1)th node in the subtree rooted at "node". */
|
||||
private Node<T> getNodeWithRank(Node<T> node, int rank) {
|
||||
if (rank < 0 || rank >= node.size) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
if (rank == node.left.size) {
|
||||
return node;
|
||||
} else if (rank < node.left.size) {
|
||||
return getNodeWithRank(node.left, rank);
|
||||
} else {
|
||||
return getNodeWithRank(node.right, rank - node.left.size - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the (rank + 1)th-smallest value in the tree. */
|
||||
public T getItemWithRank(int rank) {
|
||||
return getNodeWithRank(root, rank).value;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# Documentation
|
||||
See <https://btrekkie.github.io/RedBlackNode/index.html> for API documentation.
|
28
pom.xml
28
pom.xml
|
@ -1,28 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.btrekkie.red_black_node</groupId>
|
||||
<artifactId>RedBlackNode</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<name>RedBlackNode</name>
|
||||
<description>Java implementation of augmented red-black trees. Easily maintain custom augmentation information by subclassing RedBlackNode: the base class does the work for you.</description>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
Binary file not shown.
Loading…
Reference in New Issue