| Crates.io | counting_sort |
| lib.rs | counting_sort |
| version | 1.0.10 |
| created_at | 2020-04-30 20:51:07.334017+00 |
| updated_at | 2022-08-18 21:03:15.612071+00 |
| description | Counting sort implementation for Iterators |
| homepage | https://gitlab.com/counting_sort/crate/-/tree/main/ |
| repository | https://gitlab.com/counting_sort/crate/-/tree/main/ |
| max_upload_size | |
| id | 235938 |
| size | 105,020 |
A counting sort implementation for Iterators.
Add dependency to your Cargo.toml:
[dependencies]
counting_sort = "1.0.10"
Works immediately "out of the box" for e.g. Vecs holding integers like u8, u16, i8, i16 etc..
/*
* Add counting sort to your source code.
*/
use counting_sort::CountingSort;
let vec = vec![2,4,1,3];
// counting sort may fail, therefore a result is returned
let sorted_vec_result = vec.iter().cnt_sort();
assert!(sorted_vec_result.is_ok());
// if successful sorted elements were copied into a Vec
assert_eq!(vec![1,2,3,4], sorted_vec_result.unwrap());
all & pedantic)Readme.md, changed license-file to licensekeywords, categories and license-file to Cargo.toml[INFO tarpaulin] Coverage Results:
|| Uncovered Lines:
|| Tested/Total Lines:
|| src/lib.rs: 82/82
||
100.00% coverage, 82/82 lines covered
cnt_sort on your Vec, LinkedList etc.cnt_sort_min_maxu32 and i32 without allocating 2³²-1 usize integers if the distance d = max_value - min_value is smaller than that.cnt_sort_min_max method with a too small maximum value and Rust panics when the index is out of boundsn elements and checks if this value is the new minimum value or maximum valued = max_value - min_value (i.e. the distance d)n elements again to create the histogram of each valued elements of the count values vector to calculate the prefix sumn elements back to front to re-order the elements into a new vectorTherefore the asymptotic performance is O(3n+d). When using the cnt_sort_min_max function (when the minimum and maximum value is known) then the asymptotic performance is O(2n+d).
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 36 bits physical, 48 bits virtual
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 42
Model name: Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz
Stepping: 7
CPU MHz: 1721.799
CPU max MHz: 2900,0000
CPU min MHz: 800,0000
BogoMIPS: 4591.83
Virtualization: VT-x
L1d cache: 64 KiB
L1i cache: 64 KiB
L2 cache: 512 KiB
L3 cache: 3 MiB
NUMA node0 CPU(s): 0-3
Vulnerability Itlb multihit: KVM: Mitigation: Split huge pages
Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown: Mitigation; PTI
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling
Vulnerability Tsx async abort: Not affected
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ht tm pbe syscall nx rdtscp l
m constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm
2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm epb pti ssbd ibrs ibpb stibp tpr_shadow
vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
| # elements | cnt_sort | cnt_sort_min_max | vector.sort | sort_u8 |
|---|---|---|---|---|
| 20000 | 82 us | 63 us | 1048 us | 27 us |
| 40000 | 161 us | 123 us | 2239 us | 55 us |
| 60000 | 244 us | 185 us | 3513 us | 82 us |
| 80000 | 323 us | 248 us | 4761 us | 109 us |
| 100000 | 406 us | 310 us | 6180 us | 137 us |
| # elements | cnt_sort | cnt_sort_min_max | vector.sort | sort_u16 |
|---|---|---|---|---|
| 20000 | 89 us | 73 us | 1051 us | 95 us |
| 40000 | 188 us | 172 us | 2250 us | 122 us |
| 60000 | 318 us | 229 us | 3513 us | 148 us |
| 80000 | 382 us | 355 us | 4785 us | 174 us |
| 100000 | 477 us | 392 us | 6200 us | 205 us |