-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds [Heap]PriorityQueue.of
constructor.
#734
base: main
Are you sure you want to change the base?
Conversation
Introduces efficient "heapify" algorithm for converting an unsorted list to a heap-sorted list, using it for the `of` constructor, and after a large `addAll` operation, when it's presumed faster than just bubbling down all the new elements. Also rewrites `HeapPriorityQueue` to use a growable list as backing array, instead of implementing the same thing using the double-when-full algorithm, and still having to deal with nullable cells. The platform growable list implementation is assumed to efficiently avoid some of those `null` checks.
PR HealthBreaking changes ✔️
Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs.
Coverage
|
File | Coverage |
---|---|
pkgs/collection/lib/src/priority_queue.dart | 💔 98 % ⬇️ 0 % |
This check for test coverage is informational (issues shown here will not fail the PR).
This check can be disabled by tagging the PR with skip-coverage-check
.
API leaks ✔️
The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
Package | Leaked API symbols |
---|
License Headers ✔️
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files |
---|
no missing headers |
All source files should start with a license header.
/// 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.of( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the right way to easily support Comparable<T>
factory PriorityQueue.ofComparable<T extends Comparable<T>>(Iterable<T>)
...something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an option, with static
instead of factory
since constructors cannot be generic.
static PriorityQueue<T> ofComparable<T extends Comparable<T>>([Iterable<T>? values]) =>
PriorityQueue<T>.of(compareComparable<T>, values);
Or just have the user use Comparable.compare
explicitly.
A problem with <T extends Comparable<T>>
is that it currently fails to infer for int
and double
.
(Although that seems to be fixed in 3.7.)
Introduces efficient (linear-number of comparisons) "heapify" algorithm for converting an unsorted list to a heap-sorted list, using it for the
of
constructor, and after a largeaddAll
operation, when it's presumed faster than just bubbling down all the new elements.Also rewrites
HeapPriorityQueue
to use a growable list as backing array, instead of implementing the same thing using the double-when-full algorithm, and still having to deal with nullable cells. The platform growable list implementation is assumed to efficiently avoid some of thosenull
checks.Closes #732