gnu_sort/
lib.rs

1//! GNU sort implementation in Rust
2//!
3//! This crate provides a complete, production-ready implementation of the GNU sort utility
4//! with all major features including multiple comparison modes, field sorting, parallelization,
5//! and memory-efficient operations.
6
7#![warn(clippy::all)]
8
9pub mod config;
10pub mod error;
11
12// Core sorting implementations
13pub mod adaptive_sort;
14pub mod args;
15pub mod core_sort;
16pub mod external_sort;
17pub mod hash_sort;
18pub mod locale;
19pub mod radix_sort;
20pub mod simd_compare;
21pub mod zero_copy;
22
23// Re-export commonly used types
24pub use config::{SortConfig, SortMode, SortOrder};
25pub use error::{SortError, SortResult};
26
27/// Exit codes matching GNU sort
28pub const EXIT_SUCCESS: i32 = 0;
29pub const EXIT_FAILURE: i32 = 1;
30pub const SORT_FAILURE: i32 = 2;
31
32/// Main sort function that processes input according to configuration
33pub fn sort(config: &SortConfig, input_files: &[String]) -> SortResult<i32> {
34    // Use Core Sort implementation for optimal performance
35    let args = crate::args::SortArgs {
36        files: input_files.to_vec(),
37        output: config.output_file.clone(),
38        reverse: config.reverse,
39        numeric_sort: matches!(config.mode, crate::config::SortMode::Numeric),
40        general_numeric_sort: matches!(config.mode, crate::config::SortMode::GeneralNumeric),
41        human_numeric_sort: matches!(config.mode, crate::config::SortMode::HumanNumeric),
42        version_sort: matches!(config.mode, crate::config::SortMode::Version),
43        random_sort: matches!(config.mode, crate::config::SortMode::Random),
44        random_seed: None, // Use random seed
45        ignore_case: config.ignore_case,
46        unique: config.unique,
47        stable: config.stable,
48        field_separator: config.field_separator,
49        zero_terminated: config.zero_terminated,
50        check: config.check,
51        merge: config.merge,
52    };
53
54    let core_sort = crate::core_sort::CoreSort::new(args, config.clone());
55    core_sort
56        .sort()
57        .map_err(|e| SortError::internal(&e.to_string()))?;
58    Ok(EXIT_SUCCESS)
59}