Skip to content

Register snapshot, transistion to new Hash #12492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/doc/guide-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ order.
Each `HashMap` instance has a random 128-bit key to use with a keyed hash,
making the order of a set of keys in a given hash table randomized. Rust
provides a [SipHash](https://131002.net/siphash/) implementation for any type
implementing the `IterBytes` trait.
implementing the `Hash` trait.

## Double-ended queues

Expand Down Expand Up @@ -186,12 +186,12 @@ let mut calls = 0;
let it = xs.iter().scan((), |_, x| {
calls += 1;
if *x < 3 { Some(x) } else { None }});

// the iterator will only yield 1 and 2 before returning None
// If we were to call it 5 times, calls would end up as 5, despite
// only 2 values being yielded (and therefore 3 unique calls being
// made). The fuse() adaptor can fix this.

let mut it = it.fuse();
it.next();
it.next();
Expand Down
6 changes: 3 additions & 3 deletions src/doc/po/ja/tutorial.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -4421,15 +4421,15 @@ msgstr ""
#, fuzzy
#| msgid ""
#| "The full list of derivable traits is `Eq`, `TotalEq`, `Ord`, `TotalOrd`, "
#| "`Encodable` `Decodable`, `Clone`, `DeepClone`, `IterBytes`, `Rand`, "
#| "`Encodable` `Decodable`, `Clone`, `DeepClone`, `Hash`, `Rand`, "
#| "`Zero`, and `ToStr`."
msgid ""
"The full list of derivable traits is `Eq`, `TotalEq`, `Ord`, `TotalOrd`, "
"`Encodable` `Decodable`, `Clone`, `DeepClone`, `IterBytes`, `Rand`, "
"`Encodable` `Decodable`, `Clone`, `DeepClone`, `Hash`, `Rand`, "
"`Default`, `Zero`, and `ToStr`."
msgstr ""
"実装を自動的に導出可能なトレイトは、 `Eq`, `TotalEq`, `Ord`, `TotalOrd`, "
"`Encodable` `Decodable`, `Clone`, `DeepClone`, `IterBytes`, `Rand`, `Zero`, "
"`Encodable` `Decodable`, `Clone`, `DeepClone`, `Hash`, `Rand`, `Zero`, "
"および `ToStr` です。."

#. type: Plain text
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ Supported traits for `deriving` are:
* Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`.
* Serialization: `Encodable`, `Decodable`. These require `serialize`.
* `Clone` and `DeepClone`, to perform (deep) copies.
* `IterBytes`, to iterate over the bytes in a data type.
* `Hash`, to iterate over the bytes in a data type.
* `Rand`, to create a random instance of a data type.
* `Default`, to create an empty instance of a data type.
* `Zero`, to create an zero instance of a numeric data type.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2525,7 +2525,7 @@ enum ABC { A, B, C }

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

# Crates and the module system

Expand Down
1 change: 0 additions & 1 deletion src/etc/vim/syntax/rust.vim
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ syn keyword rustTrait GenericPath Path PosixPath WindowsPath
syn keyword rustTrait RawPtr
syn keyword rustTrait Buffer Writer Reader Seek
syn keyword rustTrait Str StrVector StrSlice OwnedStr IntoMaybeOwned
syn keyword rustTrait IterBytes
syn keyword rustTrait ToStr IntoStr
syn keyword rustTrait Tuple1 Tuple2 Tuple3 Tuple4
syn keyword rustTrait Tuple5 Tuple6 Tuple7 Tuple8
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use std::num::Bitwise;

#[deriving(Clone, Eq, IterBytes, ToStr, Encodable, Decodable)]
#[deriving(Clone, Eq, Hash, ToStr, Encodable, Decodable)]
/// A specialized Set implementation to use enum types.
pub struct EnumSet<E> {
// We must maintain the invariant that no bits are set
Expand Down
25 changes: 11 additions & 14 deletions src/libcollections/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

use std::cmp::max;
use std::fmt;
use std::hash_old::Hash;
use std::hash::{Hash, Hasher, sip};
use std::iter::{FilterMap, Chain, Repeat, Zip};
use std::iter;
use std::mem::replace;
Expand All @@ -79,10 +79,7 @@ struct Bucket<K,V> {
/// hash function for internal state. This means that the order of all hash maps
/// is randomized by keying each hash map randomly on creation.
///
/// It is required that the keys implement the `Eq` and `Hash` traits, although
/// this can frequently be achieved by just implementing the `Eq` and
/// `IterBytes` traits as `Hash` is automatically implemented for types that
/// implement `IterBytes`.
/// It is required that the keys implement the `Eq` and `Hash` traits.
pub struct HashMap<K,V> {
priv k0: u64,
priv k1: u64,
Expand Down Expand Up @@ -131,14 +128,14 @@ impl<K:Hash + Eq,V> HashMap<K, V> {

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

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

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

let hash = k.hash_keyed(self.k0, self.k1) as uint;
let hash = sip::hash_with_keys(self.k0, self.k1, &k) as uint;
self.insert_internal(hash, k, v)
}

/// Removes a key from the map, returning the value at the key if the key
/// was previously in the map.
fn pop(&mut self, k: &K) -> Option<V> {
let hash = k.hash_keyed(self.k0, self.k1) as uint;
let hash = sip::hash_with_keys(self.k0, self.k1, k) as uint;
self.pop_internal(hash, k)
}
}
Expand Down Expand Up @@ -446,7 +443,7 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
self.expand();
}

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

impl<
E: Encoder,
K: Encodable<E> + Hash + IterBytes + Eq,
K: Encodable<E> + Hash + Eq,
V: Encodable<E>
> Encodable<E> for HashMap<K, V> {
fn encode(&self, e: &mut E) {
Expand All @@ -942,7 +939,7 @@ impl<

impl<
D: Decoder,
K: Decodable<D> + Hash + IterBytes + Eq,
K: Decodable<D> + Hash + Eq,
V: Decodable<D>
> Decodable<D> for HashMap<K, V> {
fn decode(d: &mut D) -> HashMap<K, V> {
Expand All @@ -960,7 +957,7 @@ impl<

impl<
S: Encoder,
T: Encodable<S> + Hash + IterBytes + Eq
T: Encodable<S> + Hash + Eq
> Encodable<S> for HashSet<T> {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
Expand All @@ -975,7 +972,7 @@ impl<

impl<
D: Decoder,
T: Decodable<D> + Hash + IterBytes + Eq
T: Decodable<D> + Hash + Eq
> Decodable<D> for HashSet<T> {
fn decode(d: &mut D) -> HashSet<T> {
d.read_seq(|d, len| {
Expand Down
16 changes: 8 additions & 8 deletions src/libcollections/lru_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//! ```

use std::container::Container;
use std::to_bytes::Cb;
use std::hash::{Hash, sip};
use std::ptr;
use std::cast;

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

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

Expand Down Expand Up @@ -93,7 +93,7 @@ impl<K, V> LruEntry<K, V> {
}
}

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

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

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

impl<K: IterBytes + Eq, V> Mutable for LruCache<K, V> {
impl<K: Hash + Eq, V> Mutable for LruCache<K, V> {
/// Clear the cache of all key-value pairs.
fn clear(&mut self) {
self.map.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#[allow(missing_doc)];

use std::cmp;
use std::hash_old::Hash;
use std::hash::Hash;
use std::io;
use std::mem;
use std::num;
Expand Down
14 changes: 7 additions & 7 deletions src/libextra/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use std::io::BufReader;
use std::cmp::Eq;
use collections::HashMap;
use std::to_bytes;
use std::hash::{Hash, sip};
use std::uint;

/// A Uniform Resource Locator (URL). A URL is a form of URI (Uniform Resource
Expand Down Expand Up @@ -855,15 +855,15 @@ impl ToStr for Path {
}
}

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

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

Expand Down
8 changes: 4 additions & 4 deletions src/libglob/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ fn list_dir_sorted(path: &Path) -> ~[Path] {
/**
* A compiled Unix shell style pattern.
*/
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes, Default)]
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash, Default)]
pub struct Pattern {
priv tokens: ~[PatternToken]
}

#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes)]
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash)]
enum PatternToken {
Char(char),
AnyChar,
Expand All @@ -179,7 +179,7 @@ enum PatternToken {
AnyExcept(~[CharSpecifier])
}

#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes)]
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash)]
enum CharSpecifier {
SingleChar(char),
CharRange(char, char)
Expand Down Expand Up @@ -490,7 +490,7 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
/**
* Configuration options to modify the behaviour of `Pattern::matches_with(..)`
*/
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes, Default)]
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash, Default)]
pub struct MatchOptions {

/**
Expand Down
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ This API is completely unstable and subject to change.
html_root_url = "http://static.rust-lang.org/doc/master")];

#[feature(macro_rules, globs, struct_variant, managed_boxes)];
#[allow(unknown_features)]; // Note: remove it after a snapshot.
#[feature(quote)];

extern crate extra;
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use middle::typeck;
use middle::astencode::vtable_decoder_helpers;

use std::u64;
use std::hash_old::Hash;
use std::hash;
use std::hash::Hash;
use std::io;
use std::io::extensions::u64_from_be_bytes;
use std::option;
Expand Down Expand Up @@ -86,7 +87,7 @@ pub fn maybe_find_item<'a>(item_id: ast::NodeId,
}
lookup_hash(items,
|a| eq_item(a, item_id),
(item_id as i64).hash())
hash::hash(&(item_id as i64)))
}

fn find_item<'a>(item_id: ast::NodeId, items: ebml::Doc<'a>) -> ebml::Doc<'a> {
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use middle;
use serialize::Encodable;
use std::cast;
use std::cell::{Cell, RefCell};
use std::hash_old::Hash;
use std::hash;
use std::hash::Hash;
use std::io::MemWriter;
use std::str;
use collections::{HashMap, HashSet};
Expand Down Expand Up @@ -1380,15 +1381,15 @@ fn encode_info_for_items(ecx: &EncodeContext,

// Path and definition ID indexing

fn create_index<T:Clone + Hash + IterBytes + 'static>(
fn create_index<T:Clone + Hash + 'static>(
index: ~[entry<T>])
-> ~[@~[entry<T>]] {
let mut buckets: ~[@RefCell<~[entry<T>]>] = ~[];
for _ in range(0u, 256u) {
buckets.push(@RefCell::new(~[]));
}
for elt in index.iter() {
let h = elt.val.hash() as uint;
let h = hash::hash(&elt.val) as uint;
let mut bucket = buckets[h % 256].borrow_mut();
bucket.get().push((*elt).clone());
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub struct BorrowStats {
//
// Note that there is no entry with derefs:3---the type of that expression
// is T, which is not a box.
#[deriving(Eq, IterBytes)]
#[deriving(Eq, Hash)]
pub struct root_map_key {
id: ast::NodeId,
derefs: uint
Expand Down Expand Up @@ -224,13 +224,13 @@ pub enum LoanCause {
RefBinding,
}

#[deriving(Eq, IterBytes)]
#[deriving(Eq, Hash)]
pub enum LoanPath {
LpVar(ast::NodeId), // `x` in doc.rs
LpExtend(@LoanPath, mc::MutabilityCategory, LoanPathElem)
}

#[deriving(Eq, IterBytes)]
#[deriving(Eq, Hash)]
pub enum LoanPathElem {
LpDeref(mc::PointerKind), // `*LV` in doc.rs
LpInterior(mc::InteriorKind) // `LV.f` in doc.rs
Expand Down
Loading