Skip to content

Commit 46afdbe

Browse files
Anatoly Akkermanmeta-codesync[bot]
authored andcommitted
Add stable LSD radix sort library
Summary: Add a generalized stable radix sort implementation to folly/algorithm. This extracts and generalizes techniques from the AdInfoStorage radix sort implementation into a reusable library. The algorithm was initially ideated/implemented by konstantin1, so the credit should go to him for coming up with it. Key features: - Stable O(n) LSD (Least Significant Digit) radix sort - Handles unsigned/signed integers and floating-point types - Custom key extractors for sorting by struct members - Ascending and descending order variants - IEEE 754 to sortable key transformation for floats/doubles - Alternating buffer pattern to minimize copying - Falls back to insertion-sort for small inputs (<16 elements) I ended up doing it because marksantaniello requested it :) It was `claude`d all the way.... Reviewed By: yfeldblum Differential Revision: D91785878 fbshipit-source-id: a85fc6a4282a120ef84c7fafff3fbab9d8f300d7
1 parent beb48e7 commit 46afdbe

File tree

6 files changed

+1091
-0
lines changed

6 files changed

+1091
-0
lines changed

folly/algorithm/BUCK

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ fb_dirsync_cpp_library(
1515
"//folly/lang:builtin",
1616
],
1717
)
18+
19+
fb_dirsync_cpp_library(
20+
name = "stable_radix_sort",
21+
headers = ["StableRadixSort.h"],
22+
use_raw_headers = True,
23+
xplat_impl = folly_xplat_library,
24+
exported_deps = [
25+
"//folly:traits",
26+
],
27+
)

folly/algorithm/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ folly_add_library(
2222
folly_lang_builtin
2323
)
2424

25+
folly_add_library(
26+
NAME stable_radix_sort
27+
HEADERS
28+
StableRadixSort.h
29+
EXPORTED_DEPS
30+
folly_traits
31+
)
32+
2533
add_subdirectory(simd)

0 commit comments

Comments
 (0)