Skip to content

A simple implementation for an ordered set

License

Notifications You must be signed in to change notification settings

lig/ordered_set

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

A simple implementation for an ordered set

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 91.7%
  • Shell 8.3%