ordered_set 1.1.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

ordered_set #

Build Status Coverage Status

A simple implementation for an ordered set for Dart.

It accepts a compare function that compares items for their priority.

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

It also implements Iterable, so you can iterate it in O(n).

Usage #

A simple usage example:

  import 'package:ordered_set/ordered_set.dart';

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

Comparing #

In order to assist the creation of OrderedSet's, there is a Comparing class to easily create Comparables:

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

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

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

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!

1.1.5 #

  • Fix coveralls, bump dependencies

1.1.4 #

  • Improve build and fix warnings

1.1.3 #

  • Formatting, removing warnings

1.1.2 #

  • Fix for dart2

1.1.0 #

  • Improving documentation via dartdocs

1.0.0 #

  • Adding Comparing class

0.1.0 #

  • Initial version, adding Ordered Set with basic operations

example/ordered_set_example.dart

import 'package:ordered_set/ordered_set.dart';
import 'package:ordered_set/comparing.dart';

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

  OrderedSet<Person> a = OrderedSet((a, b) => a.age - b.age);
  a.add(Person(12, 'Klaus'));
  a.add(Person(1, 'Sunny'));
  a.add(Person(14, 'Violet'));
  print(a.elementAt(0).name); // Sunny
  print(a.elementAt(2).name); // Violet

  a.add(Person(13, 'Isadora'));
  a.add(Person(13, 'Duncan'));
  a.add(Person(13, 'Quigley'));
  print(a.toList().map((e) => e.name));
  // Sunny, Klaus, Isadora, Duncan, Quigley, Violet

  // use Comparing for simpler creation:
  // sort by age desc and then name asc
  OrderedSet<Person> b =
      OrderedSet(Comparing.join([(p) => -p.age, (p) => p.name]));
  b.addAll(a.toList());
  print(b.toList().map((e) => e.name));
  // Violet, Duncan, Isadora, Quigley, Klaus, Sunny
}

class Person {
  int age;
  String name;
  Person(this.age, this.name);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ordered_set: ^1.1.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ordered_set/ordered_set.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
77
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

We analyzed this package on Jan 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.54.0 <3.0.0
Dev dependencies
test ^1.9.4