-
The type to store in the
Heap
Declaration
Swift
associatedtype T
-
The storage array of the
Heap
Declaration
Swift
var storage: [T] { get set }
-
size
Default implementationThe size of the
Heap
Default Implementation
The internal storage’s
Array
.size
propertyDeclaration
Swift
var size: Int { get }
-
isEmpty
Default implementationTrue if the
Heap
is empty it is true and otherwise is false.Default Implementation
The internal storage’s
Array
.isEmpty
propertyDeclaration
Swift
var isEmpty: Bool { get }
-
A function implementing the
heapifyUp
algorithmDeclaration
Swift
mutating func heapifyUp()
-
A function implementing the
heapifyDown
algorithmDeclaration
Swift
mutating func heapifyDown()
-
peak()
Extension methodRead the next item off the
Heap
without removing it.Declaration
Swift
func peak() -> T?
-
pull()
Extension methodRead and remove the next item off
Heap
.Declaration
Swift
mutating func pull() -> T?
-
add(_:
Extension method) Add an item to the
Heap
.Declaration
Swift
mutating func add(_ elem: T)
Parameters
elem
Item to add to the
Heap
. -
getLeftChildIndex(_:
Extension method) Calculates the left child index for any given index
Declaration
Swift
internal static func getLeftChildIndex(_ parent: Int) -> Int
Parameters
parent
the parent index
Return Value
left child index
-
getRightChildIndex(_:
Extension method) Calculates the right child index for any given index
Declaration
Swift
internal static func getRightChildIndex(_ parent: Int) -> Int
Parameters
parent
the parent index
Return Value
right child index
-
getParentIndex(_:
Extension method) Calculates the parent index for any given index
Declaration
Swift
internal static func getParentIndex(_ child: Int) -> Int
Parameters
child
the parent index
Return Value
right child index
-
hasLeftChild(_:
Extension method) Checks to see if there is a left child
Declaration
Swift
internal func hasLeftChild(_ parent: Int) -> Bool
Parameters
parent
the parent index
Return Value
true if there is a left child otherwise it returns false.
-
hasRightChild(_:
Extension method) Checks to see if there is a right child
Declaration
Swift
internal func hasRightChild(_ parentIndex: Int) -> Bool
Parameters
parent
the parent index
Return Value
true if there is a right child otherwise it returns false.
-
hasParent(_:
Extension method) Checks to see if there is a parent
Declaration
Swift
internal func hasParent(_ child: Int) -> Bool
Parameters
child
The child index.
Return Value
True if there is a parent otherwise it returns false.
-
getLeftChild(_:
Extension method) Retrieve the left child
Declaration
Swift
internal func getLeftChild(_ parent: Int) -> T
Parameters
parent
The parent index.
Return Value
The left child
-
getRightChild(_:
Extension method) Retrieve the right child
Declaration
Swift
internal func getRightChild(_ parent: Int) -> T
Parameters
parent
the parent index
Return Value
The right child.
-
getParent(_:
Extension method) Retrieve the parent
Declaration
Swift
internal func getParent(_ child: Int) -> T
Parameters
child
the child index
Return Value
the parent
-
swap(_:
Extension method_: ) Swap element’s indecies
Declaration
Swift
internal mutating func swap(_ first: Int, _ second: Int)
Parameters
first
The first element’s index.
second
The second element’s index.