ReferenceTreeProtocol
public protocol ReferenceTreeProtocol : AnyObject
Interface for nodes in tree structures.
Provides default implementations for many tree structure operations.
Useable only by
final classtypes.
-
Parent node.
Declaration
Swift
var parent: Self? { get set } -
Child nodes.
Declaration
Swift
var children: [Self] { get set } -
isLeafDefault implementationDefault Implementation
Declaration
Swift
var isLeaf: Bool { get }Return Value
trueif there are no children. Otherwise,false. -
isContainerDefault implementationDefault Implementation
Declaration
Swift
var isContainer: Bool { get }Return Value
trueif there is at least one child. Otherwise,false. -
isRootDefault implementationDefault Implementation
Declaration
Swift
var isRoot: Bool { get }Return Value
trueif there is no parent. Otherwise,false. -
leavesDefault implementationAll leaves.
Default Implementation
Declaration
Swift
var leaves: [Self] { get } -
rootDefault implementationRoot.
Default Implementation
Declaration
Swift
var root: Self { get } -
pathToRootDefault implementationArray of all Node objects between (and including)
selfup toroot.Default Implementation
Array of all Node objects between (and including)
selfup toroot.Declaration
Swift
var pathToRoot: [Self] { get } -
depthDefault implementationDepth of node.
Default Implementation
Depth of node.
Declaration
Swift
var depth: Int { get } -
heightDefault implementationHeight of node.
Default Implementation
Height of node.
Declaration
Swift
var height: Int { get } -
heightOfTreeDefault implementationHeight of containing tree.
Default Implementation
Height of containing tree.
Declaration
Swift
var heightOfTree: Int { get }
-
addChild(_:Default implementation) Append a child node.
Default Implementation
Add the given
nodetochildren.Declaration
Swift
func addChild(_ node: Self) -
addChildren(_:Default implementation) Append an array of Child nodes.
Default Implementation
Append the given
nodestochildren.Declaration
Swift
func addChildren(_ nodes: [Self]) -
insertChild(_:Default implementationat: ) Insert the given child node at the given
index.Throws
ReferenceTreeError.Error.insertionErrorif the givenindexis out of bounds.Default Implementation
Insert the given
nodeat the givenindexofchildren.Throws
ReferenceTreeError.insertionErrorifindexis out of bounds.Declaration
Swift
func insertChild(_ node: Self, at index: Int) throws -
removeChild(_:Default implementation) Remove the given child node.
Throws
ReferenceTreeError.Error.removalErrorif the given node is not contained herein.Default Implementation
Remove the given
nodefromchildren.Throws
ReferenceTreeError.removalErrorif the givennodeis not held inchildren.Declaration
Swift
func removeChild(_ node: Self) throws -
removeChild(at:Default implementation) Remove the child node at the given
index.Throws
ReferenceTreeError.Error.removalErrorif the givenindexis out of bounds.Default Implementation
Remove the node at the given
index.Throws
ReferenceTreeError.removalErrorifindexis out of bounds.Declaration
Swift
func removeChild(at index: Int) throws -
child(at:Default implementation) Default Implementation
Declaration
Swift
func child(at index: Int) -> `Self`?Return Value
Child node at the given
index, if present. Otherwise,nil. -
leaf(at:Default implementation) Default Implementation
Declaration
Swift
func leaf(at index: Int) -> `Self`?Return Value
Returns the leaf node at the given
index, if present. Otherwise,nil. -
hasChild(_:Default implementation) Default Implementation
Declaration
Swift
func hasChild(_ child: Self) -> BoolReturn Value
trueif the given node is contained herein. Otherwise,false. -
hasLeaf(_:Default implementation) Default Implementation
Declaration
Swift
func hasLeaf(_ node: Self) -> BoolReturn Value
trueif the given node is a leaf. Otherwise,false. -
hasAncestor(_:Default implementation) Default Implementation
Declaration
Swift
func hasAncestor(_ node: Self) -> BoolReturn Value
trueif the given node is an ancestor. Otherwise,false. -
ancestor(at:Default implementation) Default Implementation
Declaration
Swift
func ancestor(at distance: Int) -> `Self`?Return Value
Ancestor at the given distance, if present. Otherwise,
nil. -
hasDescendent(_:Default implementation) Default Implementation
Declaration
Swift
func hasDescendent(_ node: Self) -> BoolReturn Value
trueif the given node is a descendent. Otherwise,false.
View on GitHub
Install in Dash
ReferenceTreeProtocol Protocol Reference