Skip to content

Commit

Permalink
Remove and comment out more MergeState code
Browse files Browse the repository at this point in the history
  • Loading branch information
14427 committed Oct 25, 2012
1 parent 046460c commit 8e6d209
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/libstd/sort.rs
Expand Up @@ -353,17 +353,17 @@ struct RunState {

struct MergeState<T> {
mut min_gallop: uint,
mut mergePt: uint,
mut tmpPt: uint,
//mut mergePt: uint,
//mut tmpPt: uint,
mut array: &[mut T],
runs: DVec<RunState>,
}

fn MergeState<T>() -> MergeState<T> {
MergeState {
min_gallop: MIN_GALLOP,
mergePt: 0,
tmpPt: 0,
//mergePt: 0,
//tmpPt: 0,
array: &[mut],
runs: DVec(),
}
Expand Down Expand Up @@ -427,13 +427,13 @@ impl<T: Copy Ord> MergeState<T> {
}

let slice = vec::mut_view(array, b1, b1+l1);
self.mergePt = b1;
//self.mergePt = b1;
let k = gallop_right(&const array[b2], slice, 0);
b1 += k;
l1 -= k;
if l1 != 0 {
let slice = vec::mut_view(array, b2, b2+l2);
self.mergePt = b2;
//self.mergePt = b2;
let l2 = gallop_left(
&const array[b1+l1-1],slice,l2-1);
if l2 > 0 {
Expand All @@ -446,16 +446,16 @@ impl<T: Copy Ord> MergeState<T> {
}
}
self.runs.pop();
self.mergePt = 0;
//self.mergePt = 0;
}

fn merge_lo(&self, array: &[mut T], base1: uint, len1: uint,
base2: uint, len2: uint) {
assert len1 != 0 && len2 != 0 && base1+len1 == base2;

let tmp = vec::to_mut(vec::slice(array, base1, base1+len1));
self.tmpPt = 0;
self.mergePt = base1;
//self.tmpPt = 0;
//self.mergePt = base1;

let mut c1 = 0;
let mut c2 = base2;
Expand All @@ -465,7 +465,7 @@ impl<T: Copy Ord> MergeState<T> {

array[dest] <-> array[c2];
dest += 1; c2 += 1; len2 -= 1;
self.mergePt += 1;
//self.mergePt += 1;

if len2 == 0 {
copy_vec(array, dest, tmp, 0, len1);
Expand All @@ -488,16 +488,16 @@ impl<T: Copy Ord> MergeState<T> {
if array[c2] < tmp[c1] {
array[dest] <-> array[c2];
dest += 1; c2 += 1; len2 -= 1;
self.mergePt += 1;
//self.mergePt += 1;
count2 += 1; count1 = 0;
if len2 == 0 {
break_outer = true;
}
} else {
array[dest] <-> tmp[c1];
dest += 1; c1 += 1; len1 -= 1;
self.mergePt += 1;
self.tmpPt += 1;
//self.mergePt += 1;
//self.tmpPt += 1;
count1 += 1; count2 = 0;
if len1 == 1 {
break_outer = true;
Expand All @@ -519,25 +519,25 @@ impl<T: Copy Ord> MergeState<T> {
if count1 != 0 {
copy_vec(array, dest, tmp, c1, count1);
dest += count1; c1 += count1; len1 -= count1;
self.mergePt += count1; self.tmpPt += count1;
//self.mergePt += count1; self.tmpPt += count1;
if len1 <= 1 { break_outer = true; break; }
}
array[dest] <-> array[c2];
dest += 1; c2 += 1; len2 -= 1;
self.mergePt += 1;
//self.mergePt += 1;
if len2 == 0 { break_outer = true; break; }

let tmp_view = vec::const_view(array, c2, c2+len2);
count2 = gallop_left(&const tmp[c1], tmp_view, 0);
if count2 != 0 {
copy_vec(array, dest, array, c2, count2);
dest += count2; c2 += count2; len2 -= count2;
self.mergePt += count2;
//self.mergePt += count2;
if len2 == 0 { break_outer = true; break; }
}
array[dest] <-> tmp[c1];
dest += 1; c1 += 1; len1 -= 1;
self.mergePt += 1; self.tmpPt += 1;
//self.mergePt += 1; self.tmpPt += 1;
if len1 == 1 { break_outer = true; break; }
min_gallop -= 1;
if !(count1 >= MIN_GALLOP || count2 >= MIN_GALLOP) {
Expand All @@ -561,7 +561,7 @@ impl<T: Copy Ord> MergeState<T> {
assert len1 > 1;
copy_vec(array, dest, tmp, c1, len1);
}
self.tmpPt = 0;
//self.tmpPt = 0;
}

fn merge_hi(&self, array: &[mut T], base1: uint, len1: uint,
Expand All @@ -576,8 +576,8 @@ impl<T: Copy Ord> MergeState<T> {
let mut len1 = len1;
let mut len2 = len2;

self.mergePt = dest;
self.tmpPt = len2 - 1;
//self.mergePt = dest;
//self.tmpPt = len2 - 1;

array[dest] <-> array[c1];
dest -= 1; c1 -= 1; len1 -= 1;
Expand Down Expand Up @@ -605,15 +605,15 @@ impl<T: Copy Ord> MergeState<T> {
if tmp[c2] < array[c1] {
array[dest] <-> array[c1];
dest -= 1; c1 -= 1; len1 -= 1;
self.mergePt -= 1;
//self.mergePt -= 1;
count1 += 1; count2 = 0;
if len1 == 0 {
break_outer = true;
}
} else {
array[dest] <-> tmp[c2];
dest -= 1; c2 -= 1; len2 -= 1;
self.mergePt -= 1; self.tmpPt -= 1;
//self.mergePt -= 1; self.tmpPt -= 1;
count2 += 1; count1 = 0;
if len2 == 1 {
break_outer = true;
Expand All @@ -635,28 +635,28 @@ impl<T: Copy Ord> MergeState<T> {

if count1 != 0 {
dest -= count1; c1 -= count1; len1 -= count1;
self.mergePt -= count1;
//self.mergePt -= count1;
copy_vec(array, dest+1, array, c1+1, count1);
if len1 == 0 { break_outer = true; break; }
}

array[dest] <-> tmp[c2];
dest -= 1; c2 -= 1; len2 -= 1;
self.mergePt -= 1; self.tmpPt -= 1;
//self.mergePt -= 1; self.tmpPt -= 1;
if len2 == 1 { break_outer = true; break; }

//let tmp_view = vec::mut_view(tmp, 0, len2);
let count2 = len2 - gallop_left(&const array[c1],
vec::mut_view(tmp, 0, len2), len2-1);
if count2 != 0 {
dest -= count2; c2 -= count2; len2 -= count2;
self.mergePt -= count2; self.tmpPt -= count2;
//self.mergePt -= count2; self.tmpPt -= count2;
copy_vec(array, dest+1, tmp, c2+1, count2);
if len2 <= 1 { break_outer = true; break; }
}
array[dest] <-> array[c1];
dest -= 1; c1 -= 1; len1 -= 1;
self.mergePt -= 1;
//self.mergePt -= 1;
if len1 == 0 { break_outer = true; break; }
min_gallop -= 1;
if !(count1 >= MIN_GALLOP || count2 >= MIN_GALLOP) {
Expand All @@ -683,7 +683,7 @@ impl<T: Copy Ord> MergeState<T> {
assert len2 != 0;
copy_vec(array, dest-(len2-1), tmp, 0, len2);
}
self.tmpPt = 0;
//self.tmpPt = 0;
}

fn merge_collapse(&self, array: &[mut T]) {
Expand Down Expand Up @@ -1139,7 +1139,7 @@ mod big_tests {
arr[idx] = @rng.gen_float();
}
tim_sort(arr);
isSorted(arr, 1);
isSorted(arr);

let arr = if n > 4 {
let part = vec::view(arr, 0, 4);
Expand Down

0 comments on commit 8e6d209

Please sign in to comment.