| 1 | //! The merge algorithm. This one can merge unequal slices, allocating an n/2 |
| 2 | //! sized temporary slice of the same type. Naturally, it can only merge slices |
| 3 | //! that are themselves already sorted. |
| 4 | |
| 5 | #[cfg(test)] |
| 6 | mod testsrust-analyzer cargo timsort 0.1.3 merge/tests/; |
| 7 | |
| 8 | use craterust-analyzer cargo timsort 0.1.3 crate/::galloprust-analyzer cargo timsort 0.1.3 gallop/::{selfrust-analyzer cargo timsort 0.1.3 gallop/, gallop_leftrust-analyzer cargo timsort 0.1.3 gallop/gallop_left()., gallop_rightrust-analyzer cargo timsort 0.1.3 gallop/gallop_right().}; |
| 9 | use craterust-analyzer cargo timsort 0.1.3 crate/::Comparatorrust-analyzer cargo timsort 0.1.3 Comparator#; |
| 10 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 11 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#; |
| 12 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/; |
| 13 | |
| 14 | /// Merge implementation switch. |
| 15 | pub(craterust-analyzer cargo timsort 0.1.3 crate/) fn mergerust-analyzer cargo timsort 0.1.3 merge/merge().<T, C: Comparatorrust-analyzer cargo timsort 0.1.3 Comparator#<T>>( |
| 16 | list: &mut [T], |
| 17 | mut first_len: usize, |
| 18 | cmp: &C, |
| 19 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), C::Errorrust-analyzer cargo timsort 0.1.3 Comparator#Error#> { |
| 20 | if first_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 21 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 22 | } |
| 23 | let (first, second) = list.split_at_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at_mut().(first_len); |
| 24 | let second_len = gallop_leftrust-analyzer cargo timsort 0.1.3 gallop/gallop_left().(first.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), second, galloprust-analyzer cargo timsort 0.1.3 gallop/::Moderust-analyzer cargo timsort 0.1.3 gallop/Mode#::Reverserust-analyzer cargo timsort 0.1.3 gallop/Mode#Reverse#, cmp)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 25 | let first_of_second = match second.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(0) { |
| 26 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => x, |
| 27 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 28 | }; |
| 29 | let first_off = gallop_rightrust-analyzer cargo timsort 0.1.3 gallop/gallop_right().(first_of_second, first, galloprust-analyzer cargo timsort 0.1.3 gallop/::Moderust-analyzer cargo timsort 0.1.3 gallop/Mode#::Forwardrust-analyzer cargo timsort 0.1.3 gallop/Mode#Forward#, cmp)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 30 | first_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().first_off; |
| 31 | if first_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 32 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 33 | } |
| 34 | |
| 35 | let nlist = &mut list[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().first_off..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#first_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().second_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`IndexMut<I>`]index_mut().; |
| 36 | if first_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().second_len { |
| 37 | merge_hirust-analyzer cargo timsort 0.1.3 merge/merge_hi().(nlist, first_len, second_len, cmp) |
| 38 | } else { |
| 39 | merge_lorust-analyzer cargo timsort 0.1.3 merge/merge_lo().(nlist, first_len, cmp) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /// The number of times any one run can win before we try galloping. |
| 44 | /// Change this during testing. |
| 45 | const MIN_GALLOPrust-analyzer cargo timsort 0.1.3 merge/MIN_GALLOP.: usize = 7; |
| 46 | |
| 47 | /// Merge implementation used when the first run is smaller than the second. |
| 48 | pub(craterust-analyzer cargo timsort 0.1.3 crate/) fn merge_lorust-analyzer cargo timsort 0.1.3 merge/merge_lo().<T, C: Comparatorrust-analyzer cargo timsort 0.1.3 Comparator#<T>>( |
| 49 | list: &mut [T], |
| 50 | first_len: usize, |
| 51 | cmp: &C, |
| 52 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), C::Errorrust-analyzer cargo timsort 0.1.3 Comparator#Error#> { |
| 53 | MergeLorust-analyzer cargo timsort 0.1.3 merge/MergeLo#::newrust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeLo<'a, T, C>`]new().(list, first_len, cmp).mergerust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeLo<'a, T, C>`]merge().() |
| 54 | } |
| 55 | |
| 56 | #[inline(always)] |
| 57 | fn md_as_innerrust-analyzer cargo timsort 0.1.3 merge/md_as_inner().<T>(x: &[ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#<T>]) -> &[T] { |
| 58 | // SAFETY: ManuallyDrop<T> is repr(transparent) over T |
| 59 | unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().(x as *const [_] as *const [T]) } |
| 60 | } |
| 61 | |
| 62 | /// Implementation of `merge_lo`. We need to have an object in order to |
| 63 | /// implement panic safety. |
| 64 | struct MergeLorust-analyzer cargo timsort 0.1.3 merge/MergeLo#<'a, T, C: Comparatorrust-analyzer cargo timsort 0.1.3 Comparator#<T>> { |
| 65 | list_lenrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list_len.: usize, |
| 66 | first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos.: usize, |
| 67 | first_lenrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_len.: usize, |
| 68 | second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos.: usize, |
| 69 | dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos.: usize, |
| 70 | listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list.: &'a mut [T], |
| 71 | tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#<T>>, |
| 72 | cmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#cmp.: &'a C, |
| 73 | } |
| 74 | impl<'a, T, C: Comparatorrust-analyzer cargo timsort 0.1.3 Comparator#<T>> MergeLorust-analyzer cargo timsort 0.1.3 merge/MergeLo#<'a, T, C> { |
| 75 | /// Constructor for a lower merge. |
| 76 | fn newrust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeLo<'a, T, C>`]new().(list: &'a mut [T], first_len: usize, cmp: &'a C) -> Selfrust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeLo<'a, T, C>`] { |
| 77 | let mut ret_val = MergeLorust-analyzer cargo timsort 0.1.3 merge/MergeLo# { |
| 78 | list_lenrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list_len.: list.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 79 | first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos.: 0, |
| 80 | first_lenrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_len., |
| 81 | second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos.: first_len, |
| 82 | dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos.: 0, |
| 83 | listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list., |
| 84 | tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(first_len), |
| 85 | cmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#cmp., |
| 86 | }; |
| 87 | // First, move the smallest run into temporary storage, leaving the |
| 88 | // original contents uninitialized. |
| 89 | unsafe { |
| 90 | ret_val.tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp..set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(first_len); |
| 91 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copy_nonoverlappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy_nonoverlapping().( |
| 92 | ret_val.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().() as *const ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#<T>, |
| 93 | ret_val.tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp..as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().(), |
| 94 | first_len, |
| 95 | ); |
| 96 | } |
| 97 | ret_val |
| 98 | } |
| 99 | /// Perform the one-by-one comparison and insertion. |
| 100 | fn mergerust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeLo<'a, T, C>`]merge().(mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), C::Errorrust-analyzer cargo timsort 0.1.3 Comparator#Error#> { |
| 101 | let cmp = self.cmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#cmp.; |
| 102 | let mut first_count = 0; |
| 103 | let mut second_count = 0; |
| 104 | while self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos. && self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.list_lenrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list_len. { |
| 105 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). (self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos. -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). self.first_lenrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_len.) == self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos.); |
| 106 | if (second_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitOr<Self>`]bitor().first_count) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().MIN_GALLOPrust-analyzer cargo timsort 0.1.3 merge/MIN_GALLOP. { |
| 107 | // One-at-a-time mode. |
| 108 | unsafe { |
| 109 | if cmp.is_gtrust-analyzer cargo timsort 0.1.3 Comparator#is_gt().( |
| 110 | self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos.), |
| 111 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos.), |
| 112 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 113 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copy_nonoverlappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy_nonoverlapping().( |
| 114 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos.), |
| 115 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos.), |
| 116 | 1, |
| 117 | ); |
| 118 | self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 119 | second_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 120 | first_count = 0; |
| 121 | } else { |
| 122 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copy_nonoverlappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy_nonoverlapping().( |
| 123 | &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos.), |
| 124 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos.), |
| 125 | 1, |
| 126 | ); |
| 127 | self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 128 | first_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 129 | second_count = 0; |
| 130 | } |
| 131 | } |
| 132 | self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 133 | } else { |
| 134 | // Galloping mode. |
| 135 | second_count = gallop_leftrust-analyzer cargo timsort 0.1.3 gallop/gallop_left().( |
| 136 | unsafe { md_as_innerrust-analyzer cargo timsort 0.1.3 merge/md_as_inner().(&self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp.).get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos.) }, |
| 137 | &self.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 138 | galloprust-analyzer cargo timsort 0.1.3 gallop/::Moderust-analyzer cargo timsort 0.1.3 gallop/Mode#::Forwardrust-analyzer cargo timsort 0.1.3 gallop/Mode#Forward#, |
| 139 | cmp, |
| 140 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 141 | unsafe { |
| 142 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy().( |
| 143 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos.), |
| 144 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos.), |
| 145 | second_count, |
| 146 | ) |
| 147 | } |
| 148 | self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().second_count; |
| 149 | self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().second_count; |
| 150 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). (self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos. -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). self.first_lenrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_len.) == self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos.); |
| 151 | if self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos. && self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.list_lenrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list_len. { |
| 152 | first_count = gallop_rightrust-analyzer cargo timsort 0.1.3 gallop/gallop_right().( |
| 153 | unsafe { self.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#second_pos.) }, |
| 154 | md_as_innerrust-analyzer cargo timsort 0.1.3 merge/md_as_inner().(&self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().), |
| 155 | galloprust-analyzer cargo timsort 0.1.3 gallop/::Moderust-analyzer cargo timsort 0.1.3 gallop/Mode#::Forwardrust-analyzer cargo timsort 0.1.3 gallop/Mode#Forward#, |
| 156 | cmp, |
| 157 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 158 | unsafe { |
| 159 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copy_nonoverlappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy_nonoverlapping().( |
| 160 | md_as_innerrust-analyzer cargo timsort 0.1.3 merge/md_as_inner().(&self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp.).get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos.), |
| 161 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos.), |
| 162 | first_count, |
| 163 | ) |
| 164 | }; |
| 165 | self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().first_count; |
| 166 | self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().first_count; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 171 | } |
| 172 | } |
| 173 | impl<'a, T, C: Comparatorrust-analyzer cargo timsort 0.1.3 Comparator#<T>> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for MergeLorust-analyzer cargo timsort 0.1.3 merge/MergeLo#<'a, T, C> { |
| 174 | /// Copy all remaining items in the temporary storage into the list. |
| 175 | /// If the comparator panics, the result will not be sorted, but will still |
| 176 | /// contain no duplicates or uninitialized spots. |
| 177 | fn droprust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeLo<'a, T, C>`][Drop]drop().(&mut self) { |
| 178 | unsafe { |
| 179 | // Make sure that the entire tmp storage is consumed. Since there are no uninitialized |
| 180 | // spaces before dest_pos, and no uninitialized space after first_pos, this will ensure |
| 181 | // that there are no uninitialized spaces inside the slice after we drop. Thus, the |
| 182 | // function is safe. |
| 183 | if self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.first_lenrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_len. { |
| 184 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copy_nonoverlappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy_nonoverlapping().( |
| 185 | self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos.) as *const _ as *const T, |
| 186 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeLo#list..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#dest_pos.), |
| 187 | self.first_lenrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeLo#first_pos., |
| 188 | ); |
| 189 | } |
| 190 | // The temporary storage is now full of nothing but uninitialized. |
| 191 | // We want to deallocate the space, but not call the destructors. |
| 192 | self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeLo#tmp..set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(0); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /// Merge implementation used when the first run is larger than the second. |
| 198 | pub(craterust-analyzer cargo timsort 0.1.3 crate/) fn merge_hirust-analyzer cargo timsort 0.1.3 merge/merge_hi().<T, C: Comparatorrust-analyzer cargo timsort 0.1.3 Comparator#<T>>( |
| 199 | list: &mut [T], |
| 200 | first_len: usize, |
| 201 | second_len: usize, |
| 202 | cmp: &C, |
| 203 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), C::Errorrust-analyzer cargo timsort 0.1.3 Comparator#Error#> { |
| 204 | MergeHirust-analyzer cargo timsort 0.1.3 merge/MergeHi#::newrust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeHi<'a, T, C>`]new().(list, first_len, second_len, cmp).mergerust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeHi<'a, T, C>`]merge().() |
| 205 | } |
| 206 | |
| 207 | /// Implementation of `merge_hi`. We need to have an object in order to |
| 208 | /// implement panic safety. |
| 209 | struct MergeHirust-analyzer cargo timsort 0.1.3 merge/MergeHi#<'a, T, C: Comparatorrust-analyzer cargo timsort 0.1.3 Comparator#<T>> { |
| 210 | first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos.: isize, |
| 211 | second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos.: isize, |
| 212 | dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos.: isize, |
| 213 | listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list.: &'a mut [T], |
| 214 | tmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#tmp.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#<T>>, |
| 215 | cmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#cmp.: &'a C, |
| 216 | } |
| 217 | |
| 218 | impl<'a, T, C: Comparatorrust-analyzer cargo timsort 0.1.3 Comparator#<T>> MergeHirust-analyzer cargo timsort 0.1.3 merge/MergeHi#<'a, T, C> { |
| 219 | /// Constructor for a higher merge. |
| 220 | fn newrust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeHi<'a, T, C>`]new().(list: &'a mut [T], first_len: usize, second_len: usize, cmp: &'a C) -> Selfrust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeHi<'a, T, C>`] { |
| 221 | let mut ret_val = MergeHirust-analyzer cargo timsort 0.1.3 merge/MergeHi# { |
| 222 | first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos.: first_len as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().1, |
| 223 | second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos.: second_len as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().1, |
| 224 | dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos.: list.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().1, |
| 225 | listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list., |
| 226 | tmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#tmp.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(second_len), |
| 227 | cmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#cmp., |
| 228 | }; |
| 229 | // First, move the smallest run into temporary storage, leaving the |
| 230 | // original contents uninitialized. |
| 231 | unsafe { |
| 232 | ret_val.tmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#tmp..set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(second_len); |
| 233 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copy_nonoverlappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy_nonoverlapping().( |
| 234 | ret_val.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().().addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]add().(first_len), |
| 235 | ret_val.tmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#tmp..as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().() as *mut T, |
| 236 | second_len, |
| 237 | ); |
| 238 | } |
| 239 | ret_val |
| 240 | } |
| 241 | /// Perform the one-by-one comparison and insertion. |
| 242 | fn mergerust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeHi<'a, T, C>`]merge().(mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), C::Errorrust-analyzer cargo timsort 0.1.3 Comparator#Error#> { |
| 243 | let cmp = self.cmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#cmp.; |
| 244 | let mut first_count: usize = 0; |
| 245 | let mut second_count: usize = 0; |
| 246 | while self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos. && self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().0 { |
| 247 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). 1 == self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos.); |
| 248 | if (second_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitOr<Self>`]bitor().first_count) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().MIN_GALLOPrust-analyzer cargo timsort 0.1.3 merge/MIN_GALLOP. { |
| 249 | // One-at-a-time mode. |
| 250 | unsafe { |
| 251 | if cmp.is_gtrust-analyzer cargo timsort 0.1.3 Comparator#is_gt().( |
| 252 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. as usize), |
| 253 | self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#tmp..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. as usize), |
| 254 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 255 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copy_nonoverlappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy_nonoverlapping().( |
| 256 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. as usize), |
| 257 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos. as usize), |
| 258 | 1, |
| 259 | ); |
| 260 | self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().1; |
| 261 | } else { |
| 262 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copy_nonoverlappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy_nonoverlapping().( |
| 263 | md_as_innerrust-analyzer cargo timsort 0.1.3 merge/md_as_inner().(&self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#tmp.).get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. as usize), |
| 264 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos. as usize), |
| 265 | 1, |
| 266 | ); |
| 267 | self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().1; |
| 268 | } |
| 269 | } |
| 270 | self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().1; |
| 271 | } else { |
| 272 | // Galloping mode. |
| 273 | first_count = self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 |
| 274 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().gallop_rightrust-analyzer cargo timsort 0.1.3 gallop/gallop_right().( |
| 275 | unsafe { md_as_innerrust-analyzer cargo timsort 0.1.3 merge/md_as_inner().(&self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#tmp.).get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. as usize) }, |
| 276 | &self.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeToInclusive#self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 277 | galloprust-analyzer cargo timsort 0.1.3 gallop/::Moderust-analyzer cargo timsort 0.1.3 gallop/Mode#::Reverserust-analyzer cargo timsort 0.1.3 gallop/Mode#Reverse#, |
| 278 | cmp, |
| 279 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 280 | unsafe { |
| 281 | copy_backwardsrust-analyzer cargo timsort 0.1.3 merge/copy_backwards().( |
| 282 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. as usize), |
| 283 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos. as usize), |
| 284 | first_count, |
| 285 | ) |
| 286 | } |
| 287 | self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().first_count as isize; |
| 288 | self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().first_count as isize; |
| 289 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). 1 == self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos.); |
| 290 | if self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos. && self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().0 { |
| 291 | second_count = self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 |
| 292 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().gallop_leftrust-analyzer cargo timsort 0.1.3 gallop/gallop_left().( |
| 293 | unsafe { self.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list..get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.first_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#first_pos. as usize) }, |
| 294 | md_as_innerrust-analyzer cargo timsort 0.1.3 merge/md_as_inner().(&self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#tmp.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeToInclusive#self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. as usize]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().), |
| 295 | galloprust-analyzer cargo timsort 0.1.3 gallop/::Moderust-analyzer cargo timsort 0.1.3 gallop/Mode#::Reverserust-analyzer cargo timsort 0.1.3 gallop/Mode#Reverse#, |
| 296 | cmp, |
| 297 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 298 | unsafe { |
| 299 | copy_nonoverlapping_backwardsrust-analyzer cargo timsort 0.1.3 merge/copy_nonoverlapping_backwards().( |
| 300 | md_as_innerrust-analyzer cargo timsort 0.1.3 merge/md_as_inner().(&self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#tmp.).get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. as usize), |
| 301 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos. as usize), |
| 302 | second_count, |
| 303 | ) |
| 304 | } |
| 305 | self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().second_count as isize; |
| 306 | self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().second_count as isize; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | /// Perform a backwards `ptr::copy_nonoverlapping`. Behave identically when size = 1, but behave |
| 315 | /// differently all other times |
| 316 | unsafe fn copy_backwardsrust-analyzer cargo timsort 0.1.3 merge/copy_backwards().<T>(src: *const T, dest: *mut T, size: usize) { |
| 317 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy().( |
| 318 | src.subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]sub().(size.wrapping_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]wrapping_sub().(1)), |
| 319 | dest.subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]sub().(size.wrapping_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]wrapping_sub().(1)), |
| 320 | size, |
| 321 | ) |
| 322 | } |
| 323 | |
| 324 | /// Perform a backwards `ptr::copy_nonoverlapping`. Behave identically when size = 1, but behave |
| 325 | /// differently all other times |
| 326 | unsafe fn copy_nonoverlapping_backwardsrust-analyzer cargo timsort 0.1.3 merge/copy_nonoverlapping_backwards().<T>(src: *const T, dest: *mut T, size: usize) { |
| 327 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copy_nonoverlappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy_nonoverlapping().( |
| 328 | src.subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]sub().(size.wrapping_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]wrapping_sub().(1)), |
| 329 | dest.subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]sub().(size.wrapping_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]wrapping_sub().(1)), |
| 330 | size, |
| 331 | ) |
| 332 | } |
| 333 | |
| 334 | impl<'a, T, C: Comparatorrust-analyzer cargo timsort 0.1.3 Comparator#<T>> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for MergeHirust-analyzer cargo timsort 0.1.3 merge/MergeHi#<'a, T, C> { |
| 335 | /// Copy all remaining items in the temporary storage into the list. |
| 336 | /// If the comparator panics, the result will not be sorted, but will still |
| 337 | /// contain no duplicates or uninitialized spots. |
| 338 | fn droprust-analyzer cargo timsort 0.1.3 merge/impl#[`MergeHi<'a, T, C>`][Drop]drop().(&mut self) { |
| 339 | unsafe { |
| 340 | // Make sure that the entire tmp storage is consumed. Since there are no uninitialized |
| 341 | // spaces before dest_pos, and no uninitialized space after first_pos, this will ensure |
| 342 | // that there are no uninitialized spaces inside the slice after we drop. Thus, the |
| 343 | // function is safe. |
| 344 | if self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().0 { |
| 345 | copy_nonoverlapping_backwardsrust-analyzer cargo timsort 0.1.3 merge/copy_nonoverlapping_backwards().( |
| 346 | md_as_innerrust-analyzer cargo timsort 0.1.3 merge/md_as_inner().(&self.tmprust-analyzer cargo timsort 0.1.3 merge/MergeHi#tmp.).get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. as usize), |
| 347 | self.listrust-analyzer cargo timsort 0.1.3 merge/MergeHi#list..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(self.dest_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#dest_pos. as usize), |
| 348 | self.second_posrust-analyzer cargo timsort 0.1.3 merge/MergeHi#second_pos. as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, |
| 349 | ); |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | } |