Skip to content

Commit efaf4db

Browse files
committed
Transition to new Hash, removing IterBytes and std::to_bytes.
1 parent 5444da5 commit efaf4db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+286
-1321
lines changed

src/doc/guide-container.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ order.
3838
Each `HashMap` instance has a random 128-bit key to use with a keyed hash,
3939
making the order of a set of keys in a given hash table randomized. Rust
4040
provides a [SipHash](https://131002.net/siphash/) implementation for any type
41-
implementing the `IterBytes` trait.
41+
implementing the `Hash` trait.
4242

4343
## Double-ended queues
4444

@@ -186,12 +186,12 @@ let mut calls = 0;
186186
let it = xs.iter().scan((), |_, x| {
187187
calls += 1;
188188
if *x < 3 { Some(x) } else { None }});
189-
189+
190190
// the iterator will only yield 1 and 2 before returning None
191191
// If we were to call it 5 times, calls would end up as 5, despite
192192
// only 2 values being yielded (and therefore 3 unique calls being
193193
// made). The fuse() adaptor can fix this.
194-
194+
195195
let mut it = it.fuse();
196196
it.next();
197197
it.next();

src/doc/po/ja/tutorial.md.po

+3-3
Original file line numberDiff line numberDiff line change
@@ -4421,15 +4421,15 @@ msgstr ""
44214421
#, fuzzy
44224422
#| msgid ""
44234423
#| "The full list of derivable traits is `Eq`, `TotalEq`, `Ord`, `TotalOrd`, "
4424-
#| "`Encodable` `Decodable`, `Clone`, `DeepClone`, `IterBytes`, `Rand`, "
4424+
#| "`Encodable` `Decodable`, `Clone`, `DeepClone`, `Hash`, `Rand`, "
44254425
#| "`Zero`, and `ToStr`."
44264426
msgid ""
44274427
"The full list of derivable traits is `Eq`, `TotalEq`, `Ord`, `TotalOrd`, "
4428-
"`Encodable` `Decodable`, `Clone`, `DeepClone`, `IterBytes`, `Rand`, "
4428+
"`Encodable` `Decodable`, `Clone`, `DeepClone`, `Hash`, `Rand`, "
44294429
"`Default`, `Zero`, and `ToStr`."
44304430
msgstr ""
44314431
"実装を自動的に導出可能なトレイトは、 `Eq`, `TotalEq`, `Ord`, `TotalOrd`, "
4432-
"`Encodable` `Decodable`, `Clone`, `DeepClone`, `IterBytes`, `Rand`, `Zero`, "
4432+
"`Encodable` `Decodable`, `Clone`, `DeepClone`, `Hash`, `Rand`, `Zero`, "
44334433
"および `ToStr` です。."
44344434

44354435
#. type: Plain text

src/doc/rust.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ Supported traits for `deriving` are:
20352035
* Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`.
20362036
* Serialization: `Encodable`, `Decodable`. These require `serialize`.
20372037
* `Clone` and `DeepClone`, to perform (deep) copies.
2038-
* `IterBytes`, to iterate over the bytes in a data type.
2038+
* `Hash`, to iterate over the bytes in a data type.
20392039
* `Rand`, to create a random instance of a data type.
20402040
* `Default`, to create an empty instance of a data type.
20412041
* `Zero`, to create an zero instance of a numeric data type.

src/doc/tutorial.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,7 @@ enum ABC { A, B, C }
25252525

25262526
The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,
25272527
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `DeepClone`,
2528-
`IterBytes`, `Rand`, `Default`, `Zero`, `FromPrimitive` and `Show`.
2528+
`Hash`, `Rand`, `Default`, `Zero`, `FromPrimitive` and `Show`.
25292529

25302530
# Crates and the module system
25312531

src/etc/vim/syntax/rust.vim

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ syn keyword rustTrait GenericPath Path PosixPath WindowsPath
9393
syn keyword rustTrait RawPtr
9494
syn keyword rustTrait Buffer Writer Reader Seek
9595
syn keyword rustTrait Str StrVector StrSlice OwnedStr IntoMaybeOwned
96-
syn keyword rustTrait IterBytes
9796
syn keyword rustTrait ToStr IntoStr
9897
syn keyword rustTrait Tuple1 Tuple2 Tuple3 Tuple4
9998
syn keyword rustTrait Tuple5 Tuple6 Tuple7 Tuple8

src/libcollections/enum_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
use std::num::Bitwise;
1717

18-
#[deriving(Clone, Eq, IterBytes, ToStr, Encodable, Decodable)]
18+
#[deriving(Clone, Eq, Hash, ToStr, Encodable, Decodable)]
1919
/// A specialized Set implementation to use enum types.
2020
pub struct EnumSet<E> {
2121
// We must maintain the invariant that no bits are set

src/libcollections/hashmap.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
5555
use std::cmp::max;
5656
use std::fmt;
57-
use std::hash_old::Hash;
57+
use std::hash::{Hash, Hasher, sip};
5858
use std::iter::{FilterMap, Chain, Repeat, Zip};
5959
use std::iter;
6060
use std::mem::replace;
@@ -79,10 +79,7 @@ struct Bucket<K,V> {
7979
/// hash function for internal state. This means that the order of all hash maps
8080
/// is randomized by keying each hash map randomly on creation.
8181
///
82-
/// It is required that the keys implement the `Eq` and `Hash` traits, although
83-
/// this can frequently be achieved by just implementing the `Eq` and
84-
/// `IterBytes` traits as `Hash` is automatically implemented for types that
85-
/// implement `IterBytes`.
82+
/// It is required that the keys implement the `Eq` and `Hash` traits.
8683
pub struct HashMap<K,V> {
8784
priv k0: u64,
8885
priv k1: u64,
@@ -131,14 +128,14 @@ impl<K:Hash + Eq,V> HashMap<K, V> {
131128

132129
#[inline]
133130
fn bucket_for_key(&self, k: &K) -> SearchResult {
134-
let hash = k.hash_keyed(self.k0, self.k1) as uint;
131+
let hash = sip::hash_with_keys(self.k0, self.k1, k) as uint;
135132
self.bucket_for_key_with_hash(hash, k)
136133
}
137134

138135
#[inline]
139136
fn bucket_for_key_equiv<Q:Hash + Equiv<K>>(&self, k: &Q)
140137
-> SearchResult {
141-
let hash = k.hash_keyed(self.k0, self.k1) as uint;
138+
let hash = sip::hash_with_keys(self.k0, self.k1, k) as uint;
142139
self.bucket_for_key_with_hash_equiv(hash, k)
143140
}
144141

@@ -339,14 +336,14 @@ impl<K:Hash + Eq,V> MutableMap<K, V> for HashMap<K, V> {
339336
self.expand();
340337
}
341338

342-
let hash = k.hash_keyed(self.k0, self.k1) as uint;
339+
let hash = sip::hash_with_keys(self.k0, self.k1, &k) as uint;
343340
self.insert_internal(hash, k, v)
344341
}
345342

346343
/// Removes a key from the map, returning the value at the key if the key
347344
/// was previously in the map.
348345
fn pop(&mut self, k: &K) -> Option<V> {
349-
let hash = k.hash_keyed(self.k0, self.k1) as uint;
346+
let hash = sip::hash_with_keys(self.k0, self.k1, k) as uint;
350347
self.pop_internal(hash, k)
351348
}
352349
}
@@ -446,7 +443,7 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
446443
self.expand();
447444
}
448445

449-
let hash = k.hash_keyed(self.k0, self.k1) as uint;
446+
let hash = sip::hash_with_keys(self.k0, self.k1, &k) as uint;
450447
let idx = match self.bucket_for_key_with_hash(hash, &k) {
451448
TableFull => fail!("Internal logic error"),
452449
FoundEntry(idx) => { found(&k, self.mut_value_for_bucket(idx), a); idx }
@@ -925,7 +922,7 @@ pub type SetAlgebraItems<'a, T> =
925922

926923
impl<
927924
E: Encoder,
928-
K: Encodable<E> + Hash + IterBytes + Eq,
925+
K: Encodable<E> + Hash + Eq,
929926
V: Encodable<E>
930927
> Encodable<E> for HashMap<K, V> {
931928
fn encode(&self, e: &mut E) {
@@ -942,7 +939,7 @@ impl<
942939

943940
impl<
944941
D: Decoder,
945-
K: Decodable<D> + Hash + IterBytes + Eq,
942+
K: Decodable<D> + Hash + Eq,
946943
V: Decodable<D>
947944
> Decodable<D> for HashMap<K, V> {
948945
fn decode(d: &mut D) -> HashMap<K, V> {
@@ -960,7 +957,7 @@ impl<
960957

961958
impl<
962959
S: Encoder,
963-
T: Encodable<S> + Hash + IterBytes + Eq
960+
T: Encodable<S> + Hash + Eq
964961
> Encodable<S> for HashSet<T> {
965962
fn encode(&self, s: &mut S) {
966963
s.emit_seq(self.len(), |s| {
@@ -975,7 +972,7 @@ impl<
975972

976973
impl<
977974
D: Decoder,
978-
T: Decodable<D> + Hash + IterBytes + Eq
975+
T: Decodable<D> + Hash + Eq
979976
> Decodable<D> for HashSet<T> {
980977
fn decode(d: &mut D) -> HashSet<T> {
981978
d.read_seq(|d, len| {

src/libcollections/lru_cache.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
//! ```
3939
4040
use std::container::Container;
41-
use std::to_bytes::Cb;
41+
use std::hash::{Hash, sip};
4242
use std::ptr;
4343
use std::cast;
4444

@@ -61,9 +61,9 @@ pub struct LruCache<K, V> {
6161
priv tail: *mut LruEntry<K, V>,
6262
}
6363

64-
impl<K: IterBytes> IterBytes for KeyRef<K> {
65-
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
66-
unsafe{ (*self.k).iter_bytes(lsb0, f) }
64+
impl<K: Hash> Hash for KeyRef<K> {
65+
fn hash(&self, s: &mut sip::SipState) {
66+
unsafe {(*self.k).hash(s)}
6767
}
6868
}
6969

@@ -93,7 +93,7 @@ impl<K, V> LruEntry<K, V> {
9393
}
9494
}
9595

96-
impl<K: IterBytes + Eq, V> LruCache<K, V> {
96+
impl<K: Hash + Eq, V> LruCache<K, V> {
9797
/// Create an LRU Cache that holds at most `capacity` items.
9898
pub fn new(capacity: uint) -> LruCache<K, V> {
9999
let cache = LruCache {
@@ -217,7 +217,7 @@ impl<K: IterBytes + Eq, V> LruCache<K, V> {
217217
}
218218
}
219219

220-
impl<A: ToStr + IterBytes + Eq, B: ToStr> ToStr for LruCache<A, B> {
220+
impl<A: ToStr + Hash + Eq, B: ToStr> ToStr for LruCache<A, B> {
221221
/// Return a string that lists the key-value pairs from most-recently
222222
/// used to least-recently used.
223223
#[inline]
@@ -250,14 +250,14 @@ impl<A: ToStr + IterBytes + Eq, B: ToStr> ToStr for LruCache<A, B> {
250250
}
251251
}
252252

253-
impl<K: IterBytes + Eq, V> Container for LruCache<K, V> {
253+
impl<K: Hash + Eq, V> Container for LruCache<K, V> {
254254
/// Return the number of key-value pairs in the cache.
255255
fn len(&self) -> uint {
256256
self.map.len()
257257
}
258258
}
259259

260-
impl<K: IterBytes + Eq, V> Mutable for LruCache<K, V> {
260+
impl<K: Hash + Eq, V> Mutable for LruCache<K, V> {
261261
/// Clear the cache of all key-value pairs.
262262
fn clear(&mut self) {
263263
self.map.clear();

src/libextra/stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#[allow(missing_doc)];
1212

1313
use std::cmp;
14-
use std::hash_old::Hash;
14+
use std::hash::Hash;
1515
use std::io;
1616
use std::mem;
1717
use std::num;

src/libextra/url.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use std::io::BufReader;
1616
use std::cmp::Eq;
1717
use collections::HashMap;
18-
use std::to_bytes;
18+
use std::hash::{Hash, sip};
1919
use std::uint;
2020

2121
/// A Uniform Resource Locator (URL). A URL is a form of URI (Uniform Resource
@@ -855,15 +855,15 @@ impl ToStr for Path {
855855
}
856856
}
857857

858-
impl IterBytes for Url {
859-
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
860-
self.to_str().iter_bytes(lsb0, f)
858+
impl Hash for Url {
859+
fn hash(&self, s: &mut sip::SipState) {
860+
self.to_str().hash(s)
861861
}
862862
}
863863

864-
impl IterBytes for Path {
865-
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
866-
self.to_str().iter_bytes(lsb0, f)
864+
impl Hash for Path {
865+
fn hash(&self, s: &mut sip::SipState) {
866+
self.to_str().hash(s)
867867
}
868868
}
869869

src/libglob/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ fn list_dir_sorted(path: &Path) -> ~[Path] {
165165
/**
166166
* A compiled Unix shell style pattern.
167167
*/
168-
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes, Default)]
168+
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash, Default)]
169169
pub struct Pattern {
170170
priv tokens: ~[PatternToken]
171171
}
172172

173-
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes)]
173+
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash)]
174174
enum PatternToken {
175175
Char(char),
176176
AnyChar,
@@ -179,7 +179,7 @@ enum PatternToken {
179179
AnyExcept(~[CharSpecifier])
180180
}
181181

182-
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes)]
182+
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash)]
183183
enum CharSpecifier {
184184
SingleChar(char),
185185
CharRange(char, char)
@@ -490,7 +490,7 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
490490
/**
491491
* Configuration options to modify the behaviour of `Pattern::matches_with(..)`
492492
*/
493-
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes, Default)]
493+
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash, Default)]
494494
pub struct MatchOptions {
495495

496496
/**

src/librustc/metadata/decoder.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ use middle::typeck;
2727
use middle::astencode::vtable_decoder_helpers;
2828

2929
use std::u64;
30-
use std::hash_old::Hash;
30+
use std::hash;
31+
use std::hash::Hash;
3132
use std::io;
3233
use std::io::extensions::u64_from_be_bytes;
3334
use std::option;
@@ -86,7 +87,7 @@ pub fn maybe_find_item<'a>(item_id: ast::NodeId,
8687
}
8788
lookup_hash(items,
8889
|a| eq_item(a, item_id),
89-
(item_id as i64).hash())
90+
hash::hash(&(item_id as i64)))
9091
}
9192

9293
fn find_item<'a>(item_id: ast::NodeId, items: ebml::Doc<'a>) -> ebml::Doc<'a> {

src/librustc/metadata/encoder.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ use middle;
2626
use serialize::Encodable;
2727
use std::cast;
2828
use std::cell::{Cell, RefCell};
29-
use std::hash_old::Hash;
29+
use std::hash;
30+
use std::hash::Hash;
3031
use std::io::MemWriter;
3132
use std::str;
3233
use collections::{HashMap, HashSet};
@@ -1380,15 +1381,15 @@ fn encode_info_for_items(ecx: &EncodeContext,
13801381

13811382
// Path and definition ID indexing
13821383

1383-
fn create_index<T:Clone + Hash + IterBytes + 'static>(
1384+
fn create_index<T:Clone + Hash + 'static>(
13841385
index: ~[entry<T>])
13851386
-> ~[@~[entry<T>]] {
13861387
let mut buckets: ~[@RefCell<~[entry<T>]>] = ~[];
13871388
for _ in range(0u, 256u) {
13881389
buckets.push(@RefCell::new(~[]));
13891390
}
13901391
for elt in index.iter() {
1391-
let h = elt.val.hash() as uint;
1392+
let h = hash::hash(&elt.val) as uint;
13921393
let mut bucket = buckets[h % 256].borrow_mut();
13931394
bucket.get().push((*elt).clone());
13941395
}

src/librustc/middle/borrowck/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub struct BorrowStats {
186186
//
187187
// Note that there is no entry with derefs:3---the type of that expression
188188
// is T, which is not a box.
189-
#[deriving(Eq, IterBytes)]
189+
#[deriving(Eq, Hash)]
190190
pub struct root_map_key {
191191
id: ast::NodeId,
192192
derefs: uint
@@ -224,13 +224,13 @@ pub enum LoanCause {
224224
RefBinding,
225225
}
226226

227-
#[deriving(Eq, IterBytes)]
227+
#[deriving(Eq, Hash)]
228228
pub enum LoanPath {
229229
LpVar(ast::NodeId), // `x` in doc.rs
230230
LpExtend(@LoanPath, mc::MutabilityCategory, LoanPathElem)
231231
}
232232

233-
#[deriving(Eq, IterBytes)]
233+
#[deriving(Eq, Hash)]
234234
pub enum LoanPathElem {
235235
LpDeref(mc::PointerKind), // `*LV` in doc.rs
236236
LpInterior(mc::InteriorKind) // `LV.f` in doc.rs

0 commit comments

Comments
 (0)