ReferenceTreeProtocol
public protocol ReferenceTreeProtocol : AnyObject
Interface for nodes in tree structures.
Provides default implementations for many tree structure operations.
Useable only by
final class
types.
-
Parent node.
Declaration
Swift
var parent: Self? { get set }
-
Child nodes.
Declaration
Swift
var children: [Self] { get set }
-
isLeaf
Default implementationDefault Implementation
Declaration
Swift
var isLeaf: Bool { get }
Return Value
true
if there are no children. Otherwise,false
. -
isContainer
Default implementationDefault Implementation
Declaration
Swift
var isContainer: Bool { get }
Return Value
true
if there is at least one child. Otherwise,false
. -
isRoot
Default implementationDefault Implementation
Declaration
Swift
var isRoot: Bool { get }
Return Value
true
if there is no parent. Otherwise,false
. -
leaves
Default implementationAll leaves.
Default Implementation
Declaration
Swift
var leaves: [Self] { get }
-
root
Default implementationRoot.
Default Implementation
Declaration
Swift
var root: Self { get }
-
pathToRoot
Default implementationArray of all Node objects between (and including)
self
up toroot
.Default Implementation
Array of all Node objects between (and including)
self
up toroot
.Declaration
Swift
var pathToRoot: [Self] { get }
-
depth
Default implementationDepth of node.
Default Implementation
Depth of node.
Declaration
Swift
var depth: Int { get }
-
height
Default implementationHeight of node.
Default Implementation
Height of node.
Declaration
Swift
var height: Int { get }
-
heightOfTree
Default 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
node
tochildren
.Declaration
Swift
func addChild(_ node: Self)
-
addChildren(_:
Default implementation) Append an array of Child nodes.
Default Implementation
Append the given
nodes
tochildren
.Declaration
Swift
func addChildren(_ nodes: [Self])
-
insertChild(_:
Default implementationat: ) Insert the given child node at the given
index
.Throws
ReferenceTreeError.Error.insertionError
if the givenindex
is out of bounds.Default Implementation
Insert the given
node
at the givenindex
ofchildren
.Throws
ReferenceTreeError.insertionError
ifindex
is out of bounds.Declaration
Swift
func insertChild(_ node: Self, at index: Int) throws
-
removeChild(_:
Default implementation) Remove the given child node.
Throws
ReferenceTreeError.Error.removalError
if the given node is not contained herein.Default Implementation
Remove the given
node
fromchildren
.Throws
ReferenceTreeError.removalError
if the givennode
is 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.removalError
if the givenindex
is out of bounds.Default Implementation
Remove the node at the given
index
.Throws
ReferenceTreeError.removalError
ifindex
is 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) -> Bool
Return Value
true
if the given node is contained herein. Otherwise,false
. -
hasLeaf(_:
Default implementation) Default Implementation
Declaration
Swift
func hasLeaf(_ node: Self) -> Bool
Return Value
true
if the given node is a leaf. Otherwise,false
. -
hasAncestor(_:
Default implementation) Default Implementation
Declaration
Swift
func hasAncestor(_ node: Self) -> Bool
Return Value
true
if 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) -> Bool
Return Value
true
if the given node is a descendent. Otherwise,false
.