Class/Object

org.bitbucket.inkytonik.kiama.relation

Tree

Related Docs: object Tree | package relation

Permalink

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
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Tree(originalRoot: R)

    Permalink

Type Members

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

    Permalink

    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: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. object TreeRelationFactory extends RelationFactory[TreeRelation]

    Permalink

    Relation factory for tree relations.

  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def bottomupNoBridges(s: Strategy): Strategy

    Permalink

    A version of bottomup that doesn't traverse bridges.

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

    Permalink

    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.

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

    Permalink

    The graph of the child relation for this tree.

  9. def clone(): AnyRef

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

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

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

    Permalink

    A version of everywherebu that doesn't traverse bridges.

  13. def finalize(): Unit

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

    Permalink

    A relation that relates a node to its first child.

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

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

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

    Permalink

    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.

  18. def isFirst(t: T): Boolean

    Permalink

    Return whether or not t is a first child.

  19. final def isInstanceOf[T0]: Boolean

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

    Permalink

    Return whether or not t is a last child.

  21. def isRoot(t: T): Boolean

    Permalink

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

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

    Permalink

    A relation that relates a node to its last child.

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

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

    Permalink

    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.

  25. val nodes: Vector[T]

    Permalink

    The nodes that occur in this tree.

  26. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  27. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  28. val originalRoot: R

    Permalink
  29. lazy val parent: TreeRelation[T, T]

    Permalink

    A relation that relates a node to its parent.

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

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

    Permalink

    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.

  31. lazy val root: R

    Permalink

    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.

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

    Permalink

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

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

    Permalink
    Definition Classes
    AnyRef
  34. def toString(): String

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

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

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

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

    Permalink

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

Inherited from AnyRef

Inherited from Any

Ungrouped