Class

org.bitbucket.inkytonik.kiama.relation

Tree

Related Doc: 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).

The shape argument governs how the structure referred to by originalRoot is treated. If shape is LeaveAlone (the default) then the structure is used without change. If shape is CheckTree then a check is run before the structure is used to make sure that it is a tree (i.e., no node sharing nor cycles). A runtime error occurs if this is not the case. If shape is EnsureTree then shared parts of the structure are cloned to ensure that it is a tree before it is used.

If you are confident that your structure is a tree (e.g., it comes from a parser) then the default shape should be fine. If you prefer a bit more safety, then use CheckTree so that a non-tree structure cannot be missed. Finally, use EnsureTree if you know that your structure may contain sharing (e.g., it is produced by a term rewriting process).

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, shape: TreeShape = LeaveAlone)

    Permalink

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. final def asInstanceOf[T0]: T0

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

    Permalink

    A version of bottomup that doesn't traverse bridges.

  6. lazy val child: TreeRelation[T]

    Permalink

    The basic relations between a node and its children.

    The basic relations between a node and its children. All of the other relations are derived from child. If this tree's shape argument is CheckTree then a check will be performed that the structure is actually a tree. A runtime error will be thrown if it's not a tree.

  7. def clone(): AnyRef

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

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

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

    Permalink

    A version of everywherebu that doesn't traverse bridges.

  11. def finalize(): Unit

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

    Permalink

    A relation that relates a node to its first child.

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

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

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

    Permalink

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

    Return the first index of t in the children of t's parent node. Counts from zero. Is zero for root.

  16. def indexFromEnd(t: T): Int

    Permalink

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

    Return the last index of t in the children of t's parent node. Counts from zero. Is zero for root.

  17. def isFirst(t: T): Boolean

    Permalink

    Return whether or not t is a first child.

    Return whether or not t is a first child. True for root.

  18. final def isInstanceOf[T0]: Boolean

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

    Permalink

    Return whether or not t is a last child.

    Return whether or not t is a last child. True for root.

  20. def isRoot(t: T): Boolean

    Permalink

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

  21. lazy val lastChild: TreeRelation[T]

    Permalink

    A relation that relates a node to its last child.

  22. def mapChild(f: (Vector[T]) ⇒ Vector[T]): TreeRelation[T]

    Permalink

    Map the function f over the images of this tree's child relation and use the resulting graph to make a new tree relation.

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

    Permalink
    Definition Classes
    AnyRef
  24. lazy val next: TreeRelation[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. lazy val nodes: Vector[T]

    Permalink

    The nodes that occur in this tree.

    The nodes that occur in this tree. Mostly useful if you want to iterate to look at every node.

  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]

    Permalink

    The parent relation for this tree (inverse of child relation).

  30. lazy val prev: TreeRelation[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. If this tree's shape argument is EnsureTree 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 or EnsureTree is not specified then root will be same as originalRoot.

    Bridges to other structures will not be traversed. This behaviour means that you can have references to other structures while still processing this structure as a tree in its own right.

  32. lazy val sibling: TreeRelation[T]

    Permalink

    A relation that relates a node to its siblings, including itself.

  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[V](t: T, v: ⇒ V): V

    Permalink

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

    If the tree contains node u return v, otherwise throw a NodeNotInTreeException. v is only evaluated if necessary.

Inherited from AnyRef

Inherited from Any

Ungrouped