パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v8.0.1

ordered_set

同じ優先順位を持つ複数のアイテムを許可する、Dart用のシンプルな順序付きセットの実装。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
16.8万
いいね数
35
Pub ポイント
160

パッケージをインストール

flutter pub add ordered_set

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

同じ優先度を持つ複数のアイテムをサポートする順序付きセットの実装を提供するDartパッケージです。同じ優先度を持つ要素については挿入順序を維持し、順序付きコレクションが必要なアプリケーションで予測可能かつ効率的なソートを可能にします。重複した優先度が想定されるが、順序の保持が重要となるユースケースに最適です。このパッケージは軽量で、すべての主要プラットフォームと互換性があり、pub.dev経由でFlutterプロジェクトにスムーズに統合できます。

用途

  • 優先度ベースのタスクスケジューリング
  • 重複を含む順序付きログの維持
  • タイブレーキングを用いた優先度キューの実装
  • 同等の緊急性でイベントシーケンスを管理する
  • データパイプラインにおけるカスタムソート
  • 注文制約付きのリアルタイムデータ処理

主な機能

  • 同じ優先順位を持つ複数のアイテムをサポート
  • 同等の優先順位内の挿入順序を保持する
  • クロスプラットフォーム互換性
  • 軽量で統合が簡単
  • 効率的な検索と挿入
  • 外部の依存関係なし

適している対象

  • 重複する優先度を持つ順序付きコレクションが必要な開発者
  • 決定論的順序を必要とするアプリケーション
  • 複雑なデータソートが必要なFlutterアプリ
  • 時間に敏感または優先順位に基づくワークフローを管理するシステム
  • カスタムキューまたはバッファシステムを構築しているエンジニア

注意事項

  • パフォーマンス上のトレードオフのため、高頻度の更新には適していません
  • 単一キー順序のみ(マルチレベルソートは不可)
  • 優先順位の変更を手動で処理する必要があります
  • 中程度のデータセットに最適
  • ネイティブに逆方向の反復はサポートされていません
  • 重複が多数存在する場合、標準のセットよりもメモリを多く消費する可能性があります

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

ordered_set

Pub Version Build Status Coverage Status

A simple implementation for an Ordered Set for Dart.

It accepts either a comparator function that compares items for their priority or a mapper function that maps items to their priority.

Unlike Dart's SplayTreeSet or SplayTreeMap classes, it allows for several different elements with the same "priority" to be added.

It also implements Iterable, allowing you to iterate the contents (in order) in O(n) (no additional overhead).

Usage

A simple usage example:

  import 'package:ordered_set/ordered_set.dart';

  main() {
    final items = OrderedSet.simple<num, int>();
    items.add(2);
    items.add(1);
    print(items.toList()); // [1, 2]
  }

But it can accept multiple items with the same priority:

  import 'package:ordered_set/ordered_set.dart';

  main() {
    final items = OrderedSet.mapping<String, Person>((p) => p.name);
    items.add(Person('Alice', 'Engineering'));
    items.add(Person('Bob', 'Accounting'));
    items.add(Person('Alice', 'Marketing'));
    print(items.toList()); // [Alice, Alice, Bob]
  }

Comparing

In order to assist the creation of Comparators, the Comparing class can be used:

  // sort by name length
  final people = OrderedSet.comparing<Person>(Comparing.on((p) => p.name.length));

  // sort by name desc
  final people = OrderedSet.comparing<Person>(Comparing.reverse(Comparing.on((p) => p.name)));

  // sort by role and then by name
  final people = OrderedSet.comparing<Person>(Comparing.join([(p) => p.role, (p) => p.name]));

Note that you could instead just create a MappingOrderedSet instead:

  final people = OrderedSet.mapping<num, Person>((p) => p.name.length);
  // ...

Mapping vs Comparing

There are two main implementations of the OrderedSet interface:

  • ComparingOrderedSet: the simplest implementation, takes in a Comparator and does not cache priorities. It uses Dart's SplayTreeSet as a backing implementation.
  • MappingOrderedSet: a slightly more advanced implementation that takes in a mapper function (maps elements to their priorities) and caches them. It uses Dart's SplayTreeMap as a backing implementation.

In order to create an OrderedSet, however, you can just use the static methods on the interface itself:

  • OrderedSet.comparing<E>([comparator]): creates a ComparingOrderedSet with the given Comparator.
  • OrderedSet.mapping<K, E>([mapper]): creates a MappingOrderedSet with the given mapper function.
  • OrderedSet.comparable<K, E>(): if E extends Comparable<K>, this is a simpler way of creating a MappingOrderedSet with identity mapping.
  • OrderedSet.simple<E>(): if E extends Comparable<E>, this is an even simpler way of creating a MappingOrderedSet with identity mapping.

Querying

You can [register] a set of queries, i.e., predefined sub-types, whose results, i.e., subsets of this set, are then cached. Since the queries have to be type checks, and types are runtime constants, this can be vastly optimized.

You can then filter by type by using the [query] method (or using [whereType]; which is overridden).

Note that you can change [strictMode] to allow for querying for unregistered types; if you do so, the registration cost is payed on the first query.

Contributing

All contributions are very welcome! Please feel free to create Issues, help us with PR's or comment your suggestions, feature requests, bugs, et cetera. Give us a star if you liked it!

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト