https://github.com/appsup-dart/sortedmap
A map of objects which can be sorted and filtered on both their key and value
https://github.com/appsup-dart/sortedmap
Last synced: 3 months ago
JSON representation
A map of objects which can be sorted and filtered on both their key and value
- Host: GitHub
- URL: https://github.com/appsup-dart/sortedmap
- Owner: appsup-dart
- License: bsd-3-clause
- Created: 2016-06-07T10:24:38.000Z (about 9 years ago)
- Default Branch: release/0.1.0
- Last Pushed: 2024-04-22T19:30:33.000Z (about 1 year ago)
- Last Synced: 2025-04-11T00:03:45.309Z (3 months ago)
- Size: 150 KB
- Stars: 7
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Contains a `SortedMap` and `FilteredMap` class, which hold a map of objects that can be ordered relative to each other.
Unlike `SplayTreeMap` the objects can be ordered on both key and value or a combination of both.
The `FilteredMap` also allows to specify an `isValid` function on key/value pairs and limit the number of objects
allowed in the map.## SortedMap
A simple usage example:
import 'package:sortedmap/sortedmap.dart';
main() {
var map = new SortedMap((Pair a, Pair b)=>Comparable.compare(a.value, b.value));
map.addAll({
"a": 3,
"b": 2,
"c": 4,
"d": 1
});
print(map.lastKeyBefore("c")); // a
print(map.firstKeyAfter("d")); // b
}## FilteredMap
A simple usage example:
import 'package:sortedmap/sortedmap.dart';
main() {
var map = new FilteredMap(new Filter(
compare: (Pair a, Pair b)=>Comparable.compare(a.value, b.value),
isValid: (Pair v) => v.key!="b",
limit: 2));
map.addAll({
"a": 3,
"b": 2,
"c": 4,
"d": 1
});
print(map.keys); // (d, a)
}## Features and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
[tracker]: https://github.com/appsup-dart/sortedmap/issues