Top Description Inners Fields Methods
io.vavr.collection

pack-priv Interface RedBlackTree<T>

Additional top-level class in compilation unit: RedBlackTreeModule.

extends Iterable<T>, Serializable
Known Direct Implementers
io.vavr.collection.RedBlackTreeModule.Node, io.vavr.collection.RedBlackTreeModule.Empty
Type Parameters
<T>
Component type
Imports
io.vavr.Tuple, .Tuple2, .Tuple3, io.vavr.collection.RedBlackTreeModule.Empty, .RedBlackTreeModule.Node, io.vavr.control.Option, java.io.Serializable, java.util.Comparator, .NoSuchElementException, .Objects

Purely functional Red/Black Tree, inspired by Kazu Yamamoto's Haskell implementation.

Based on

Author
Daniel Dietrich

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
public static final long

Method Summary

Modifier and TypeMethod and Description
public RedBlackTree.Color

Returns:

Either RED or BLACK.
color
()

Return the Color of this Red/Black Tree node.

public Comparator<T>

Returns:

The comparator.
comparator
()

Returns the underlying java.util.Comparator of this RedBlackTree.

public boolean

Returns:

true, if this tree contains the value, false otherwise.
contains
(T
A value.
value
)

Checks, if this RedBlackTree contains the given value.

public default RedBlackTree<T>

Returns:

A new RedBlackTree if the value is present, otherwise this.
delete
(T
A value
value
)

Deletes a value from this RedBlackTree.

public default RedBlackTree<T>
public static <T> RedBlackTree<T>
empty(Comparator<? super T> comparator)

public RedBlackTree<T>

Returns:

An empty ReadBlackTree
emptyInstance
()

Returns the empty instance of this RedBlackTree.

public Option<T>

Returns:

Some value, if this tree contains a value equal to the given value according to the underlying comparator. Otherwise None.
find
(T
A value
value
)

Finds the value stored in this tree, if exists, by applying the underlying comparator to the tree elements and the given element.

public default RedBlackTree<T>

Returns:

A new tree if this tree does not contain the given value, otherwise the same tree instance.
insert
(T
A value.
value
)

Inserts a new value into this tree.

public default RedBlackTree<T>
public boolean

Returns:

true, if it is empty, false otherwise.
isEmpty
()

Checks if this RedBlackTree is empty, i.e. an instance of Leaf.

public default Iterator<T>
iterator()

Implements java.lang.Iterable.iterator.

Returns an Iterator that iterates elements in the order induced by the underlying Comparator.

public RedBlackTree<T>

Returns:

The left child.
left
()

Returns the left child if this is a non-empty node, otherwise throws.

public default Option<T>

Returns:

Some element, if this is not empty, otherwise None
max
()

Returns the maximum element of this tree according to the underlying comparator.

public default Option<T>

Returns:

Some element, if this is not empty, otherwise None
min
()

Returns the minimum element of this tree according to the underlying comparator.

public static <T> RedBlackTree<T>
of(Comparator<? super T> comparator, T value)

public static <T> RedBlackTree<T>
of(Comparator<? super T> comparator, T... values)

public static <T> RedBlackTree<T>
ofAll(Comparator<? super T> comparator, Iterable<? extends T> values)

public RedBlackTree<T>

Returns:

The right child.
right
()

Returns the right child if this is a non-empty node, otherwise throws.

public int

Returns:

the number of nodes of this tree and 0 if this is the empty tree
size
()

Returns the size of this tree.

public String

Returns:

This Tree as Lisp like String.
toString
()

Returns a Lisp like representation of this tree.

public default RedBlackTree<T>

Returns:

A new RedBlackTree that contains all distinct elements of this and the given tree.
union
(RedBlackTree<T>
The RedBlackTree to form the union with.
tree
)

Adds all of the elements of the given tree to this tree, if not already present.

public T

Returns:

The value.
value
()

Returns the value of the current tree node or throws if this is empty.

Inherited from java.lang.Iterable:
forEachspliterator

Field Detail

serialVersionUIDback to summary
public static final long serialVersionUID

Method Detail

colorback to summary
public RedBlackTree.Color color()

Return the Color of this Red/Black Tree node.

An empty node is BLACK by definition.

Returns:RedBlackTree.Color

Either RED or BLACK.

comparatorback to summary
public Comparator<T> comparator()

Returns the underlying java.util.Comparator of this RedBlackTree.

Returns:Comparator<T>

The comparator.

containsback to summary
public boolean contains(T value)

Checks, if this RedBlackTree contains the given value.

Parameters
value:T

A value.

Returns:boolean

true, if this tree contains the value, false otherwise.

deleteback to summary
public default RedBlackTree<T> delete(T value)

Deletes a value from this RedBlackTree.

Parameters
value:T

A value

Returns:RedBlackTree<T>

A new RedBlackTree if the value is present, otherwise this.

differenceback to summary
public default RedBlackTree<T> difference(RedBlackTree<T> tree)
emptyback to summary
public static <T> RedBlackTree<T> empty(Comparator<? super T> comparator)
emptyInstanceback to summary
public RedBlackTree<T> emptyInstance()

Returns the empty instance of this RedBlackTree.

Returns:RedBlackTree<T>

An empty ReadBlackTree

findback to summary
public Option<T> find(T value)

Finds the value stored in this tree, if exists, by applying the underlying comparator to the tree elements and the given element.

Especially the value returned may differ from the given value, even if the underlying comparator states that both are equal.

Parameters
value:T

A value

Returns:Option<T>

Some value, if this tree contains a value equal to the given value according to the underlying comparator. Otherwise None.

insertback to summary
public default RedBlackTree<T> insert(T value)

Inserts a new value into this tree.

Parameters
value:T

A value.

Returns:RedBlackTree<T>

A new tree if this tree does not contain the given value, otherwise the same tree instance.

intersectionback to summary
public default RedBlackTree<T> intersection(RedBlackTree<T> tree)
isEmptyback to summary
public boolean isEmpty()

Checks if this RedBlackTree is empty, i.e. an instance of Leaf.

Returns:boolean

true, if it is empty, false otherwise.

iteratorback to summary
public default Iterator<T> iterator()

Implements java.lang.Iterable.iterator.

Returns an Iterator that iterates elements in the order induced by the underlying Comparator.

Internally an in-order traversal of the RedBlackTree is performed.

Example:


      4
     / \
    2   6
   / \ / \
  1  3 5  7
Iteration order: 1, 2, 3, 4, 5, 6, 7

See also Implement Iterator for BinaryTree I (In-order).

Returns:Iterator<T>

Doc from java.lang.Iterable.iterator.

an Iterator.

Annotations
@Override
leftback to summary
public RedBlackTree<T> left()

Returns the left child if this is a non-empty node, otherwise throws.

Returns:RedBlackTree<T>

The left child.

Exceptions
UnsupportedOperationException:
if this RedBlackTree is empty
maxback to summary
public default Option<T> max()

Returns the maximum element of this tree according to the underlying comparator.

Returns:Option<T>

Some element, if this is not empty, otherwise None

minback to summary
public default Option<T> min()

Returns the minimum element of this tree according to the underlying comparator.

Returns:Option<T>

Some element, if this is not empty, otherwise None

ofback to summary
public static <T> RedBlackTree<T> of(Comparator<? super T> comparator, T value)
ofback to summary
public static <T> RedBlackTree<T> of(Comparator<? super T> comparator, T... values)
Annotations
@SafeVarargs
ofAllback to summary
public static <T> RedBlackTree<T> ofAll(Comparator<? super T> comparator, Iterable<? extends T> values)
Annotations
@SuppressWarnings:unchecked
rightback to summary
public RedBlackTree<T> right()

Returns the right child if this is a non-empty node, otherwise throws.

Returns:RedBlackTree<T>

The right child.

Exceptions
UnsupportedOperationException:
if this RedBlackTree is empty
sizeback to summary
public int size()

Returns the size of this tree.

Returns:int

the number of nodes of this tree and 0 if this is the empty tree

toStringback to summary
public String toString()

Returns a Lisp like representation of this tree.

Returns:String

This Tree as Lisp like String.

Annotations
@Override
unionback to summary
public default RedBlackTree<T> union(RedBlackTree<T> tree)

Adds all of the elements of the given tree to this tree, if not already present.

Parameters
tree:RedBlackTree<T>

The RedBlackTree to form the union with.

Returns:RedBlackTree<T>

A new RedBlackTree that contains all distinct elements of this and the given tree.

valueback to summary
public T value()

Returns the value of the current tree node or throws if this is empty.

Returns:T

The value.

Exceptions
NoSuchElementException:
if this is the empty node.
io.vavr.collection back to summary

public final Enum RedBlackTree.Color

extends Enum<RedBlackTree.Color>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final RedBlackTree.Color
public static final RedBlackTree.Color

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.

public static RedBlackTree.Color
public static RedBlackTree.Color[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

BLACKback to summary
public static final RedBlackTree.Color BLACK
REDback to summary
public static final RedBlackTree.Color RED

Constructor Detail

Colorback to summary
private Color()

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static RedBlackTree.Color valueOf(String name)
valuesback to summary
public static RedBlackTree.Color[] values()