1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/// Parallel data organization and sorting utilities.
///
/// This module provides parallel algorithms for organizing and sorting data,
/// including deduplication, sorting, and searching operations optimized for
/// concurrent execution.
///
/// ## Features
///
/// - **Parallel Deduplication**: Remove consecutive duplicates efficiently
/// - **Parallel Sorting**: Sort large datasets using multiple threads
/// - **Parallel Search**: Binary search across sorted data
/// - **Memory Efficient**: In-place operations where possible
/// - **Stable Operations**: Maintain relative order where appropriate
///
/// ## Examples
///
/// ### Deduplication
/// ```rust
/// use trash_utilities::parallel::parallel_dedup;
///
/// let data = vec![1, 1, 2, 3, 3, 3, 4, 5, 5];
/// let deduped = parallel_dedup(data);
/// assert_eq!(deduped, vec![1, 2, 3, 4, 5]);
/// ```
///
/// ### Parallel Sorting
/// ```rust
/// use trash_utilities::parallel::parallel_sort;
///
/// let mut data = vec![3, 1, 4, 1, 5, 9, 2, 6];
/// parallel_sort(&mut data);
/// assert_eq!(data, vec![1, 1, 2, 3, 4, 5, 6, 9]);
/// ```
///
/// ### Parallel Search
/// ```rust
/// use trash_utilities::parallel::parallel_search;
///
/// let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
/// let index = parallel_search(&data, |&x| x == 7);
/// assert_eq!(index, Some(6));
///
/// let not_found = parallel_search(&data, |&x| x == 42);
/// assert_eq!(not_found, None);
/// ```
///
/// This function removes consecutive duplicate elements from a vector,
/// keeping only the first occurrence of each consecutive group.
///
/// # Type Parameters
/// - `T`: The element type, must be `Send + Sync + PartialEq`.
///
/// # Parameters
/// - `data`: The input vector to deduplicate.
///
/// # Returns
/// A new vector with consecutive duplicates removed.
///
/// # Examples
/// ```rust
/// use trash_analyzer::parallel::parallel_dedup;
///
/// let data = vec![1, 1, 2, 3, 3, 3, 4, 5, 5];
/// let deduped = parallel_dedup(data);
/// assert_eq!(deduped, vec![1, 2, 3, 4, 5]);
/// ```
/// Parallel sort a vector using `fork_union`.
///
/// This function sorts a vector in parallel using multiple threads.
/// More efficient than sequential sorting for large datasets.
///
/// # Type Parameters
/// - `T`: The element type, must be `Ord + Send`.
///
/// # Parameters
/// - `data`: The vector to sort.
///
/// # Returns
/// The sorted vector.
///
/// # Examples
/// ```rust
/// use trash_analyzer::parallel::parallel_sort;
///
/// let mut data = vec![3, 1, 4, 1, 5, 9, 2, 6];
/// parallel_sort(&mut data);
/// assert_eq!(data, vec![1, 1, 2, 3, 4, 5, 6, 9]);
/// ```
/// Parallel search for an element in a sorted vector.
///
/// This function performs binary search across multiple threads.
/// Useful for searching large sorted datasets.
///
/// # Type Parameters
/// - `T`: The element type, must be `Ord`.
/// - `F`: The predicate function type.
///
/// # Parameters
/// - `data`: The sorted vector to search.
/// - `predicate`: Function that returns true for the target element.
///
/// # Returns
/// The index of the found element, or None if not found.
///
/// # Examples
/// ```rust
/// use trash_analyzer::parallel::parallel_search;
///
/// let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
///
/// let index = parallel_search(&data, |&x| x == 7);
/// assert_eq!(index, Some(6));
/// ```