Skip to main content

adze_concurrency_map_core/
lib.rs

1//! Core bounded parallel map utilities built on deterministic partition planning.
2
3#![forbid(unsafe_op_in_unsafe_fn)]
4#![deny(missing_docs)]
5#![cfg_attr(feature = "strict_api", deny(unreachable_pub))]
6#![cfg_attr(not(feature = "strict_api"), warn(unreachable_pub))]
7#![cfg_attr(feature = "strict_docs", deny(missing_docs))]
8#![cfg_attr(not(feature = "strict_docs"), allow(missing_docs))]
9
10/// Re-exported bounded parallel map and partition planning utilities.
11pub use adze_concurrency_bounded_map_core::{
12    ParallelPartitionPlan, bounded_parallel_map, normalized_concurrency,
13};
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18
19    #[test]
20    fn normalized_concurrency_clamps_zero_to_one() {
21        assert_eq!(normalized_concurrency(0), 1);
22    }
23
24    #[test]
25    fn normalized_concurrency_preserves_positive() {
26        assert_eq!(normalized_concurrency(1), 1);
27        assert_eq!(normalized_concurrency(4), 4);
28    }
29
30    #[test]
31    fn bounded_parallel_map_empty_input() {
32        let result: Vec<i32> = bounded_parallel_map(vec![], 4, |x: i32| x + 1);
33        assert!(result.is_empty());
34    }
35
36    #[test]
37    fn bounded_parallel_map_single_item() {
38        let result = bounded_parallel_map(vec![42], 4, |x| x * 2);
39        assert_eq!(result, vec![84]);
40    }
41
42    #[test]
43    fn partition_plan_for_empty() {
44        let plan = ParallelPartitionPlan::for_item_count(0, 4);
45        // Even for empty input, chunk_size is at least 1 (items/concurrency rounded up)
46        assert!(plan.chunk_size >= 1);
47    }
48}