Viewing version 0.0.2+3. Open the latest package page.

dart_sort_queue

0.0.2+3

A tiny queue that sorts its items

Download archive

Readme

tinyqueue

import 'package:dart_sort_queue/dart_sort_queue.dart';

main() {
  // create a priority queue from an existing array (modifies the array)
  dynamic queue = SortQueue<int>([7, 5, 10], (a, b) => a.compareTo(b));

// add some items
  queue.push(7);
  queue.push(5);
  queue.push(10);

// remove the top item
  var top = queue.pop(); // returns 5

// return the top item (without removal)
  top = queue.peek(); // returns 7

// get queue length
  queue.length; // returns 2

// pass a custom item comparator as a second argument
  queue = SortQueue<Map<String, int>>([
    {"value": 5},
    {"value": 7}
  ], (a, b) {
    return (a["value"] ?? 0) - (b["value"] ?? 0);
  });

// turn a queue into a sorted array
  var list = queue.toList();
}

For a faster number-based queue, see flatqueue.

Install

Install using pub for Dart (dart pub add dart_sort_queue), or for Flutter (flutter pub add dart_sort_queue) then:

Thanks

A port of tinyqueue by mourner to Dart


Inspired by js-priority-queue by Adam Hooper.

Changelog

0.0.2+3

  • example updated

0.0.2+2

  • better typing of the variables

0.0.2+1

  • bugfix in _down()

0.0.2

  • bug in the _down() is fixed

0.0.1

  • Initial version.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'dart_sort_queue:0.0.2+3'
pubspec.yaml
name: dart_sort_queue
description: A tiny queue that sorts its items
version: 0.0.2+3
homepage: https://github.com/dartclub/dart_sort_queue

environment:
  sdk: ">=2.17.5 <3.0.0"

dev_dependencies:
  dartclub_lint: ^0.4.2
  test: ^1.16.0

dependencies:
  collection: ^1.16.0

Version history

VersionPublishedArchiveSHA-256
0.0.1On demandDownload6a55c20e…230c98
0.0.2-1On demandDownload26fb3f54…f6f734
0.0.2On demandDownload593b25a9…2cccb8
0.0.2+3Cached · Upstream SHA-256 matchedDownloadf3353ba8…f5f5b1

Dependencies

collection "^1.16.0"