array_merge/lib.rs
1pub mod am {
2
3 /// Takes one source array, divides it into two arrays using `start`, `middle` and `end`
4 /// delimiters. Overwrites the destination array.
5 #[allow(dead_code)]
6 pub fn merge(
7 source: &mut [u8],
8 destination: &mut [u8],
9 start: usize,
10 end: usize,
11 middle: usize,
12 ) {
13
14 let mut i = start;
15 let mut j = middle;
16
17 for index in start..end {
18
19 if (j >= end || source[i] <= source[j]) && i < middle {
20 destination[index] = source[i];
21 i += 1;
22 }
23 else
24 {
25 destination[index] = source[j];
26 j += 1;
27 }
28 }
29 }
30}
31
32#[cfg(test)]
33mod test;