Skip to content

Commit 9a10f36

Browse files
committed
---
yaml --- r: 124966 b: refs/heads/auto c: 9e83d29 h: refs/heads/master v: v3
1 parent 7e7193c commit 9a10f36

File tree

21 files changed

+312
-602
lines changed

21 files changed

+312
-602
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: 826b8358134f909f0b8aeb4c1d67a3fdda50b4b0
16+
refs/heads/auto: 9e83d29f30046292f43e982893517f9aee47fa48
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: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,15 @@ 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-
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).
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 = ...`).
631636

632637
The second kind of statement in Rust is the **expression statement**. Its
633638
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,38 +190,33 @@ 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 guides tree navigation. That means `f` should
195-
/// be aware of natural ordering of the tree.
193+
/// Return the value for which f(key) returns Equal. f is invoked
194+
/// with current key and helps to navigate the tree
196195
///
197196
/// # Example
198197
///
199198
/// ```
200-
/// use collections::treemap::TreeMap;
199+
/// use std::ascii::StrAsciiExt;
201200
///
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-
/// }
201+
/// let mut t = collections::treemap::TreeMap::new();
202+
/// t.insert("Content-Type", "application/xml");
203+
/// t.insert("User-Agent", "Curl-Rust/0.1");
208204
///
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())
205+
/// let ua_key = "user-agent";
206+
/// let ua = t.find_with(|&k| {
207+
/// ua_key.cmp(&k.to_ascii_lower().as_slice())
213208
/// });
214209
///
215-
/// assert_eq!((*ua.unwrap()).as_slice(), "Curl-Rust/0.1");
210+
/// assert_eq!(*ua.unwrap(), "Curl-Rust/0.1");
216211
/// ```
217212
#[inline]
218213
pub fn find_with<'a>(&'a self, f:|&K| -> Ordering) -> Option<&'a V> {
219214
tree_find_with(&self.root, f)
220215
}
221216

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.
217+
/// Return the value for which f(key) returns Equal. f is invoked
218+
/// with current key and helps to navigate the tree
219+
///
225220
/// # Example
226221
///
227222
/// ```
@@ -918,9 +913,14 @@ fn split<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
918913
}
919914
}
920915

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))
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))
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: 27 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};
@@ -292,7 +293,16 @@ impl<T> Extendable<(uint, T)> for TrieMap<T> {
292293
}
293294
}
294295

296+
impl<S: Writer, T: Hash<S>> Hash<S> for TrieMap<T> {
297+
fn hash(&self, state: &mut S) {
298+
for elt in self.iter() {
299+
elt.hash(state);
300+
}
301+
}
302+
}
303+
295304
#[allow(missing_doc)]
305+
#[deriving(Hash)]
296306
pub struct TrieSet {
297307
map: TrieMap<()>
298308
}
@@ -1049,6 +1059,7 @@ mod bench_map {
10491059
mod test_set {
10501060
use std::prelude::*;
10511061
use std::uint;
1062+
use std::hash;
10521063

10531064
use {MutableSet, Set};
10541065
use super::TrieSet;
@@ -1082,4 +1093,20 @@ mod test_set {
10821093
assert!(set.contains(x));
10831094
}
10841095
}
1096+
1097+
#[test]
1098+
fn test_hash() {
1099+
let mut x = TrieSet::new();
1100+
let mut y = TrieSet::new();
1101+
1102+
x.insert(1);
1103+
x.insert(2);
1104+
x.insert(3);
1105+
1106+
y.insert(3);
1107+
y.insert(2);
1108+
y.insert(1);
1109+
1110+
assert!(hash::hash(&x) == hash::hash(&y));
1111+
}
10851112
}

0 commit comments

Comments
 (0)