搜尋套件、儲存庫與 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 進行迭代,並提供強大的方法,例如 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

}

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。