ReferenceTree

public class ReferenceTree

Mutable Tree structure.

Instance Properties

  • Parent MutableTree. The root of a tree has no parent.

    Declaration

    Swift

    public weak var parent: ReferenceTree?
  • Children MutableTree objects.

    Declaration

    Swift

    public var children: [ReferenceTree]
  • Declaration

    Swift

    public var isLeaf: Bool { get }

    Return Value

    true if there are no children. Otherwise, false.

  • All leaves.

    Declaration

    Swift

    public var leaves: [ReferenceTree] { get }
  • Declaration

    Swift

    public var isContainer: Bool { get }

    Return Value

    true if there is at least one child. Otherwise, false.

  • Declaration

    Swift

    public var isRoot: Bool { get }

    Return Value

    true if there is no parent. Otherwise, false.

  • Declaration

    Swift

    public var root: ReferenceTree { get }

    Return Value

    true if there is no parent. Otherwise, false.

  • Array of all MutableTree objects between (and including) self up to root.

    Declaration

    Swift

    public var pathToRoot: [ReferenceTree] { get }
  • Height of node.

    Declaration

    Swift

    public var height: Int { get }
  • Height of containing tree.

    Declaration

    Swift

    public var heightOfTree: Int { get }
  • Depth of node.

    Declaration

    Swift

    public var depth: Int { get }

Initializers

  • Create a ReferenceTree.

    Declaration

    Swift

    public init(parent: ReferenceTree? = nil, children: [ReferenceTree] = [])

Instance Methods

  • Add the given node to children.

    Declaration

    Swift

    public func addChild(_ node: ReferenceTree)
  • Append the given nodes to children.

    Declaration

    Swift

    public func addChildren(_ nodes: [ReferenceTree])
  • Insert the given node at the given index of children.

    Throws

    Error.insertionError if index is out of bounds.

    Declaration

    Swift

    public func insertChild(_ node: ReferenceTree, at index: Int) throws
  • Remove the given node from children.

    Throws

    Error.removalError if the given node is not held in children.

    Declaration

    Swift

    public func removeChild(_ node: ReferenceTree) throws
  • Remove the node at the given index.

    Throws

    Error.removalError if index is out of bounds.

    Declaration

    Swift

    public func removeChild(at index: Int) throws
  • Declaration

    Swift

    public func hasChild(_ child: ReferenceTree) -> Bool

    Return Value

    true if the given node is contained herein. Otherwise, false.

  • Declaration

    Swift

    public func child(at index: Int) -> ReferenceTree?

    Return Value

    Child node at the given index, if present. Otherwise, nil.

  • Declaration

    Swift

    public func leaf(at index: Int) -> ReferenceTree?

    Return Value

    Returns the leaf node at the given index, if present. Otherwise, nil.

  • Declaration

    Swift

    public func hasLeaf(_ node: ReferenceTree) -> Bool

    Return Value

    true if the given node is a leaf. Otherwise, false.

  • Declaration

    Swift

    public func hasAncestor(_ node: ReferenceTree) -> Bool

    Return Value

    true if the given node is an ancestor. Otherwise, false.

  • Declaration

    Swift

    public func ancestor(at distance: Int) -> ReferenceTree?

    Return Value

    Ancestor at the given distance, if present. Otherwise, nil.

  • Declaration

    Swift

    public func hasDescendent(_ node: ReferenceTree) -> Bool

    Return Value

    true if the given node is a descendent. Otherwise, false.