Package components.tree
Interface TreeKernel<T>
- Type Parameters:
T- type ofTreeKernelnode labels
- All Known Subinterfaces:
Tree<T>
- All Known Implementing Classes:
Tree1,TreeSecondary
Tree kernel component with primary methods. (Note: by package-wide
convention, all references are non-null.)
- Mathematical Definitions:
PRE_ORDER( t: tree of T ): string of T satisfies if t = empty_tree then PRE_ORDER(tree) = <> else there exists root: T, children: string of tree of T (t = compose(root, children) and PRE_ORDER(t) = <root> * STRING_PRE_ORDER(children)) STRING_PRE_ORDER( s: string of tree of T ): string of T satisfies if s = empty_string then STRING_PRE_ORDER(s) = <> else there exists t: tree of T, rest: string of tree of T (s = <t> * rest and STRING_PRE_ORDER(s) = PRE_ORDER(t) * STRING_PRE_ORDER(rest))- Mathematical Model (abstract value and abstract invariant of this):
type TreeKernel is modeled by tree of T- Constructor(s) (initial abstract value(s) of this):
(): ensures this = empty_tree- Iterator String (abstract value of ~this):
~this.seen * ~this.unseen = PRE_ORDER(this)
-
Method Summary
Modifier and TypeMethodDescriptionvoidAssembles inthisa tree with root labelrootand subtreeschildren; the declaration notwithstanding, the dynamic type of each entry ofchildrenmust be the same as the dynamic type ofthisand the dynamic type ofchildrenmust be the same as that returned bynewSequenceOfTree.disassemble(Sequence<Tree<T>> children) Disassemblesthisinto its root label, which is returned as the value of the function, and subtrees inchildren; the declaration notwithstanding, the dynamic type ofchildrenmust be the same as that returned bynewSequenceOfTree.Creates and returns an emptySequence<Tree<T>>of the dynamic type needed inassembleanddisassemble.intsize()Reports the size ofthis.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliteratorMethods inherited from interface components.standard.Standard
clear, newInstance, transferFrom
-
Method Details
-
newSequenceOfTree
Creates and returns an emptySequence<Tree<T>>of the dynamic type needed inassembleanddisassemble.- Returns:
- a new empty
Sequence<Tree<T>> - Ensures:
newSequenceOfTree = <>
-
assemble
Assembles inthisa tree with root labelrootand subtreeschildren; the declaration notwithstanding, the dynamic type of each entry ofchildrenmust be the same as the dynamic type ofthisand the dynamic type ofchildrenmust be the same as that returned bynewSequenceOfTree.- Parameters:
root- the root labelchildren- the subtrees- Aliases:
- reference
root - Replaces:
this- Clears:
children- Ensures:
this = compose(root, #children)
-
disassemble
Disassemblesthisinto its root label, which is returned as the value of the function, and subtrees inchildren; the declaration notwithstanding, the dynamic type ofchildrenmust be the same as that returned bynewSequenceOfTree.- Parameters:
children- the subtrees- Returns:
- the root label
- Replaces:
children- Clears:
this- Requires:
this /= empty_tree- Ensures:
#this = compose(disassemble, children)
-
size
int size()Reports the size ofthis.- Returns:
- the size
- Ensures:
size = |this|
-