AEBinaryTree 1.0.3

AEBinaryTree 1.0.3

Allan Evans维护。



  • Allan Evans

AEBinaryTree

AEBinaryTree是一个符合AVL(Adelson-Velsky and Landis)要求的自平衡二叉树或二叉搜索树,其中每个子树都有深度(或高度)相差不超过1的左右子树。BinaryTree类是通用的,可以接受符合Comparable协议的任何类型的实例。

由于许多应用程序需要根据从某些后端服务接收到数据进行排序,但在UI中显示为数组,BinaryTree类提供了插入元素和提供枚举数组属性以及随机访问索引的便捷方法。此外,BinaryTree直接通过具有O(logN)复杂度的下标方法支持随机访问,这应该足够快,可以将其用作UITableView或UICollectionView的数据源。

每个BinaryTree实例的内部操作是线程安全的。BinaryTree类提供了具有O(logN)复杂度的insert()、remove()和index(of:)操作的便捷方法,内部递归操作在主线程之外执行。

使用方法

import AEBinaryTree

class SomeClass {

    var intTree: BinaryTree<Int> // A binary tree of integers
    var stringTree: BinaryTree<String> // A binary tree of strings
    var doubleTree: BinaryTree<Double> // A binary tree of doubles, not the hotel chain
    var someTree: BinaryTree<SomeElement> // A binary tree of SomeElement that conforms to the Comparable protocol

}

项目集成

CocoaPods

CocoaPods是最推荐的依赖管理器

    pod AEBinaryTree

克隆仓库

$ git clone https://github.com/AllanEvans/BinaryTree-Swift.git <directory>