org.bitbucket.inkytonik.kiama.relation

Tree

class Tree[T <: Product, +R <: T] extends AnyRef

Relational representations of trees built out of hierarchical Product instances. Typically, the nodes are instances of case classes.

The type T is the common base type of the tree nodes. The type R is a sub-type of T that is the type of the root node.

The originalRoot value should be the root of a finite, acyclic structure that contains only Product instances of type T (unless they are skipped, see below). If the structure reachable from originalRoot is actually a tree (i.e., contains no shared nodes) then the field root will be the same as originalRoot.

On the other hand, if the structure contains shared nodes, then root will be the root of a new structure which duplicates the original structure but removes the sharing. In other words, shared nodes will be copied.

The child relation of a tree is defined to skip certain nodes. Specifically, if a node of type T is wrapped in a Some of an option, a Left or Right of an Either, a tuple up to size four, or a TraversableOnce, then those wrappers are ignored. E.g., if t1 is Some (t2) where both t1 and t2 are of type T, then t1 will be t2's parent, not the Some value.

Thanks to Len Hamey for the idea to use lazy cloning to restore the tree structure instead of requiring that the input trees contain no sharing.

Self Type
Tree[T, R]
Source
Tree.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Tree
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Tree(originalRoot: R)

Type Members

  1. class TreeRelation[V, W] extends RelationLike[V, W, TreeRelation]

    A tree relation is a binary relation on tree nodes with an extra property that the image operation throws a NodeNotInTreeException exception if it is applied to a node that is not in this tree.

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. object TreeRelationFactory extends RelationFactory[TreeRelation]

    Relation factory for tree relations.

  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def bottomupNoBridges(s: Strategy): Strategy

    A version of bottomup that doesn't traverse bridges.

  9. lazy val child: TreeRelation[T, T]

    The basic relation between a node and its children.

    The basic relation between a node and its children. All of the other relations are derived from this one. This relation preserves order in the sense that the graph of this relation records the children of a particular node in the order they appear in the tree.

  10. lazy val childGraph: Vector[(T, T)]

    The graph of the child relation for this tree.

  11. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  12. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  14. def everywherebuNoBridges(s: Strategy): Strategy

    A version of everywherebu that doesn't traverse bridges.

  15. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. lazy val firstChild: TreeRelation[T, T]

    A relation that relates a node to its first child.

  17. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  18. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  19. def index(t: T): Int

    Return the index of t in the children of t's parent node.

    Return the index of t in the children of t's parent node. Counts from zero.

  20. def isFirst(t: T): Boolean

    Return whether or not t is a first child.

  21. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  22. def isLast(t: T): Boolean

    Return whether or not t is a last child.

  23. def isRoot(t: T): Boolean

    Return whether or not t is the root of this tree.

  24. lazy val lastChild: TreeRelation[T, T]

    A relation that relates a node to its last child.

  25. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  26. lazy val next: TreeRelation[T, T]

    A relation that relates a node to its next sibling.

    A relation that relates a node to its next sibling. Inverse of the prev relation.

  27. val nodes: Vector[T]

    The nodes that occur in this tree.

  28. final def notify(): Unit

    Definition Classes
    AnyRef
  29. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  30. val originalRoot: R

  31. lazy val parent: TreeRelation[T, T]

    A relation that relates a node to its parent.

    A relation that relates a node to its parent. Inverse of the child relation.

  32. lazy val prev: TreeRelation[T, T]

    A relation that relates a node to its previous sibling.

    A relation that relates a node to its previous sibling. Inverse of the next relation.

  33. lazy val root: R

    The root node of the tree.

    The root node of the tree. The root node will be different from the original root if any nodes in the original tree are shared, since they will be cloned as necessary to yield a proper tree structure. If there is no sharing then root will be same as originalRoot. Bridges to other structures will not be traversed.

  34. lazy val siblings: TreeRelation[T, T]

    A relation that relates a node to all of its siblings.

  35. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  36. def toString(): String

    Definition Classes
    AnyRef → Any
  37. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. def whenContains[U, V](u: U, v: V): V

    If the tree contains node u return v, otherwise throw a NodeNotInTreeException.

Inherited from AnyRef

Inherited from Any

Ungrouped