MCPcopy Create free account
hub / github.com/douchuan/algorithm / wmerge

Function wmerge

src/sort/merge.rs:137–163  ·  view source on GitHub ↗

merge two sorted subs xs[i, m) and xs[j...n) to working area xs[w...]

(xs: &mut [T], mut i: usize, m: usize, mut j: usize, n: usize, mut w: usize)

Source from the content-addressed store, hash-verified

135pub mod v3 {
136 // merge two sorted subs xs[i, m) and xs[j...n) to working area xs[w...]
137 fn wmerge<T>(xs: &mut [T], mut i: usize, m: usize, mut j: usize, n: usize, mut w: usize)
138 where
139 T: Ord,
140 {
141 while i < m && j < n {
142 if xs[i] < xs[j] {
143 xs.swap(w, i);
144 i += 1;
145 } else {
146 xs.swap(w, j);
147 j += 1;
148 }
149 w += 1;
150 }
151
152 while i < m {
153 xs.swap(w, i);
154 i += 1;
155 w += 1;
156 }
157
158 while j < n {
159 xs.swap(w, j);
160 j += 1;
161 w += 1;
162 }
163 }
164
165 /// sort xs[l, u), and put result to working area w.
166 /// constraint, len(w) == u - l

Callers 2

wsortFunction · 0.85
do_sortFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected