Skip to content

Commit 327318b

Browse files
committed
---
yaml --- r: 124972 b: refs/heads/auto c: b3a732a h: refs/heads/master v: v3
1 parent 6c73fe7 commit 327318b

File tree

19 files changed

+643
-281
lines changed

19 files changed

+643
-281
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: e34e86d151341076556635b9bc233338d3d9898e
16+
refs/heads/auto: b3a732a3eab60862068b1006973de5924bcda9e2
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/guide.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -624,15 +624,10 @@ let x = (let y = 5i); // found `let` in ident position
624624
The compiler is telling us here that it was expecting to see the beginning of
625625
an expression, and a `let` can only begin a statement, not an expression.
626626

627-
However, assigning to a variable binding is an expression:
628-
629-
```{rust}
630-
let x;
631-
let y = x = 5i;
632-
```
633-
634-
In this case, we have an assignment expression (`x = 5`) whose value is
635-
being used as part of a `let` declaration statement (`let y = ...`).
627+
Note that assigning to an already-bound variable (e.g. `y = 5i`) is still an
628+
expression, although its value is not particularly useful. Unlike C, where an
629+
assignment evaluates to the assigned value (e.g. `5i` in the previous example),
630+
in Rust the value of an assignment is the unit type `()` (which we'll cover later).
636631

637632
The second kind of statement in Rust is the **expression statement**. Its
638633
purpose is to turn any expression into a statement. In practical terms, Rust's

branches/auto/src/libcollections/treemap.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,33 +190,38 @@ impl<K: Ord, V> TreeMap<K, V> {
190190
}
191191

192192
impl<K, V> TreeMap<K, V> {
193-
/// Return the value for which f(key) returns Equal. f is invoked
194-
/// with current key and helps to navigate the tree
193+
/// Return the value for which `f(key)` returns `Equal`. `f` is invoked
194+
/// with current key and guides tree navigation. That means `f` should
195+
/// be aware of natural ordering of the tree.
195196
///
196197
/// # Example
197198
///
198199
/// ```
199-
/// use std::ascii::StrAsciiExt;
200+
/// use collections::treemap::TreeMap;
200201
///
201-
/// let mut t = collections::treemap::TreeMap::new();
202-
/// t.insert("Content-Type", "application/xml");
203-
/// t.insert("User-Agent", "Curl-Rust/0.1");
202+
/// fn get_headers() -> TreeMap<String, String> {
203+
/// let mut result = TreeMap::new();
204+
/// result.insert("Content-Type".to_string(), "application/xml".to_string());
205+
/// result.insert("User-Agent".to_string(), "Curl-Rust/0.1".to_string());
206+
/// result
207+
/// }
204208
///
205-
/// let ua_key = "user-agent";
206-
/// let ua = t.find_with(|&k| {
207-
/// ua_key.cmp(&k.to_ascii_lower().as_slice())
209+
/// let headers = get_headers();
210+
/// let ua_key = "User-Agent";
211+
/// let ua = headers.find_with(|k| {
212+
/// ua_key.cmp(&k.as_slice())
208213
/// });
209214
///
210-
/// assert_eq!(*ua.unwrap(), "Curl-Rust/0.1");
215+
/// assert_eq!((*ua.unwrap()).as_slice(), "Curl-Rust/0.1");
211216
/// ```
212217
#[inline]
213218
pub fn find_with<'a>(&'a self, f:|&K| -> Ordering) -> Option<&'a V> {
214219
tree_find_with(&self.root, f)
215220
}
216221

217-
/// Return the value for which f(key) returns Equal. f is invoked
218-
/// with current key and helps to navigate the tree
219-
///
222+
/// Return the value for which `f(key)` returns `Equal`. `f` is invoked
223+
/// with current key and guides tree navigation. That means `f` should
224+
/// be aware of natural ordering of the tree.
220225
/// # Example
221226
///
222227
/// ```
@@ -913,14 +918,9 @@ fn split<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
913918
}
914919
}
915920

916-
// Next 2 functions have the same conventions
917-
//
918-
// The only difference is that non-mutable version uses loop instead
919-
// of recursion (performance considerations)
920-
// It seems to be impossible to avoid recursion with mutability
921-
//
922-
// So convention is that comparator is gets at input current key
923-
// and returns search_key cmp cur_key (i.e. search_key.cmp(cur_key))
921+
// Next 2 functions have the same convention: comparator gets
922+
// at input current key and returns search_key cmp cur_key
923+
// (i.e. search_key.cmp(&cur_key))
924924
fn tree_find_with<'r, K, V>(node: &'r Option<Box<TreeNode<K, V>>>,
925925
f: |&K| -> Ordering) -> Option<&'r V> {
926926
let mut current: &'r Option<Box<TreeNode<K, V>>> = node;

branches/auto/src/libcollections/trie.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use core::default::Default;
1717
use core::mem::zeroed;
1818
use core::mem;
1919
use core::uint;
20+
use std::hash::{Writer, Hash};
2021

2122
use {Collection, Mutable, Map, MutableMap, Set, MutableSet};
2223
use slice::{Items, MutItems};
@@ -40,6 +41,15 @@ pub struct TrieMap<T> {
4041
length: uint
4142
}
4243

44+
impl<T: PartialEq> PartialEq for TrieMap<T> {
45+
fn eq(&self, other: &TrieMap<T>) -> bool {
46+
self.len() == other.len() &&
47+
self.iter().zip(other.iter()).all(|(a, b)| a == b)
48+
}
49+
}
50+
51+
impl<T: Eq> Eq for TrieMap<T> {}
52+
4353
impl<T> Collection for TrieMap<T> {
4454
/// Return the number of elements in the map
4555
#[inline]
@@ -292,7 +302,16 @@ impl<T> Extendable<(uint, T)> for TrieMap<T> {
292302
}
293303
}
294304

305+
impl<S: Writer, T: Hash<S>> Hash<S> for TrieMap<T> {
306+
fn hash(&self, state: &mut S) {
307+
for elt in self.iter() {
308+
elt.hash(state);
309+
}
310+
}
311+
}
312+
295313
#[allow(missing_doc)]
314+
#[deriving(Hash, PartialEq, Eq)]
296315
pub struct TrieSet {
297316
map: TrieMap<()>
298317
}
@@ -661,6 +680,7 @@ mod test_map {
661680
use std::prelude::*;
662681
use std::iter::range_step;
663682
use std::uint;
683+
use std::hash;
664684

665685
use {MutableMap, Map};
666686
use super::{TrieMap, TrieNode, Internal, External, Nothing};
@@ -933,6 +953,41 @@ mod test_map {
933953
assert!(m_lower.iter().all(|(_, &x)| x == 0));
934954
assert!(m_upper.iter().all(|(_, &x)| x == 0));
935955
}
956+
957+
#[test]
958+
fn test_eq() {
959+
let mut a = TrieMap::new();
960+
let mut b = TrieMap::new();
961+
962+
assert!(a == b);
963+
assert!(a.insert(0, 5i));
964+
assert!(a != b);
965+
assert!(b.insert(0, 4i));
966+
assert!(a != b);
967+
assert!(a.insert(5, 19));
968+
assert!(a != b);
969+
assert!(!b.insert(0, 5));
970+
assert!(a != b);
971+
assert!(b.insert(5, 19));
972+
assert!(a == b);
973+
}
974+
975+
#[test]
976+
fn test_hash() {
977+
let mut x = TrieMap::new();
978+
let mut y = TrieMap::new();
979+
980+
assert!(hash::hash(&x) == hash::hash(&y));
981+
x.insert(1, 'a');
982+
x.insert(2, 'b');
983+
x.insert(3, 'c');
984+
985+
y.insert(3, 'c');
986+
y.insert(2, 'b');
987+
y.insert(1, 'a');
988+
989+
assert!(hash::hash(&x) == hash::hash(&y));
990+
}
936991
}
937992

938993
#[cfg(test)]

0 commit comments

Comments
 (0)