Skip to content

Commit b4877d8

Browse files
committed
---
yaml --- r: 163189 b: refs/heads/snap-stage3 c: 20eaf16 h: refs/heads/master i: 163187: 167db10 v: v3
1 parent 30ed192 commit b4877d8

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 67ae3a49e4864133784cd745a9a8866889f3ae15
4+
refs/heads/snap-stage3: 20eaf168c5b40c003bd7d28fe4c071b24118410e
55
refs/heads/try: 20cbbffeefc1f35e2ea63afce7b42fbd79611d42
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libcollections/vec_map.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use core::iter;
2121
use core::iter::{Enumerate, FilterMap};
2222
use core::mem::replace;
2323

24+
use hash::{Hash, Writer};
2425
use {vec, slice};
2526
use vec::Vec;
2627

@@ -81,6 +82,19 @@ impl<V:Clone> Clone for VecMap<V> {
8182
}
8283
}
8384

85+
impl<S: Writer, V: Hash<S>> Hash<S> for VecMap<V> {
86+
fn hash(&self, state: &mut S) {
87+
// In order to not traverse the `VecMap` twice, count the elements
88+
// during iteration.
89+
let mut count: uint = 0;
90+
for elt in self.iter() {
91+
elt.hash(state);
92+
count += 1;
93+
}
94+
count.hash(state);
95+
}
96+
}
97+
8498
impl<V> VecMap<V> {
8599
/// Creates an empty `VecMap`.
86100
///
@@ -605,6 +619,7 @@ pub type MoveItems<V> =
605619
mod test_map {
606620
use std::prelude::*;
607621
use vec::Vec;
622+
use hash::hash;
608623

609624
use super::VecMap;
610625

@@ -918,6 +933,28 @@ mod test_map {
918933
assert!(a < b && a <= b);
919934
}
920935

936+
#[test]
937+
fn test_hash() {
938+
let mut x = VecMap::new();
939+
let mut y = VecMap::new();
940+
941+
assert!(hash(&x) == hash(&y));
942+
x.insert(1, 'a');
943+
x.insert(2, 'b');
944+
x.insert(3, 'c');
945+
946+
y.insert(3, 'c');
947+
y.insert(2, 'b');
948+
y.insert(1, 'a');
949+
950+
assert!(hash(&x) == hash(&y));
951+
952+
x.insert(1000, 'd');
953+
x.remove(&1000);
954+
955+
assert!(hash(&x) == hash(&y));
956+
}
957+
921958
#[test]
922959
fn test_from_iter() {
923960
let xs: Vec<(uint, char)> = vec![(1u, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')];

0 commit comments

Comments
 (0)