搜索插件、代码仓与 APP 分类

插件详情v1.0.7

binary_tree

适用于 Dart 的自平衡二叉搜索树。BST 实现为可迭代类型。提供了许多操作,例如 greaterThen、lessThenOrEqual(创建子列表)、max、min 等。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
95
喜欢数
28
Pub 分数
150

安装插件

flutter pub add binary_tree

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一种在 Dart 中实现的自平衡二叉搜索树,旨在通过 O(log n) 复杂度保持高效的搜索、插入和删除操作。该树支持通过 Iterable 进行迭代,并提供 powerful 方法,如 greaterThan、lessThanOrEqual(用于创建子列表)、max 和 min。非常适合需要有序访问和范围查询的动态数据集。设计时兼顾性能与易用性,适用于跨多个平台需要快速排序数据管理的应用程序。

适合场景

  • 动态管理排序数据
  • 实现范围查询
  • 高效的查找和插入
  • 构建有序集合
  • 支持实时数据处理
  • 启用快速最小/最大值检索

主要特点

  • 自平衡结构
  • Iterable 支持
  • 基于范围的查询(greaterThan,lessThanOrEqual)
  • O(log n) 操作
  • 最小/最大访问方法
  • 跨平台兼容性

适合对象

  • 需要有序数据结构的开发人员
  • 频繁插入和查找的应用程序
  • 需要排序子集的系统
  • 性能关键的数据处理
  • Dart 项目在多个平台

使用建议

  • 比简单列表更高的内存开销
  • 不适合静态数据集
  • 需要理解BST概念
  • 不如内置集合直观
  • 调试树逻辑时可能出现的复杂性

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Self-Balancing Binary Search Tree for Dart. BST is implemented as Iterable. There are many operations such as greaterThan, lessThanOrEqual (create sublist), max , min etc.

Features

void main() {
  final myNumbers = BinaryTree([10, 8, 16, 4, 9, 13, 25, 2, 6, 12, 26, 14, 18]);
}

Binary tree stores values as a binary search tree.
For more information : Binary Search Tree.

A Self-Balancing AVL type tree is used, which balances the depth of the nodes.
For more information : Self Balancing Binary Search Tree , AVL Tree.

img.png

Usage

Use Case

You can see if you need it by looking at the benchmarks given below. It is generally advantageous in keeping long and sorted datasets. Its advantage is not noticeable on short datasets.

Benchmark scenarios

img_3.png img_1.png img_2.png

Type

Binary Tree objects must be Comparable

All of num , String , Duration etc. are Comparable.

You can define your objects as Comparable.

Comparable Documentation

void main() {
  final myLetters = BinaryTree<String>(["a", "c", "b"]);
  final myDates = BinaryTree<DateTime>([DateTime.now()]);
}
Basic operations
void main() {
  final myNumbers = BinaryTree([ 
    /*initial*/
  ]);
  myNumbers.insert(value);
  myNumbers.remove(value);
  myNumbers.contains(value);
  
}
Iterator

You can create an Iterator by "startsWith" or "endsWith" given element.

f() {
  final myNumbers = BinaryTree([10, 8, 16, 4, 9, 13, 25, 2, 6, 12, 26, 14, 18]);
  final iterator = myNumbers.iteratorFrom(8, greaterThan: true, equal: false); // defaults
  while (iterator.moveNext()) {
    print(iterator.current); // 9 , 10 ... 26
  }
}

You can also define bounds

f() {
  final myNumbers = BinaryTree([10, 8, 16, 4, 9, 13, 25, 2, 6, 12, 26, 14, 18]);
  final iterator = myNumbers.iteratorFrom(8, bound: Bound(13, equal: true));
  while (iterator.moveNext()) {
    print(iterator.current); // 9 , 10 ... 13
  }
}
toList

You can create new lists using range iterators.

f() {
  final myNumbers = BinaryTree([10, 8, 16, 4, 9, 13, 25, 2, 6, 12, 26, 14, 18]);

  myNumbers.lessThan(16);

  /// 14 , 13 , ... 2
  myNumbers.lessThanOrEqual(16);

  /// 16 , 14 , 13 , ... 2
  myNumbers.greaterThan(16);

  ///  25 , 26
  myNumbers.greaterThanOrEqual(16);

  /// 16 , 25 , 26

  /// custom bound
  myNumbers.listFrom(16, bound: Bound(13, equal: true));

  /// 16 , 14 , 13

}

所属分类

源码仓库

使用此插件的项目

暂无相关数据。