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

Function gallop_left

publication/code/chapter07/tim_sort.rs:46–64  ·  view source on GitHub ↗

找到 run1 末尾元素在 run2 中的位置

(key: &i32, list: &[i32], mode: Mode)

Source from the content-addressed store, hash-verified

44
45// 找到 run1 末尾元素在 run2 中的位置
46fn gallop_left(key: &i32, list: &[i32], mode: Mode) -> usize {
47 let (mut base, mut lim) = gallop(key, list, mode);
48
49 while lim != 0 {
50 let ix = base + lim / 2;
51 if &list[ix] < key {
52 base = ix + 1;
53 lim -= 1;
54 } else if &list[ix] == key {
55 if ix == 0 || &list[ix - 1] < key {
56 base = ix;
57 break;
58 }
59 }
60 lim /= 2;
61 }
62
63 base
64}
65
66// 找到 run2 首部元素在 run1 中的位置
67fn gallop_right(key: &i32, list: &[i32], mode: Mode) -> usize {

Callers 2

merge_sortFunction · 0.85
mergeMethod · 0.85

Calls 1

gallopFunction · 0.85

Tested by

no test coverage detected