AVLTree

public struct AVLTree<Key, Value> where Key : Comparable
extension AVLTree: ExpressibleByArrayLiteral
extension AVLTree: Equatable where Value: Equatable

Copy-on-write self-balancing binary search tree.

Instance Properties

  • The root node of this AVLTree.

    Declaration

    Swift

    public var root: AVLTree<Key, Value>.Node?
  • Creates an AVLTree with the given root node.

    Declaration

    Swift

    @inlinable
    public init(root: Node? = nil)

Nested Types

  • Node for an AVLTree which contains a key, and value, along with the left and right child nodes (if they exist), as well as its height.

    See more

    Declaration

    Swift

    public final class Node
    extension AVLTree.Node: Equatable where Value: Equatable

Initializers

  • Creates an AVLTree with the given key and value for the root node.

    Declaration

    Swift

    @inlinable
    public init(key: Key, value: Value)
  • Creates an AVLTree with the given sequence of key-value pairs.

    Declaration

    Swift

    @inlinable
    public init<S>(_ sequence: S) where S : Sequence, S.Element == (Key, Value)

Computed Properties

  • Declaration

    Swift

    @inlinable
    public var inOrder: [(Key, Value)] { get }

    Return Value

    An array of key-value pairs in sorted order.

Instance Methods

  • Inserts the given value for the given key.

    Declaration

    Swift

    @inlinable
    public mutating func insert(_ value: Value, forKey key: Key)
  • Balances an AVLTree to ensure that leaf no path is no more than one longer than any other.

    Declaration

    Swift

    @inlinable
    public static func balance(_ node: Node, with key: Key) -> Node

ExpressibleByArrayLiteral

  • Creates an AVLTree with an array literal of key-value pairs.

    Declaration

    Swift

    public init(arrayLiteral elements: (Key, Value)...)