Skip to content

Commit bef8ca9

Browse files
author
MostafaSensei106
committed
feat(sort): Rewrite BigInt sort and enhance benchmark example
Implement a hybrid Radix Sort for BigInt, featuring 16-bit radix passes, in-place partitioning for signed numbers, and an optimized fallback to integer sort. Enhance the example application with an interactive benchmark UI, comparing various radix_pulse algorithms (signed/unsigned int, double, BigInt, parallel unsigned) against `List.sort()`. Add `CODE_OF_CONDUCT.md` and `CONTRIBUTING.md` to establish clear community guidelines. Update `pubspec.yaml` description and add repository/homepage metadata. Refactor and remove outdated benchmark files and related documentation (`benchmarks/baseline.md`, `benchmarks/unsigned_sort_benchmark.dart`). Expand comprehensive test coverage for `radixSortBigInt`.
1 parent 6e02bed commit bef8ca9

13 files changed

Lines changed: 630 additions & 249 deletions

‎CODE_OF_CONDUCT.md‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, religion, or sexual identity
10+
and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the
26+
overall community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or
31+
advances of any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email
35+
address, without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards and
42+
will take appropriate and fair corrective action in response to any behavior
43+
that they deem inappropriate, threatening, offensive, or harmful.
44+
45+
Community leaders have the right and responsibility to remove, edit, or reject
46+
comments, commits, code, wiki edits, issues, and other contributions that are
47+
not aligned to this Code of Conduct, and will communicate reasons for moderation
48+
decisions when appropriate.
49+
50+
## Scope
51+
52+
This Code of Conduct applies within all community spaces, and also applies when
53+
an individual is officially representing the community in public spaces.
54+
Examples of representing our community include using an official e-mail address,
55+
posting via an official social media account, or acting as an appointed
56+
representative at an online or offline event.
57+
58+
## Enforcement
59+
60+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
61+
reported to the community leaders responsible for enforcement at
62+
[INSERT CONTACT METHOD].
63+
All complaints will be reviewed and investigated promptly and fairly.
64+
65+
All community leaders are obligated to respect the privacy and security of the
66+
reporter of any incident.
67+
68+
## Enforcement Guidelines
69+
70+
Community leaders will follow these Community Impact Guidelines in determining
71+
the consequences for any action they deem in violation of this Code of Conduct:
72+
73+
### 1. Correction
74+
75+
**Community Impact**: Use of inappropriate language or other behavior deemed
76+
unprofessional or unwelcome in the community.
77+
78+
**Consequence**: A private, written warning from community leaders, providing
79+
clarity around the nature of the violation and an explanation of why the
80+
behavior was inappropriate. A public apology may be requested.
81+
82+
### 2. Warning
83+
84+
**Community Impact**: A violation through a single incident or series
85+
of actions.
86+
87+
**Consequence**: A warning with consequences for continued behavior. No
88+
interaction with the people involved, including unsolicited interaction with
89+
those enforcing the Code of Conduct, for a specified period of time. This
90+
includes avoiding interaction in community spaces as well as external channels
91+
like social media. Violating these terms may lead to a temporary or
92+
permanent ban.
93+
94+
### 3. Temporary Ban
95+
96+
**Community Impact**: A serious violation of community standards, including
97+
sustained inappropriate behavior.
98+
99+
**Consequence**: A temporary ban from any sort of interaction or public
100+
communication with the community for a specified period of time. No public or
101+
private interaction with the people involved, including unsolicited interaction
102+
with those enforcing the Code of Conduct, is allowed during this period.
103+
Violating these terms may lead to a permanent ban.
104+
105+
### 4. Permanent Ban
106+
107+
**Community Impact**: Demonstrating a pattern of violation of community
108+
standards, including sustained inappropriate behavior, harassment of an
109+
individual, or aggression toward or disparagement of classes of individuals.
110+
111+
**Consequence**: A permanent ban from any sort of public interaction with the
112+
community.
113+
114+
## Attribution
115+
116+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
117+
version 2.1, available at
118+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
119+
120+
[homepage]: https://www.contributor-covenant.org
121+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html

‎CONTRIBUTING.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Contributing to Radix Pulse
2+
3+
First off, thank you for considering contributing to Radix Pulse! It's people like you that make the open source community such a great place.
4+
5+
## How Can I Contribute?
6+
7+
### Reporting Bugs
8+
9+
- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/your_org/radix_pulse/issues).
10+
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/your_org/radix_pulse/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
11+
12+
### Suggesting Enhancements
13+
14+
- Open a new issue and provide a clear description of the enhancement you are suggesting.
15+
- Explain why this enhancement would be useful to other users.
16+
17+
### Pull Requests
18+
19+
1. Fork the repo and create your branch from `main`.
20+
2. Add tests for any new code you write.
21+
3. Ensure the test suite passes (`dart test`).
22+
4. Make sure your code lints (`dart analyze`).
23+
5. Format your code (`dart format .`).
24+
6. Issue that pull request!
25+
26+
## Styleguides
27+
28+
We use the standard `effective_dart` style guide. Please ensure your code is formatted and analyzed before submitting a pull request.
29+
30+
We look forward to your contributions!

‎benchmarks/baseline.md‎

Lines changed: 0 additions & 19 deletions
This file was deleted.

‎benchmarks/unsigned_sort_benchmark.dart‎

Lines changed: 0 additions & 74 deletions
This file was deleted.

‎doc/api/__404error.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<header id="title">
2525
<span id="sidenav-left-toggle" class="material-symbols-outlined" role="button" tabindex="0">menu</span>
2626
<ol class="breadcrumbs gt-separated dark hidden-xs">
27-
<li class="self-crumb">radix_pulse package</li>
27+
<li><a href="https://github.com/your_org/radix_pulse">radix_pulse package</a></li>
2828
</ol>
2929
<div class="self-name">radix_pulse</div>
3030
<form class="search navbar-right" role="search">
@@ -71,7 +71,7 @@ <h1>404: Something's gone wrong :-(</h1>
7171
</form>
7272
</header>
7373
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
74-
<li class="self-crumb">radix_pulse package</li>
74+
<li><a href="https://github.com/your_org/radix_pulse">radix_pulse package</a></li>
7575
</ol>
7676

7777
<h5>

‎doc/api/index.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<header id="title">
2525
<span id="sidenav-left-toggle" class="material-symbols-outlined" role="button" tabindex="0">menu</span>
2626
<ol class="breadcrumbs gt-separated dark hidden-xs">
27-
<li class="self-crumb">radix_pulse package</li>
27+
<li><a href="https://github.com/your_org/radix_pulse">radix_pulse package</a></li>
2828
</ol>
2929
<div class="self-name">radix_pulse</div>
3030
<form class="search navbar-right" role="search">
@@ -149,7 +149,7 @@ <h2>Libraries</h2>
149149
</form>
150150
</header>
151151
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
152-
<li class="self-crumb">radix_pulse package</li>
152+
<li><a href="https://github.com/your_org/radix_pulse">radix_pulse package</a></li>
153153
</ol>
154154

155155
<h5 class="hidden-xs"><span class="package-name">radix_pulse</span> <span class="package-kind">package</span></h5>

‎doc/api/index.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"name":"radix_pulse","qualifiedName":"radix_pulse","href":"radix_pulse/","kind":9,"packageRank":0,"desc":"Support for doing something awesome."},{"name":"clearBufferPools","qualifiedName":"radix_pulse.clearBufferPools","href":"radix_pulse/clearBufferPools.html","kind":8,"packageRank":0,"desc":"A top-level function to clear all global buffer pools.","enclosedBy":{"name":"radix_pulse","kind":9,"href":"radix_pulse/"}},{"name":"radixSortBigInt","qualifiedName":"radix_pulse.radixSortBigInt","href":"radix_pulse/radixSortBigInt.html","kind":8,"packageRank":0,"desc":"Sorts a list of BigInts in place using Radix Sort.","enclosedBy":{"name":"radix_pulse","kind":9,"href":"radix_pulse/"}},{"name":"radixSortDouble","qualifiedName":"radix_pulse.radixSortDouble","href":"radix_pulse/radixSortDouble.html","kind":8,"packageRank":0,"desc":"Sorts a list of doubles in place using a stable Radix Sort.","enclosedBy":{"name":"radix_pulse","kind":9,"href":"radix_pulse/"}},{"name":"radixSortInt","qualifiedName":"radix_pulse.radixSortInt","href":"radix_pulse/radixSortInt.html","kind":8,"packageRank":0,"desc":"Sorts a list of integers in place using a stable Radix Sort.","enclosedBy":{"name":"radix_pulse","kind":9,"href":"radix_pulse/"}},{"name":"radixSortParallelUnsigned","qualifiedName":"radix_pulse.radixSortParallelUnsigned","href":"radix_pulse/radixSortParallelUnsigned.html","kind":8,"packageRank":0,"desc":"Sorts a list of non-negative integers in parallel using Radix Sort.","enclosedBy":{"name":"radix_pulse","kind":9,"href":"radix_pulse/"}}]
1+
[{"name":"radix_pulse","qualifiedName":"radix_pulse","href":"radix_pulse/","kind":9,"packageRank":0,"desc":"Support for doing something awesome."},{"name":"clearBufferPools","qualifiedName":"radix_pulse.clearBufferPools","href":"radix_pulse/clearBufferPools.html","kind":8,"packageRank":0,"desc":"A top-level function to clear all global buffer pools.","enclosedBy":{"name":"radix_pulse","kind":9,"href":"radix_pulse/"}},{"name":"radixSortBigInt","qualifiedName":"radix_pulse.radixSortBigInt","href":"radix_pulse/radixSortBigInt.html","kind":8,"packageRank":0,"desc":"Sorts a list of BigInts in place using a highly optimized, hybrid Radix Sort.","enclosedBy":{"name":"radix_pulse","kind":9,"href":"radix_pulse/"}},{"name":"radixSortDouble","qualifiedName":"radix_pulse.radixSortDouble","href":"radix_pulse/radixSortDouble.html","kind":8,"packageRank":0,"desc":"Sorts a list of doubles in place using a stable Radix Sort.","enclosedBy":{"name":"radix_pulse","kind":9,"href":"radix_pulse/"}},{"name":"radixSortInt","qualifiedName":"radix_pulse.radixSortInt","href":"radix_pulse/radixSortInt.html","kind":8,"packageRank":0,"desc":"Sorts a list of integers in place using a stable Radix Sort.","enclosedBy":{"name":"radix_pulse","kind":9,"href":"radix_pulse/"}},{"name":"radixSortParallelUnsigned","qualifiedName":"radix_pulse.radixSortParallelUnsigned","href":"radix_pulse/radixSortParallelUnsigned.html","kind":8,"packageRank":0,"desc":"Sorts a list of non-negative integers in parallel using Radix Sort.","enclosedBy":{"name":"radix_pulse","kind":9,"href":"radix_pulse/"}}]

‎doc/api/radix_pulse/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ <h2>Functions</h2>
9696

9797
</dt>
9898
<dd>
99-
Sorts a list of BigInts in place using Radix Sort.
99+
Sorts a list of BigInts in place using a highly optimized, hybrid Radix Sort.
100100

101101

102102
</dd>

‎doc/api/radix_pulse/radixSortBigInt.html‎

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,52 @@ <h1><span class="kind-function">radixSortBigInt</span> function
6363
</section>
6464

6565
<section class="desc markdown">
66-
<p>Sorts a list of BigInts in place using Radix Sort.</p>
67-
<p>This implementation handles both positive and negative BigInts.
68-
It works by separating negative and positive numbers, sorting each group
69-
using an LSB-first radix sort approach, and then combining them.</p>
70-
<p>Note: This is a simplified implementation for demonstration and may not be as
71-
performant as the integer and double sorters for very large numbers.</p>
66+
<p>Sorts a list of BigInts in place using a highly optimized, hybrid Radix Sort.</p>
7267
</section>
7368

7469

7570

7671
<section class="summary source-code" id="source">
7772
<h2><span>Implementation</span></h2>
7873
<pre class="language-dart"><code class="language-dart">void radixSortBigInt(List&lt;BigInt&gt; data) {
79-
if (data.length &lt; 2) {
74+
final len = data.length;
75+
if (len &lt; 2) {
8076
return;
8177
}
8278

83-
final negatives = data.where((n) =&gt; n.isNegative).toList();
84-
final positives = data.where((n) =&gt; !n.isNegative).toList();
79+
&#47;&#47; Fast path escape hatch: If all numbers fit in a 64-bit signed integer,
80+
&#47;&#47; use the much faster integer-specific radix sort.
81+
bool canUseIntSort = true;
82+
for (final n in data) {
83+
if (!n.isValidInt) {
84+
canUseIntSort = false;
85+
break;
86+
}
87+
}
88+
89+
if (canUseIntSort) {
90+
final intList = data.map((e) =&gt; e.toInt()).toList();
91+
radixSortInt(intList, signed: true);
92+
for (var i = 0; i &lt; len; i++) {
93+
data[i] = BigInt.from(intList[i]);
94+
}
95+
return;
96+
}
8597

86-
&#47;&#47; Sort positive numbers ascending
87-
_radixSortPositiveBigInt(positives);
98+
&#47;&#47; 1. Partition the list in-place into negative and positive sections.
99+
int positiveStart = _partitionInPlace(data);
88100

89-
&#47;&#47; Sort negative numbers by their absolute value, then reverse to get descending
90-
_radixSortPositiveBigInt(negatives, sortByAbsolute: true);
91-
negatives.setAll(0, negatives.reversed);
101+
&#47;&#47; 2. Sort the negative part (if it exists).
102+
if (positiveStart &gt; 0) {
103+
&#47;&#47; Sort negatives by absolute value, then reverse the sorted slice.
104+
_radixSortPositiveBigInt(data, 0, positiveStart, sortByAbsolute: true);
105+
_reverse(data, 0, positiveStart);
106+
}
92107

93-
&#47;&#47; Combine the sorted lists
94-
data.clear();
95-
data.addAll(negatives);
96-
data.addAll(positives);
108+
&#47;&#47; 3. Sort the positive part (if it exists).
109+
if (positiveStart &lt; len) {
110+
_radixSortPositiveBigInt(data, positiveStart, len);
111+
}
97112
}</code></pre>
98113
</section>
99114

0 commit comments

Comments
 (0)