MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / new

Method new

publication/code/chapter07/tim_sort_without_gallop.rs:172–190  ·  view source on GitHub ↗
(list: &'a mut [i32], first_len: usize)

Source from the content-addressed store, hash-verified

170
171impl<'a> MergeLo<'a> {
172 unsafe fn new(list: &'a mut [i32], first_len: usize) -> Self {
173 let mut ret_val = MergeLo {
174 list_len: list.len(),
175 first_pos: 0,
176 first_len: first_len,
177 second_pos: first_len, // run1 和 run2 挨着,所以 run2 起始位置就等于 run1 长度
178 dest_pos: 0, // 排序结果写回原始集合,且从 run1 的起始位置开始写
179 list: list,
180 temp: Vec::with_capacity(first_len),
181 };
182
183 // 把 run1 复制到 temp
184 ret_val.temp.set_len(first_len);
185 for i in 0..first_len {
186 ret_val.temp[i] = ret_val.list[i];
187 }
188
189 ret_val
190 }
191
192 // 归并排序
193 fn merge(&mut self) {

Callers

nothing calls this directly

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected