Skip to content

feat(numerics): add branchless 2D/3D Hilbert curve Radix sort - #61

Merged
Sambit003 merged 1 commit into
mainfrom
feat/hilbert-radix-sorter-33
Sep 28, 2026
Merged

Sambit003 merged 1 commit into
mainfrom
feat/hilbert-radix-sorter-33

Conversation

@Sambit003

Copy link
Copy Markdown
Owner

Pull Request

Description

Introduces a 4-pass 16-bit LSD Radix sort backend for sorting complex coordinates along a continuous Hilbert space-filling curve.

This PR addresses the need for a highly optimized, locality-preserving multidimensional sorting mechanism without recursive overhead. By leveraging branchless bit-parallel Gray code transformations for Hilbert encoding and mapping the coordinates to an $O(N)$ contiguous auxiliary buffer, we ensure strictly monotonic ordering across both single and double precision floats while avoiding branch mispredictions and dynamic allocations during the scatter passes.

Fixes #33


Type of Change

  • feat: New algorithm, heuristic, or capability
  • fix: Bug fix
  • perf: Performance optimization
  • refactor: Code refactoring without behavioral change
  • docs: Documentation addition or update
  • enhance: Incremental enhancement to existing feature
  • test: New or updated tests
  • chore: Build system, CI, dependencies, or tooling

Implementation Details

  • Time Complexity:
    • Best / Average / Worst: $O(N)$ (4 passes over 16-bit buckets for a 64-bit key)
  • Space Complexity:
    • Auxiliary: $O(N)$ (One single contiguous Payload buffer allocated once)
  • Stability / In-place guarantees:
    • Stable LSD Radix sort backend.
    • Out-of-place (requires auxiliary buffer), gracefully falling back to IntroSort for segments under 256 elements to prevent buffer allocation overhead on small inputs.

Benchmarks & Performance Metrics (if applicable)

N/A - Formal benchmark regression analysis pending in follow-up profiling.


Dependencies

None


Testing & Verification

  • C++ Unit Tests (ctest --preset debug or ctest --test-dir build --output-on-failure)
  • Python Tests (pytest tests/python/ -v)
  • Memory & UB Sanitizers (cmake --preset asan)
  • Custom / Manual test script: RapidCheck Property-Based Tests (HilbertSortPBT)

Developer Checklist

  • My PR title follows <Type>(<scope>): <Precise PR deliverable>.
  • My branch was created from main using an approved prefix (feat/, fix/, perf/, etc.).
  • I have formatted my C++ code using clang-format.
  • My code produces no new compiler warnings or static analysis issues (clang-tidy).
  • I have added unit tests covering the new functionality or regression fix.
  • I have updated documentation / docstrings where appropriate.
  • My changes do not break existing functionality.

Impact Assessment

  • Isolated: Changes are localized and do not affect existing algorithm dispatch or public APIs.
  • Breaking / Affects Others: Changes modify public APIs or dispatcher heuristics (explain below).

Future Improvements

Potential integration with simd vectorized routines to parallelize the 24-state $SO(3)$ table lookups for 3D coordinates.


Additional Notes

None

Introduces a 4-pass 16-bit LSD Radix sort backend for sorting complex coordinates
along a continuous Hilbert space-filling curve.

Implementation details:
- Implements `sort_complex_hilbert` with a single O(N) auxiliary payload buffer.
- Adds branchless 2D Hilbert encoding using SWAR bit-parallel Gray code transformations.
- Implements a 24-state SO(3) octahedral rotation lookup table for 3D state transitions.
- Uses strict bitwise math for monotonic IEEE-754 single and double precision conversion.
- Integrates `HilbertSort` wrapper complying with `SortAlgorithm` registry standard.

Fixes #33
@Sambit003 Sambit003 added type: feat New feature, algorithm, or user-facing capability area: sorting Sorting algorithms (IntroSort, TimSort, Radix, BlockSort) area: numerics Float16, Morton Z-order, Boolean fastpaths, BMI2/AVX labels Sep 28, 2026
@github-actions

Copy link
Copy Markdown

🎉 Welcome, @Sambit003!

Thank you for contributing to **Algoat**! 🚀 Your pull request has been automatically assigned to you.

### 📋 Next Steps
- ✅ Ensure all tests pass:
  - C++ GoogleTest: `ctest --preset debug`
  - Python suite: `pytest tests/python/`
  - Sanitizers: `cmake --preset asan`
- ✅ Verify formatting: `clang-format -i ...`
- ✅ Include benchmark numbers if introducing or modifying algorithms
- ✅ Address any reviewer comments or suggestions

### 🤝 Helpful Resources
- [Contributing Guidelines](CONTRIBUTING.md) — build presets, git workflows, and algorithm recipes
- [Code of Conduct](CODE_OF_CONDUCT.md) — community standards

We appreciate your contribution and look forward to reviewing your work! 💙

@github-actions github-actions Bot added type: feature size: L PR change size: 250-499 lines labels Sep 28, 2026
@Sambit003
Sambit003 merged commit 0ec611b into main Sep 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: numerics Float16, Morton Z-order, Boolean fastpaths, BMI2/AVX area: sorting Sorting algorithms (IntroSort, TimSort, Radix, BlockSort) size: L PR change size: 250-499 lines type: feat New feature, algorithm, or user-facing capability type: feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Non-Recursive Branchless 2D/3D Hilbert Space-Filling Curve Radix Sorter

1 participant