Skip to content

Adds [Heap]PriorityQueue.of constructor. #734

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

Merged
merged 6 commits into from
Apr 4, 2025
Merged

Adds [Heap]PriorityQueue.of constructor. #734

merged 6 commits into from
Apr 4, 2025

Conversation

lrhn
Copy link
Member

@lrhn lrhn commented Dec 18, 2024

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 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.

Closes #732

Copy link

github-actions bot commented Dec 18, 2024

PR Health

Breaking changes ⚠️
Package Change Current Version New Version Needed Version Looking good?
collection Breaking 1.19.1 1.20.0-wip 2.0.0
Got "1.20.0-wip" expected >= "2.0.0" (breaking changes)
⚠️

This check can be disabled by tagging the PR with skip-breaking-check.

Changelog Entry ✔️
Package Changed Files

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) 2025, 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.

@lrhn lrhn requested a review from natebosch February 3, 2025 09:12
@lrhn
Copy link
Member Author

lrhn commented Mar 19, 2025

Ping @natebosch

@lrhn lrhn requested review from a team as code owners April 4, 2025 15:39
@github-actions github-actions bot added type-infra A repository infrastructure change or enhancement package:path labels Apr 4, 2025
lrhn and others added 5 commits April 4, 2025 17:55
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.
Update docs.
Let `removeAll` return a list. It's wasteful not to. As an implementation class, it's OK to depend on implementation.
It couldn't be extended in practice since it doesn't have a
public constructor

Also made the only implementations final
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.
@github-actions github-actions bot removed type-infra A repository infrastructure change or enhancement package:path labels Apr 4, 2025
@lrhn lrhn merged commit af37fe5 into main Apr 4, 2025
14 checks passed
@lrhn lrhn deleted the heapify branch April 4, 2025 16:34
@devoncarew
Copy link
Member

We're seeing a google3 roll failure, I believe from this change:

[.../async/lib/src/priority_stream_iterator.dart:110]
'_StablePriorityQueue.removeAll' ('Iterable<T> Function()') isn't a valid override of 'HeapPriorityQueue.removeAll' ('List<T> Function()'). #invalid_override

  Iterable<T> removeAll() {
              ^^^^^^^^^

copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Apr 9, 2025
Revisions updated by `dart tools/rev_sdk_deps.dart`.

core (https://github.com/dart-lang/core/compare/7a80178..af37fe5):
  af37fe54  2025-04-04  Lasse R.H. Nielsen  Adds `[Heap]PriorityQueue.of` constructor. (dart-lang/core#734)
  635dfa32  2025-04-03  Kevin Moore  [collection] explicitly make BoolList abstract interface (dart-lang/core#875)

ecosystem (https://github.com/dart-lang/ecosystem/compare/391a80c..7f6f1c1):
  7f6f1c1  2025-04-09  Daco Harkes  [firehose] Fix dart_apitool invocations with pub workspaces (dart-lang/ecosystem#355)
  0eb0349  2025-04-07  Moritz  Fix tagging in publishing workflow (again) (dart-lang/ecosystem#353)
  1ee8568  2025-04-07  Moritz  Update README.md (dart-lang/ecosystem#352)

http (https://github.com/dart-lang/http/compare/6fabf06..e4ddd3e):
  e4ddd3e  2025-04-07  Moritz  Merge pull request `#1750` from dart-lang/fixTags
  42b42e3  2025-04-07  Moritz  Fix tags
  54bf0f7  2025-04-07  Moritz  Merge pull request `#1748` from dart-lang/fixPublish
  84adca0  2025-04-04  Moritz  Merge pull request `#1432` from dart-lang/fixHealth
  8534a69  2025-04-04  Moritz  Remove ignore breaking
  b80436a  2025-04-04  Moritz  allow underscore
  949cd87  2025-04-04  Moritz  Fix publishing workflow
  996c5d1  2024-12-17  Moritz  ignore only for breaking changes
  e5321f7  2024-12-17  Moritz  Update .github/workflows/health.yaml
  f902d8a  2024-12-17  Moritz  typo
  35f6e9a  2024-12-17  Moritz  exclude websocket
  ca8caee  2024-12-17  Moritz  Ignore http
  621401e  2024-12-17  Moritz  remove ignore license
  ce20b2a  2024-12-17  Moritz  Fix health workflow

test (https://github.com/dart-lang/test/compare/c1fa1e6..8643fbf):
  8643fbf3  2025-04-09  Ömer Sinan Ağacan  Migrate from deprecated `dart:js`, `dart:js_util`, `package:js_util` to `dart:js_interop` (dart-lang/test#2478)

tools (https://github.com/dart-lang/tools/compare/b963bbf..d74f9e1):
  d74f9e13  2025-04-08  Loïc Sharma  [UA] Add a Flutter event for plugins injected into an iOS/macOS project. (dart-lang/tools#2062)
  f34228f8  2025-04-08  Kevin Moore  [graphs] fix readme CI badge (dart-lang/tools#2068)
  0102cd63  2025-04-08  Kevin Moore  [markdown] fix crash test (dart-lang/tools#2067)

webdev (https://github.com/dart-lang/webdev/compare/697f2f7..c8b1cfa):
  c8b1cfa9  2025-04-07  Srujan Gaddam  [dwds] Split hot reload callback into 2, disable breakpoints in changed files, and publish 24.3.10 (dart-lang/webdev#2606)
  8d8413f5  2025-04-04  Wdestroier  Support custom hostname and TLS options (dart-lang/webdev#2588)

Change-Id: Idbad02c2087ceb3c7d0f7efcf0721f4806475e8e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421542
Reviewed-by: Konstantin Shcheglov <[email protected]>
Auto-Submit: Devon Carew <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement heapify in HeapPriorityQueue.addAll
4 participants