Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Unified Diff: lib/src/priority_queue.dart

Issue 1831103004: Fix strong mode warnings. (Closed) Base URL: git@github.com:dart-lang/collection@master
Patch Set: pubspec/changelog Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/src/priority_queue.dart
diff --git a/lib/src/priority_queue.dart b/lib/src/priority_queue.dart
index 64fd84f03bea8a0dae8124a07f7b03ccf2a43bbf..de91f15c7616451524a907ebfbb7e80d43700451 100644
--- a/lib/src/priority_queue.dart
+++ b/lib/src/priority_queue.dart
@@ -16,7 +16,9 @@ abstract class PriorityQueue<E> {
/// elements. An element that compares as less than another element has
/// a higher priority.
///
- /// If [comparison] is omitted, it defaults to [Comparable.compare].
+ /// If [comparison] is omitted, it defaults to [Comparable.compare]. If this
+ /// is the case, `E` must implement [Comparable], and this is checked at
+ /// runtime for every comparison.
factory PriorityQueue([int comparison(E e1, E e2)]) = HeapPriorityQueue<E>;
/// Number of elements in the queue.
@@ -121,7 +123,7 @@ class HeapPriorityQueue<E> implements PriorityQueue<E> {
static const int _INITIAL_CAPACITY = 7;
/// The comparison being used to compare the priority of elements.
- final Comparator comparison;
+ final Comparator<E> comparison;
/// List implementation of a heap.
List<E> _queue = new List<E>(_INITIAL_CAPACITY);
@@ -137,9 +139,12 @@ class HeapPriorityQueue<E> implements PriorityQueue<E> {
/// elements. An element that compares as less than another element has
/// a higher priority.
///
- /// If [comparison] is omitted, it defaults to [Comparable.compare].
+ /// If [comparison] is omitted, it defaults to [Comparable.compare]. If this
+ /// is the case, `E` must implement [Comparable], and this is checked at
+ /// runtime for every comparison.
HeapPriorityQueue([int comparison(E e1, E e2)])
- : comparison = (comparison != null) ? comparison : Comparable.compare;
+ : comparison = comparison ??
+ ((e1, e2) => (e1 as Comparable).compareTo(e2));
void add(E element) {
_add(element);

Powered by Google App Engine
This is Rietveld 408576698