Skip to content

A high-performance, in-place Radix Sort implementation for Dart and Flutter, providing significant speed improvements over standard sorting for number lists.

License

Notifications You must be signed in to change notification settings

MostafaSensei106/Radix_Plus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

32 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Radix Plus

Radix Plus Banner

A high-performance, in-place Radix Sort library for Dart and Flutter.
Fast. Efficient. Low-level sorting for number-intensive applications.

About โ€ข Features โ€ข Installation โ€ข Usage โ€ข Benchmarks โ€ข Contributing โ€ข License


About

Welcome to Radix Plus โ€” a blazing-fast, in-place sorting library for Dart and Flutter. Radix Plus provides a set of highly optimized, stable sorting algorithms that can be significantly faster than List.sort() for specific data types, especially large lists of numbers (int, double, and BigInt). It uses low-level byte manipulation to achieve top-tier performance, making it ideal for data-intensive applications, scientific computing, and real-time data processing.


Features

๐ŸŒŸ Core Functionality

  • Multi-Type Support: Sorts List<int>, List<double>, and List<BigInt>.
  • Stable Sort: Preserves the relative order of equal elements.
  • Unified Integer API: A single function, radixSortInt, handles both signed and unsigned integers.
  • Comprehensive Float Support: radixSortDouble correctly handles positive/negative values, infinities, and zero.

๐Ÿ› ๏ธ Advanced Capabilities

  • Parallel Sorting: radixSortParallelUnsigned leverages multiple CPU cores using Isolates to sort very large lists even faster.
  • Memory Efficiency: Includes a buffer pooling mechanism (reuseBuffer: true) to minimize GC pressure during frequent sorting tasks.
  • Zero-Copy Operations: Works directly on TypedData lists (Int32List, Float64List, etc.) to avoid unnecessary memory copies.
  • Adaptive Algorithms: Uses hybrid strategies (like switching to insertion sort for small sub-lists) for optimal performance across different data sizes.

Installation

๐Ÿ“ฆ Add to your project

  1. Add this to your package's pubspec.yaml file:

    dependencies:
      radix_Plus: ^1.0.3 # Replace with the latest version
  2. Install it from your terminal:

    dart pub get

    or

    flutter pub get

๐Ÿš€ Quick Start

Import the library and call the appropriate sorting function.

import 'package:radix_Plus/radix_Plus.dart';

// Sort a list of signed integers
final numbers = [40, -1, 900, -10, 0, 5];
radixSortInt(numbers); // Automatically handles signed integers
print(numbers); // [-10, -1, 0, 5, 40, 900]

๐Ÿ“‹ Usage Examples

Sorting Integers

Use radixSortInt for both signed and unsigned integer lists.

// Sort a list of signed integers (ascending)
final signedNumbers = [40, -1, 900, -10, 0, 5];
radixSortInt(signedNumbers, ascending: true);
print(signedNumbers); // [-10, -1, 0, 5, 40, 900]

// Sort a list of unsigned integers (descending)
final unsignedNumbers = [40, 1, 900, 10, 5];
radixSortInt(unsignedNumbers, signed: false, ascending: false);
print(unsignedNumbers); // [900, 40, 10, 5, 1]

Sorting Doubles

Use radixSortDouble for List<double>.

final doubleNumbers = [10.5, -1.2, 900.0, -10.0, 0.0];
radixSortDouble(doubleNumbers);
print(doubleNumbers); // [-10.0, -1.2, 0.0, 10.5, 900.0]

Sorting BigInts

Use radixSortBigInt for List<BigInt>.

final bigIntNumbers = [
  BigInt.parse('100000000000000000000'),
  BigInt.from(-100),
  BigInt.parse('-200000000000000000000'),
  BigInt.zero,
];
radixSortBigInt(bigIntNumbers);
print(bigIntNumbers);

Parallel Sorting

For very large lists, radixSortParallelUnsigned can provide a significant speed boost.

Note: Parallel sorting is not available on the Web platform.

// A large list of numbers
final largeList = List.generate(1000000, (i) => 999999 - i);

// Sort it in parallel across multiple isolates
await radixSortParallelUnsigned(largeList);

print(largeList.first); // 0
print(largeList.last); // 999999

๐Ÿš€ Blazing Fast Performance

Performance is the core feature of Radix Plus. Our algorithms are consistently faster than the standard List.sort() for large numerical datasets, often by a significant margin.

To ensure accuracy, the results below are the average of 10 separate benchmark runs on a standard development machine AMD Ryzenโ„ข 7 5800H, each sorting a list of 1,000,000 random elements.

๐Ÿ”น Integers (List<int>)

Method Average Time (ms) Speedup vs. List.sort()
List.sort() ~1628 1.0x
radixSortInt ~288 ~5.6x faster

๐Ÿ”น Typed Lists (32-bit Integers)

Typed lists (Int32List, Uint32List) achieve even better performance due to optimized memory layout.

๐Ÿ”ธ Int32List

Method Average Time (ms) Speedup vs. List.sort()
List.sort() ~1347 1.0x
radixSortInt32 ~210 ~6.4x faster

๐Ÿ”ธ Uint32List

Method Average Time (ms) Speedup vs. List.sort()
List.sort() ~1344 1.0x
radixSortUint32 ~191 ~7.0x faster

๐Ÿ”น Floating Point Numbers

Supports both List<double> and optimized Float64List, including correct handling of NaN values.

๐Ÿ”ธ List<double>

Method Average Time (ms) Speedup vs. List.sort()
List.sort() ~2471 1.0x
radixSortDouble ~571 ~4.3x faster

๐Ÿ”ธ Float64List

Method Average Time (ms) Speedup vs. List.sort()
List.sort() ~1493 1.0x
radixSortFloat64 ~387 ~3.9x faster
radixSortFloat64WithNaN ~311 ~4.8x faster

๐Ÿ”น BigInt

Efficient sorting for arbitrary-precision integers.

Method Average Time (ms) Speedup vs. List.sort()
List.sort() ~6454 1.0x
radixSortBigInt ~1092 ~5.9x faster
radixSortBigIntWithRange ~6654 ~0.97x

โ„น๏ธ radixSortBigIntWithRange is optimized for specific range-based scenarios, not general-purpose sorting.


โšก Parallel Sorting (Multi-threaded)

Leverages Dart Isolates to unlock massive speedups on multi-core CPUs.

Method Average Time (ms) Speedup vs. List.sort()
List.sort() (Standard int) ~1628 1.0x
radixSortParallelUnsigned ~29 ~56.5x faster
radixSortParallelSigned ~31 ~52.2x faster

Technologies

Technology Description
๐Ÿง  Dart dart.dev โ€” The core language for the library.
โšก Isolates dart:isolate โ€” Used for parallel sorting to leverage multiple CPU cores.
๐Ÿ’พ TypedData dart:typed_data โ€” Used for low-level, efficient memory manipulation.
๐Ÿงช benchmark_harness A framework for creating and running performance benchmarks.

Contributing

Contributions are welcome! Hereโ€™s how to get started:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/YourFeature
  3. Commit your changes: git commit -m "Add amazing feature"
  4. Push to your branch: git push origin feature/YourFeature
  5. Open a pull request.

๐Ÿ’ก Please read our Contributing Guidelines and open an issue first for major feature ideas or changes.


License

This project is licensed under the GPL-V3.0 License. See the LICENSE file for full details.

Made with โค๏ธ by MostafaSensei106

About

A high-performance, in-place Radix Sort implementation for Dart and Flutter, providing significant speed improvements over standard sorting for number lists.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks