Skip to content

Commit 5d237fc

Browse files
committed
---
yaml --- r: 42730 b: refs/heads/try c: fce6446 h: refs/heads/master v: v3
1 parent a3741d4 commit 5d237fc

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: 3a6849f36b84f7387e08ecbb1adda811aaa9587a
5+
refs/heads/try: fce6446e7e2683b5cfcc2a36211cec5ab2c355fa
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/libstd/cmp.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
#[forbid(deprecated_mode)];
12-
/// Additional general-purpose comparison functionality.
12+
//! Additional general-purpose comparison functionality.
1313
1414
use core::f32;
1515
use core::f64;
@@ -18,31 +18,49 @@ use core::float;
1818
const fuzzy_epsilon: float = 1.0e-6;
1919

2020
pub trait FuzzyEq {
21-
pure fn fuzzy_eq(other: &self) -> bool;
21+
pure fn fuzzy_eq(&self, other: &self) -> bool;
22+
pure fn fuzzy_eq_eps(&self, other: &self, epsilon: &self) -> bool;
2223
}
2324

2425
impl float: FuzzyEq {
25-
pure fn fuzzy_eq(other: &float) -> bool {
26-
return float::abs(self - *other) < fuzzy_epsilon;
26+
pure fn fuzzy_eq(&self, other: &float) -> bool {
27+
float::abs(*self - *other) < fuzzy_epsilon
28+
}
29+
30+
pure fn fuzzy_eq_eps(&self, other: &float, epsilon: &float) -> bool {
31+
float::abs(*self - *other) < *epsilon
2732
}
2833
}
2934

3035
impl f32: FuzzyEq {
31-
pure fn fuzzy_eq(other: &f32) -> bool {
32-
return f32::abs(self - *other) < (fuzzy_epsilon as f32);
36+
pure fn fuzzy_eq(&self, other: &f32) -> bool {
37+
f32::abs(*self - *other) < (fuzzy_epsilon as f32)
38+
}
39+
40+
pure fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool {
41+
f32::abs(*self - *other) < *epsilon
3342
}
3443
}
3544

3645
impl f64: FuzzyEq {
37-
pure fn fuzzy_eq(other: &f64) -> bool {
38-
return f64::abs(self - *other) < (fuzzy_epsilon as f64);
46+
pure fn fuzzy_eq(&self, other: &f64) -> bool {
47+
f64::abs(*self - *other) < (fuzzy_epsilon as f64)
48+
}
49+
50+
pure fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool {
51+
f64::abs(*self - *other) < *epsilon
3952
}
4053
}
4154

4255
#[test]
4356
fn test_fuzzy_equals() {
44-
assert ((&1.0).fuzzy_eq(&1.0));
45-
assert ((&1.0f32).fuzzy_eq(&1.0f32));
46-
assert ((&1.0f64).fuzzy_eq(&1.0f64));
57+
assert (&1.0).fuzzy_eq(&1.0);
58+
assert (&1.0f32).fuzzy_eq(&1.0f32);
59+
assert (&1.0f64).fuzzy_eq(&1.0f64);
4760
}
4861

62+
#[test]
63+
fn test_fuzzy_eq_eps() {
64+
assert (&1.2).fuzzy_eq_eps(&0.9, &0.5);
65+
assert !(&1.5).fuzzy_eq_eps(&0.9, &0.5);
66+
}

branches/try/src/libstd/priority_queue.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ impl <T: Ord> PriorityQueue<T> {
7676
}
7777

7878
/// Optimized version of a push followed by a pop
79-
fn push_pop(&mut self, mut item: T) -> T {
79+
fn push_pop(&mut self, item: T) -> T {
80+
let mut item = item;
8081
if !self.is_empty() && self.data[0] > item {
8182
item <-> self.data[0];
8283
self.siftdown(0);
@@ -85,7 +86,8 @@ impl <T: Ord> PriorityQueue<T> {
8586
}
8687

8788
/// Optimized version of a pop followed by a push - fails if empty
88-
fn replace(&mut self, mut item: T) -> T {
89+
fn replace(&mut self, item: T) -> T {
90+
let mut item = item;
8991
item <-> self.data[0];
9092
self.siftdown(0);
9193
item
@@ -127,8 +129,9 @@ impl <T: Ord> PriorityQueue<T> {
127129
// vector over the junk element. This reduces the constant factor
128130
// compared to using swaps, which involves twice as many moves.
129131

130-
priv fn siftup(&mut self, start: uint, mut pos: uint) {
132+
priv fn siftup(&mut self, start: uint, pos: uint) {
131133
unsafe {
134+
let mut pos = pos;
132135
let new = move *addr_of(&self.data[pos]);
133136

134137
while pos > start {
@@ -146,8 +149,9 @@ impl <T: Ord> PriorityQueue<T> {
146149
}
147150
}
148151

149-
priv fn siftdown_range(&mut self, mut pos: uint, end: uint) {
152+
priv fn siftdown_range(&mut self, pos: uint, end: uint) {
150153
unsafe {
154+
let mut pos = pos;
151155
let start = pos;
152156
let new = move *addr_of(&self.data[pos]);
153157

branches/try/src/libstd/treemap.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,9 @@ pure fn each_reverse<K: Ord, V>(node: &Option<~TreeNode<K, V>>,
572572
}
573573

574574
// Remove left horizontal link by rotating right
575-
fn skew<K: Ord, V>(mut node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
575+
fn skew<K: Ord, V>(node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
576576
if node.left.map_default(false, |x| x.level == node.level) {
577+
let mut node = node;
577578
let mut save = node.left.swap_unwrap();
578579
node.left <-> save.right; // save.right now None
579580
save.right = Some(node);
@@ -585,9 +586,10 @@ fn skew<K: Ord, V>(mut node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
585586

586587
// Remove dual horizontal link by rotating left and increasing level of
587588
// the parent
588-
fn split<K: Ord, V>(mut node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
589+
fn split<K: Ord, V>(node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
589590
if node.right.map_default(false,
590591
|x| x.right.map_default(false, |y| y.level == node.level)) {
592+
let mut node = node;
591593
let mut save = node.right.swap_unwrap();
592594
node.right <-> save.left; // save.left now None
593595
save.left = Some(node);
@@ -626,7 +628,8 @@ fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
626628
fn heir_swap<K: Ord, V>(node: &mut TreeNode<K, V>,
627629
child: &mut Option<~TreeNode<K, V>>) {
628630
// *could* be done without recursion, but it won't borrow check
629-
do child.mutate |mut child| {
631+
do child.mutate |child| {
632+
let mut child = child;
630633
if child.right.is_some() {
631634
heir_swap(&mut *node, &mut child.right);
632635
} else {
@@ -679,13 +682,15 @@ fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
679682
save.level -= 1;
680683

681684
if right_level > save.level {
682-
do save.right.mutate |mut x| { x.level = save.level; x }
685+
do save.right.mutate |x| {
686+
let mut x = x; x.level = save.level; x
687+
}
683688
}
684689

685690
save = skew(save);
686691

687-
do save.right.mutate |mut right| {
688-
right = skew(right);
692+
do save.right.mutate |right| {
693+
let mut right = skew(right);
689694
right.right.mutate(skew);
690695
right
691696
}

0 commit comments

Comments
 (0)