-
Notifications
You must be signed in to change notification settings - Fork 34
feat(collection): Replace quickSort with pdqsort for performance and robustness #922
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
Open
abbashosseinii
wants to merge
20
commits into
dart-lang:main
Choose a base branch
from
abbashosseinii:feature/replace-quicksort-with-pdqsort
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+621
−52
Open
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ebe5aba
feat(collection): Replace quickSort with pdqsort for performance and …
abbashosseinii ea66e16
test(collection): add benchmark for pdqsort vs. baseline quickSort
abbashosseinii 63fcfac
Merge branch 'main' into feature/replace-quicksort-with-pdqsort
abbashosseinii 307ec48
docs(collection): add changelog for quickSort pdqsort enhancement
abbashosseinii 009090e
refactor(core): Optimize and clarify _pdqSiftDown in heapsort
abbashosseinii 3c80f38
docs(benchmark): Improve documentation clarity for BenchmarkResult class
abbashosseinii 5c3d1ef
feat(benchmark): Add dataset generator and sorting benchmarks for qui…
abbashosseinii a6e53f9
chore: format code with `dart format`
abbashosseinii ec13079
refactor(algorithms): Remove unused imports and optimize _log2 function
abbashosseinii 4073118
refactor(sort): Optimize `_pdqSort3` based on @lrhn's suggestion
abbashosseinii f530bae
refactor(benchmark): Replace `getNextList` method with a getter to fo…
abbashosseinii 4a239f2
Update pkgs/collection/lib/src/algorithms.dart
abbashosseinii 660314a
fix(dataset_generator): Adjust random dataset generation to use full …
abbashosseinii 3b64a20
Refactor: Improve list generation in _generatePathological
abbashosseinii d5d4f52
Refactor: Improve list creation in _generateReverse
abbashosseinii 6546d0c
Refactor: Improve list creation in _generateSorted
abbashosseinii 5122e32
Refactor(benchmark): Pre-compute deterministic base lists
abbashosseinii cc7f09a
Chore: Use direct stepping in pathological list creation loops
abbashosseinii 9ebe846
Chore: Use `.reversed` to create the reversed base list
abbashosseinii 3960d63
Refactor: Improve clarity and correctness of benchmark data generators
abbashosseinii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // 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. | ||
|
|
||
| /// Centralized generation of datasets for all benchmarks. | ||
| /// | ||
| /// Ensures all algorithms are tested on the exact same data. | ||
| library; | ||
|
|
||
|
|
||
| import 'dart:math'; | ||
|
|
||
| const size = 50000; | ||
| const count = 128; // Number of lists to cycle through. | ||
|
|
||
| final List<List<int>> random = _generateRandom(); | ||
| final List<List<int>> sorted = _generateSorted(); | ||
| final List<List<int>> reverse = _generateReverse(); | ||
| final List<List<int>> fewUnique = _generateFewUnique(); | ||
| final List<List<int>> pathological = _generatePathological(); | ||
|
|
||
| List<List<int>> _generateRandom() { | ||
| final r = Random(12345); | ||
| return List.generate( | ||
| count, (_) => List.generate(size, (_) => r.nextInt(2000))); | ||
| } | ||
|
|
||
| List<List<int>> _generateSorted() { | ||
| final base = List.generate(size, (i) => i); | ||
abbashosseinii marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return List.generate(count, (_) => List<int>.from(base)); | ||
| } | ||
|
|
||
| List<List<int>> _generateReverse() { | ||
| final base = List.generate(size, (i) => size - 1 - i); | ||
| return List.generate(count, (_) => List<int>.from(base)); | ||
abbashosseinii marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| List<List<int>> _generateFewUnique() { | ||
| final r = Random(67890); | ||
| return List.generate(count, (_) => List.generate(size, (_) => r.nextInt(7))); | ||
| } | ||
|
|
||
| List<List<int>> _generatePathological() { | ||
| final base = List.generate(size, (i) => i); | ||
| // Creates a "V-shape" or "organ pipe" array that can be challenging | ||
| // for quicksort implementations by promoting unbalanced partitions. | ||
| final pathological = <int>[ | ||
| for (int i = 0; i < size; i++) | ||
| if (i.isEven) base[i], | ||
abbashosseinii marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for (int i = size - 1; i > 0; i--) | ||
| if (i.isOdd) base[i], | ||
| ]; | ||
| return List.generate(count, (_) => List<int>.from(pathological)); | ||
| } | ||
abbashosseinii marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.