rank 0.1.1 copy "rank: ^0.1.1" to clipboard
rank: ^0.1.1 copied to clipboard

A list ordering system made in Dart that helps to implement a string index to reorder a list or implement linked lists.

Rank #

A Dart package that helps to implement a string index.

Overview #

Before: #

class Element {
  const Element(..., this.position);

  ...
  final int position;  // 4
}

With a order number based ranking system, re-ordering a element of a list may require updating all elements of the list, which is O(n).

element position
... ...
apple 3
from _ to here Oh ho!
No room between 3 and 4.
pear 4
raspberry 5

Well, let's try adding zeros.

element position
... ...
apple 300
from _ to here Now, you can add 99 elements
before changing anything.
pear 400
raspberry 500

What if we don't use numbers?


With rank #

class Element {
  const Element(..., this.rank);
  ...
  
  final String rank; // knar
}

Using a string-based range, this is done with O(1). All you have to do is to update the rank field of the reordered element.

element rank
... ...
apple kra
a sweet fruit added kran
pear krb
raspberry krc

Then, to get your sorted list you could perform this query in your database:

SELECT * FROM "_" ORDER BY "rank";

Usage #

First, add the plugin rank to your pubspec.yaml file:

dependencies:
  rank: ^0.1.1

Import rank in files that it will be used:

import 'package:rank/rank.dart';

Next, you must initialize the plugin:

Rank rank = Rank();

To get a rank use generate

sweetFruitRank = rank.generate(previous: appleRank, next: pearRank);

Issues #

Please file any issues, bugs or feature request as an issue on our GitHub page.

Contributing #

If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature or you'd like an easier or better way to do something), consider opening a pull request.

1
likes
140
pub points
0%
popularity

Publisher

unverified uploader

A list ordering system made in Dart that helps to implement a string index to reorder a list or implement linked lists.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on rank