Class TreeGraph<T>

java.lang.Object
io.openml.gearbox.binarytree.TreeGraph<T>
Type Parameters:
T - The type of value store in the node of the original tree

public final class TreeGraph<T> extends Object
TreeGraph is a view on top of a binary tree and maps each tree node to its neighbors, including parent and left&right children.

For example, a tree of

 
      1
    /   \
   2     3
  /
 4
 
 
will be represented as a map as [ 3:[1], 4:[2], 1:[2, 3], 2:[1, 4] ]
  • Method Details

    • of

      public static <T> TreeGraph<T> of(TreeNode<T> root)
      Creates the map view of a specified tree.
      Type Parameters:
      T - The type of value store in the node of the original tree
      Parameters:
      root - The root of the provided tree
      Returns:
      a new TreeGraph instance
      Throws:
      NullPointerException - if the root is null
    • get

      public List<TreeNode<T>> get(TreeNode<T> key)
      Returns an immutable list of all neighbors to which the specified TreeNode key is mapped, or Collections.emptyList() if this TreeGraph map contains no mapping for the key.

      More formally, if this map contains a mapping from a key k to a list l such that (key == null ? k == null : key.equals(k)), then this method returns l; otherwise it returns Collections.emptyList(). (There can be at most one such mapping.)

      Parameters:
      key - The TreeNode key whose associated list of values is to be returned
      Returns:
      the list of neighbors to which the specified key is mapped, or Collections.emptyList() if this map contains no mapping for the key
      Throws:
      NullPointerException - if the specified key is null
    • keySet

      public Set<TreeNode<T>> keySet()
      Returns an immutable Set view of the all nodes of the original tree.
      Returns:
      A set view of the keys contained in this map