ordered_set 1.1.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new50

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 = new 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 = new OrderedSet<Person>(Comparing.on((p) => p.name.length));

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

  // sort by role and then by name
  final people = new 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.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 = new OrderedSet();
  items.add(2);
  items.add(1);
  print(items.toList()); // [1, 2]

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

  a.add(new Person(13, 'Isadora'));
  a.add(new Person(13, 'Duncan'));
  a.add(new 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 =
      new 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.0"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
1.1.0 May 26, 2018 Go to the documentation of ordered_set 1.1.0 Download ordered_set 1.1.0 archive
1.0.0 May 26, 2018 Go to the documentation of ordered_set 1.0.0 Download ordered_set 1.0.0 archive
0.1.0 May 26, 2018 Go to the documentation of ordered_set 0.1.0 Download ordered_set 0.1.0 archive

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

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

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:ordered_set/ordered_set.dart.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run dartfmt to format lib/comparing.dart.

Dependencies

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