diff --git a/doc/rust.md b/doc/rust.md index c6dba96267679..64f0dc93e7867 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -441,7 +441,7 @@ expression context, the final namespace qualifier is omitted. Two examples of paths with type arguments: ~~~~ -# use core::hashmap::linear::LinearMap; +# use core::hashmap::LinearMap; # fn f() { # fn id(t: T) -> T { t } type t = LinearMap; // Type arguments used in a type expression diff --git a/doc/tutorial.md b/doc/tutorial.md index 42b0d5a585aee..8c5294767c26a 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1888,7 +1888,7 @@ illegal to copy and pass by value. Generic `type`, `struct`, and `enum` declarations follow the same pattern: ~~~~ -# use core::hashmap::linear::LinearMap; +# use core::hashmap::LinearMap; type Set = LinearMap; struct Stack { diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index 2f35c1e0bb15e..46f2ad76d0792 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -43,7 +43,7 @@ use io; use libc::{size_t, uintptr_t}; use option::{None, Option, Some}; use ptr; -use hashmap::linear::LinearSet; +use hashmap::LinearSet; use stackwalk; use sys; diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index 9387ec4f43209..67942abba4633 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -13,1013 +13,1009 @@ //! The tables use a keyed hash with new random keys generated for each container, so the ordering //! of a set of keys in a hash table is randomized. -/// Open addressing with linear probing. -pub mod linear { - use container::{Container, Mutable, Map, Set}; - use cmp::{Eq, Equiv}; - use hash::Hash; - use to_bytes::IterBytes; - use iter::BaseIter; - use hash::Hash; - use iter; - use option::{None, Option, Some}; - use rand::RngUtil; - use rand; - use uint; - use vec; - use util::unreachable; +use container::{Container, Mutable, Map, Set}; +use cmp::{Eq, Equiv}; +use hash::Hash; +use to_bytes::IterBytes; +use iter::BaseIter; +use hash::Hash; +use iter; +use option::{None, Option, Some}; +use rand::RngUtil; +use rand; +use uint; +use vec; +use util::unreachable; + +static INITIAL_CAPACITY: uint = 32u; // 2^5 + +struct Bucket { + hash: uint, + key: K, + value: V, +} - static INITIAL_CAPACITY: uint = 32u; // 2^5 +pub struct LinearMap { + priv k0: u64, + priv k1: u64, + priv resize_at: uint, + priv size: uint, + priv buckets: ~[Option>], +} - struct Bucket { - hash: uint, - key: K, - value: V, - } +// We could rewrite FoundEntry to have type Option<&Bucket> +// which would be nifty +enum SearchResult { + FoundEntry(uint), FoundHole(uint), TableFull +} - pub struct LinearMap { - priv k0: u64, - priv k1: u64, - priv resize_at: uint, - priv size: uint, - priv buckets: ~[Option>], - } +#[inline(always)] +fn resize_at(capacity: uint) -> uint { + ((capacity as float) * 3. / 4.) as uint +} - // We could rewrite FoundEntry to have type Option<&Bucket> - // which would be nifty - enum SearchResult { - FoundEntry(uint), FoundHole(uint), TableFull +pub fn linear_map_with_capacity( + initial_capacity: uint) -> LinearMap { + let r = rand::task_rng(); + linear_map_with_capacity_and_keys(r.gen_u64(), r.gen_u64(), + initial_capacity) +} + +fn linear_map_with_capacity_and_keys( + k0: u64, k1: u64, + initial_capacity: uint) -> LinearMap { + LinearMap { + k0: k0, k1: k1, + resize_at: resize_at(initial_capacity), + size: 0, + buckets: vec::from_fn(initial_capacity, |_| None) } +} +priv impl LinearMap { #[inline(always)] - fn resize_at(capacity: uint) -> uint { - ((capacity as float) * 3. / 4.) as uint + fn to_bucket(&self, h: uint) -> uint { + // A good hash function with entropy spread over all of the + // bits is assumed. SipHash is more than good enough. + h % self.buckets.len() } - pub fn linear_map_with_capacity( - initial_capacity: uint) -> LinearMap { - let r = rand::task_rng(); - linear_map_with_capacity_and_keys(r.gen_u64(), r.gen_u64(), - initial_capacity) + #[inline(always)] + fn next_bucket(&self, idx: uint, len_buckets: uint) -> uint { + let n = (idx + 1) % len_buckets; + debug!("next_bucket(%?, %?) = %?", idx, len_buckets, n); + n } - fn linear_map_with_capacity_and_keys( - k0: u64, k1: u64, - initial_capacity: uint) -> LinearMap { - LinearMap { - k0: k0, k1: k1, - resize_at: resize_at(initial_capacity), - size: 0, - buckets: vec::from_fn(initial_capacity, |_| None) + #[inline(always)] + fn bucket_sequence(&self, hash: uint, + op: &fn(uint) -> bool) -> uint { + let start_idx = self.to_bucket(hash); + let len_buckets = self.buckets.len(); + let mut idx = start_idx; + loop { + if !op(idx) { + return idx; + } + idx = self.next_bucket(idx, len_buckets); + if idx == start_idx { + return start_idx; + } } } - priv impl LinearMap { - #[inline(always)] - fn to_bucket(&self, h: uint) -> uint { - // A good hash function with entropy spread over all of the - // bits is assumed. SipHash is more than good enough. - h % self.buckets.len() - } + #[inline(always)] + fn bucket_for_key(&self, k: &K) -> SearchResult { + let hash = k.hash_keyed(self.k0, self.k1) as uint; + self.bucket_for_key_with_hash(hash, k) + } - #[inline(always)] - fn next_bucket(&self, idx: uint, len_buckets: uint) -> uint { - let n = (idx + 1) % len_buckets; - debug!("next_bucket(%?, %?) = %?", idx, len_buckets, n); - n - } + #[inline(always)] + fn bucket_for_key_equiv>(&self, + k: &Q) + -> SearchResult { + let hash = k.hash_keyed(self.k0, self.k1) as uint; + self.bucket_for_key_with_hash_equiv(hash, k) + } - #[inline(always)] - fn bucket_sequence(&self, hash: uint, - op: &fn(uint) -> bool) -> uint { - let start_idx = self.to_bucket(hash); - let len_buckets = self.buckets.len(); - let mut idx = start_idx; - loop { - if !op(idx) { - return idx; - } - idx = self.next_bucket(idx, len_buckets); - if idx == start_idx { - return start_idx; - } + #[inline(always)] + fn bucket_for_key_with_hash(&self, + hash: uint, + k: &K) + -> SearchResult { + let _ = for self.bucket_sequence(hash) |i| { + match self.buckets[i] { + Some(ref bkt) => if bkt.hash == hash && *k == bkt.key { + return FoundEntry(i); + }, + None => return FoundHole(i) } - } - - #[inline(always)] - fn bucket_for_key(&self, k: &K) -> SearchResult { - let hash = k.hash_keyed(self.k0, self.k1) as uint; - self.bucket_for_key_with_hash(hash, k) - } - - #[inline(always)] - fn bucket_for_key_equiv>(&self, - k: &Q) - -> SearchResult { - let hash = k.hash_keyed(self.k0, self.k1) as uint; - self.bucket_for_key_with_hash_equiv(hash, k) - } + }; + TableFull + } - #[inline(always)] - fn bucket_for_key_with_hash(&self, - hash: uint, - k: &K) - -> SearchResult { - let _ = for self.bucket_sequence(hash) |i| { - match self.buckets[i] { - Some(ref bkt) => if bkt.hash == hash && *k == bkt.key { + #[inline(always)] + fn bucket_for_key_with_hash_equiv>(&self, + hash: uint, + k: &Q) + -> SearchResult { + let _ = for self.bucket_sequence(hash) |i| { + match self.buckets[i] { + Some(ref bkt) => { + if bkt.hash == hash && k.equiv(&bkt.key) { return FoundEntry(i); - }, - None => return FoundHole(i) - } - }; - TableFull - } - - #[inline(always)] - fn bucket_for_key_with_hash_equiv>(&self, - hash: uint, - k: &Q) - -> SearchResult { - let _ = for self.bucket_sequence(hash) |i| { - match self.buckets[i] { - Some(ref bkt) => { - if bkt.hash == hash && k.equiv(&bkt.key) { - return FoundEntry(i); - } - }, - None => return FoundHole(i) - } - }; - TableFull - } + } + }, + None => return FoundHole(i) + } + }; + TableFull + } - /// Expand the capacity of the array to the next power of two - /// and re-insert each of the existing buckets. - #[inline(always)] - fn expand(&mut self) { - let new_capacity = self.buckets.len() * 2; - self.resize(new_capacity); - } + /// Expand the capacity of the array to the next power of two + /// and re-insert each of the existing buckets. + #[inline(always)] + fn expand(&mut self) { + let new_capacity = self.buckets.len() * 2; + self.resize(new_capacity); + } - /// Expands the capacity of the array and re-insert each of the - /// existing buckets. - fn resize(&mut self, new_capacity: uint) { - let old_capacity = self.buckets.len(); - self.resize_at = resize_at(new_capacity); + /// Expands the capacity of the array and re-insert each of the + /// existing buckets. + fn resize(&mut self, new_capacity: uint) { + let old_capacity = self.buckets.len(); + self.resize_at = resize_at(new_capacity); - let mut old_buckets = vec::from_fn(new_capacity, |_| None); - self.buckets <-> old_buckets; + let mut old_buckets = vec::from_fn(new_capacity, |_| None); + self.buckets <-> old_buckets; - self.size = 0; - for uint::range(0, old_capacity) |i| { - let mut bucket = None; - bucket <-> old_buckets[i]; - self.insert_opt_bucket(bucket); - } + self.size = 0; + for uint::range(0, old_capacity) |i| { + let mut bucket = None; + bucket <-> old_buckets[i]; + self.insert_opt_bucket(bucket); } + } - fn insert_opt_bucket(&mut self, bucket: Option>) { - match bucket { - Some(Bucket{hash: hash, key: key, value: value}) => { - self.insert_internal(hash, key, value); - } - None => {} + fn insert_opt_bucket(&mut self, bucket: Option>) { + match bucket { + Some(Bucket{hash: hash, key: key, value: value}) => { + self.insert_internal(hash, key, value); } + None => {} } + } - #[inline(always)] - fn value_for_bucket(&self, idx: uint) -> &'self V { - match self.buckets[idx] { - Some(ref bkt) => &bkt.value, - None => fail!(~"LinearMap::find: internal logic error"), - } + #[inline(always)] + fn value_for_bucket(&self, idx: uint) -> &'self V { + match self.buckets[idx] { + Some(ref bkt) => &bkt.value, + None => fail!(~"LinearMap::find: internal logic error"), } + } - #[inline(always)] - fn mut_value_for_bucket(&mut self, idx: uint) -> &'self mut V { - match self.buckets[idx] { - Some(ref mut bkt) => &mut bkt.value, - None => unreachable() - } + #[inline(always)] + fn mut_value_for_bucket(&mut self, idx: uint) -> &'self mut V { + match self.buckets[idx] { + Some(ref mut bkt) => &mut bkt.value, + None => unreachable() } + } - /// Inserts the key value pair into the buckets. - /// Assumes that there will be a bucket. - /// True if there was no previous entry with that key - fn insert_internal(&mut self, hash: uint, k: K, v: V) -> bool { - match self.bucket_for_key_with_hash(hash, &k) { - TableFull => { fail!(~"Internal logic error"); } - FoundHole(idx) => { - debug!("insert fresh (%?->%?) at idx %?, hash %?", - k, v, idx, hash); - self.buckets[idx] = Some(Bucket{hash: hash, key: k, - value: v}); - self.size += 1; - true - } - FoundEntry(idx) => { - debug!("insert overwrite (%?->%?) at idx %?, hash %?", - k, v, idx, hash); - self.buckets[idx] = Some(Bucket{hash: hash, key: k, - value: v}); - false - } + /// Inserts the key value pair into the buckets. + /// Assumes that there will be a bucket. + /// True if there was no previous entry with that key + fn insert_internal(&mut self, hash: uint, k: K, v: V) -> bool { + match self.bucket_for_key_with_hash(hash, &k) { + TableFull => { fail!(~"Internal logic error"); } + FoundHole(idx) => { + debug!("insert fresh (%?->%?) at idx %?, hash %?", + k, v, idx, hash); + self.buckets[idx] = Some(Bucket{hash: hash, key: k, + value: v}); + self.size += 1; + true + } + FoundEntry(idx) => { + debug!("insert overwrite (%?->%?) at idx %?, hash %?", + k, v, idx, hash); + self.buckets[idx] = Some(Bucket{hash: hash, key: k, + value: v}); + false } } + } - fn pop_internal(&mut self, hash: uint, k: &K) -> Option { - // Removing from an open-addressed hashtable - // is, well, painful. The problem is that - // the entry may lie on the probe path for other - // entries, so removing it would make you think that - // those probe paths are empty. - // - // To address this we basically have to keep walking, - // re-inserting entries we find until we reach an empty - // bucket. We know we will eventually reach one because - // we insert one ourselves at the beginning (the removed - // entry). - // - // I found this explanation elucidating: - // http://www.maths.lse.ac.uk/Courses/MA407/del-hash.pdf - let mut idx = match self.bucket_for_key_with_hash(hash, k) { - TableFull | FoundHole(_) => return None, - FoundEntry(idx) => idx - }; - - let len_buckets = self.buckets.len(); + fn pop_internal(&mut self, hash: uint, k: &K) -> Option { + // Removing from an open-addressed hashtable + // is, well, painful. The problem is that + // the entry may lie on the probe path for other + // entries, so removing it would make you think that + // those probe paths are empty. + // + // To address this we basically have to keep walking, + // re-inserting entries we find until we reach an empty + // bucket. We know we will eventually reach one because + // we insert one ourselves at the beginning (the removed + // entry). + // + // I found this explanation elucidating: + // http://www.maths.lse.ac.uk/Courses/MA407/del-hash.pdf + let mut idx = match self.bucket_for_key_with_hash(hash, k) { + TableFull | FoundHole(_) => return None, + FoundEntry(idx) => idx + }; + + let len_buckets = self.buckets.len(); + let mut bucket = None; + self.buckets[idx] <-> bucket; + + let value = match bucket { + None => None, + Some(bucket) => { + let Bucket{value: value, _} = bucket; + Some(value) + }, + }; + + /* re-inserting buckets may cause changes in size, so remember + what our new size is ahead of time before we start insertions */ + let size = self.size - 1; + idx = self.next_bucket(idx, len_buckets); + while self.buckets[idx].is_some() { let mut bucket = None; - self.buckets[idx] <-> bucket; - - let value = match bucket { - None => None, - Some(bucket) => { - let Bucket{value: value, _} = bucket; - Some(value) - }, - }; - - /* re-inserting buckets may cause changes in size, so remember - what our new size is ahead of time before we start insertions */ - let size = self.size - 1; + bucket <-> self.buckets[idx]; + self.insert_opt_bucket(bucket); idx = self.next_bucket(idx, len_buckets); - while self.buckets[idx].is_some() { - let mut bucket = None; - bucket <-> self.buckets[idx]; - self.insert_opt_bucket(bucket); - idx = self.next_bucket(idx, len_buckets); - } - self.size = size; - - value } + self.size = size; - fn search(&self, hash: uint, - op: &fn(x: &Option>) -> bool) { - let _ = self.bucket_sequence(hash, |i| op(&self.buckets[i])); - } + value } - impl<'self,K:Hash + IterBytes + Eq,V> - BaseIter<(&'self K, &'self V)> for LinearMap { - /// Visit all key-value pairs - fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) { - for uint::range(0, self.buckets.len()) |i| { - let mut broke = false; - do self.buckets[i].map |bucket| { - if !blk(&(&bucket.key, &bucket.value)) { - broke = true; // FIXME(#3064) just write "break;" - } - }; - if broke { break; } - } + fn search(&self, hash: uint, + op: &fn(x: &Option>) -> bool) { + let _ = self.bucket_sequence(hash, |i| op(&self.buckets[i])); + } +} + +impl<'self,K:Hash + IterBytes + Eq,V> + BaseIter<(&'self K, &'self V)> for LinearMap { + /// Visit all key-value pairs + fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) { + for uint::range(0, self.buckets.len()) |i| { + let mut broke = false; + do self.buckets[i].map |bucket| { + if !blk(&(&bucket.key, &bucket.value)) { + broke = true; // FIXME(#3064) just write "break;" + } + }; + if broke { break; } } - fn size_hint(&self) -> Option { Some(self.len()) } } + fn size_hint(&self) -> Option { Some(self.len()) } +} - impl Container for LinearMap { - /// Return the number of elements in the map - fn len(&const self) -> uint { self.size } +impl Container for LinearMap { + /// Return the number of elements in the map + fn len(&const self) -> uint { self.size } - /// Return true if the map contains no elements - fn is_empty(&const self) -> bool { self.len() == 0 } - } + /// Return true if the map contains no elements + fn is_empty(&const self) -> bool { self.len() == 0 } +} - impl Mutable for LinearMap { - /// Clear the map, removing all key-value pairs. - fn clear(&mut self) { - for uint::range(0, self.buckets.len()) |idx| { - self.buckets[idx] = None; - } - self.size = 0; +impl Mutable for LinearMap { + /// Clear the map, removing all key-value pairs. + fn clear(&mut self) { + for uint::range(0, self.buckets.len()) |idx| { + self.buckets[idx] = None; } + self.size = 0; } +} - impl<'self,K:Hash + IterBytes + Eq,V> Map for LinearMap { - /// Return true if the map contains a value for the specified key - fn contains_key(&self, k: &K) -> bool { - match self.bucket_for_key(k) { - FoundEntry(_) => {true} - TableFull | FoundHole(_) => {false} - } - } - - /// Visit all keys - fn each_key(&self, blk: &fn(k: &K) -> bool) { - self.each(|&(k, _)| blk(k)) +impl<'self,K:Hash + IterBytes + Eq,V> Map for LinearMap { + /// Return true if the map contains a value for the specified key + fn contains_key(&self, k: &K) -> bool { + match self.bucket_for_key(k) { + FoundEntry(_) => {true} + TableFull | FoundHole(_) => {false} } + } - /// Visit all values - fn each_value(&self, blk: &fn(v: &V) -> bool) { - self.each(|&(_, v)| blk(v)) - } + /// Visit all keys + fn each_key(&self, blk: &fn(k: &K) -> bool) { + self.each(|&(k, _)| blk(k)) + } - /// Iterate over the map and mutate the contained values - fn mutate_values(&mut self, blk: &fn(&'self K, - &'self mut V) -> bool) { - for uint::range(0, self.buckets.len()) |i| { - match self.buckets[i] { - Some(Bucket{key: ref key, value: ref mut value, _}) => { - if !blk(key, value) { return } - } - None => () - } - } - } + /// Visit all values + fn each_value(&self, blk: &fn(v: &V) -> bool) { + self.each(|&(_, v)| blk(v)) + } - /// Return a reference to the value corresponding to the key - fn find(&self, k: &K) -> Option<&'self V> { - match self.bucket_for_key(k) { - FoundEntry(idx) => Some(self.value_for_bucket(idx)), - TableFull | FoundHole(_) => None, + /// Iterate over the map and mutate the contained values + fn mutate_values(&mut self, blk: &fn(&'self K, + &'self mut V) -> bool) { + for uint::range(0, self.buckets.len()) |i| { + match self.buckets[i] { + Some(Bucket{key: ref key, value: ref mut value, _}) => { + if !blk(key, value) { return } + } + None => () } } + } - /// Return a mutable reference to the value corresponding to the key - fn find_mut(&mut self, k: &K) -> Option<&'self mut V> { - let idx = match self.bucket_for_key(k) { - FoundEntry(idx) => idx, - TableFull | FoundHole(_) => return None - }; - unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker - Some(::cast::transmute_mut_region(self.mut_value_for_bucket(idx))) - } + /// Return a reference to the value corresponding to the key + fn find(&self, k: &K) -> Option<&'self V> { + match self.bucket_for_key(k) { + FoundEntry(idx) => Some(self.value_for_bucket(idx)), + TableFull | FoundHole(_) => None, } + } - /// Insert a key-value pair into the map. An existing value for a - /// key is replaced by the new value. Return true if the key did - /// not already exist in the map. - fn insert(&mut self, k: K, v: V) -> bool { - if self.size >= self.resize_at { - // n.b.: We could also do this after searching, so - // that we do not resize if this call to insert is - // simply going to update a key in place. My sense - // though is that it's worse to have to search through - // buckets to find the right spot twice than to just - // resize in this corner case. - self.expand(); - } - - let hash = k.hash_keyed(self.k0, self.k1) as uint; - self.insert_internal(hash, k, v) + /// Return a mutable reference to the value corresponding to the key + fn find_mut(&mut self, k: &K) -> Option<&'self mut V> { + let idx = match self.bucket_for_key(k) { + FoundEntry(idx) => idx, + TableFull | FoundHole(_) => return None + }; + unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker + Some(::cast::transmute_mut_region(self.mut_value_for_bucket(idx))) } + } - /// Remove a key-value pair from the map. Return true if the key - /// was present in the map, otherwise false. - fn remove(&mut self, k: &K) -> bool { - self.pop(k).is_some() - } + /// Insert a key-value pair into the map. An existing value for a + /// key is replaced by the new value. Return true if the key did + /// not already exist in the map. + fn insert(&mut self, k: K, v: V) -> bool { + if self.size >= self.resize_at { + // n.b.: We could also do this after searching, so + // that we do not resize if this call to insert is + // simply going to update a key in place. My sense + // though is that it's worse to have to search through + // buckets to find the right spot twice than to just + // resize in this corner case. + self.expand(); + } + + let hash = k.hash_keyed(self.k0, self.k1) as uint; + self.insert_internal(hash, k, v) } - pub impl LinearMap { - /// Create an empty LinearMap - fn new() -> LinearMap { - LinearMap::with_capacity(INITIAL_CAPACITY) - } + /// Remove a key-value pair from the map. Return true if the key + /// was present in the map, otherwise false. + fn remove(&mut self, k: &K) -> bool { + self.pop(k).is_some() + } +} - /// Create an empty LinearMap with space for at least `n` elements in - /// the hash table. - fn with_capacity(capacity: uint) -> LinearMap { - linear_map_with_capacity(capacity) - } +pub impl LinearMap { + /// Create an empty LinearMap + fn new() -> LinearMap { + LinearMap::with_capacity(INITIAL_CAPACITY) + } - /// Reserve space for at least `n` elements in the hash table. - fn reserve_at_least(&mut self, n: uint) { - if n > self.buckets.len() { - let buckets = n * 4 / 3 + 1; - self.resize(uint::next_power_of_two(buckets)); - } - } + /// Create an empty LinearMap with space for at least `n` elements in + /// the hash table. + fn with_capacity(capacity: uint) -> LinearMap { + linear_map_with_capacity(capacity) + } - fn pop(&mut self, k: &K) -> Option { - let hash = k.hash_keyed(self.k0, self.k1) as uint; - self.pop_internal(hash, k) + /// Reserve space for at least `n` elements in the hash table. + fn reserve_at_least(&mut self, n: uint) { + if n > self.buckets.len() { + let buckets = n * 4 / 3 + 1; + self.resize(uint::next_power_of_two(buckets)); } + } - fn swap(&mut self, k: K, v: V) -> Option { - // this could be faster. - let hash = k.hash_keyed(self.k0, self.k1) as uint; - let old_value = self.pop_internal(hash, &k); - - if self.size >= self.resize_at { - // n.b.: We could also do this after searching, so - // that we do not resize if this call to insert is - // simply going to update a key in place. My sense - // though is that it's worse to have to search through - // buckets to find the right spot twice than to just - // resize in this corner case. - self.expand(); - } + fn pop(&mut self, k: &K) -> Option { + let hash = k.hash_keyed(self.k0, self.k1) as uint; + self.pop_internal(hash, k) + } - self.insert_internal(hash, k, v); + fn swap(&mut self, k: K, v: V) -> Option { + // this could be faster. + let hash = k.hash_keyed(self.k0, self.k1) as uint; + let old_value = self.pop_internal(hash, &k); - old_value + if self.size >= self.resize_at { + // n.b.: We could also do this after searching, so + // that we do not resize if this call to insert is + // simply going to update a key in place. My sense + // though is that it's worse to have to search through + // buckets to find the right spot twice than to just + // resize in this corner case. + self.expand(); } - /// Return the value corresponding to the key in the map, or insert - /// and return the value if it doesn't exist. - fn find_or_insert(&mut self, k: K, v: V) -> &'self V { - if self.size >= self.resize_at { - // n.b.: We could also do this after searching, so - // that we do not resize if this call to insert is - // simply going to update a key in place. My sense - // though is that it's worse to have to search through - // buckets to find the right spot twice than to just - // resize in this corner case. - self.expand(); - } + self.insert_internal(hash, k, v); - let hash = k.hash_keyed(self.k0, self.k1) as uint; - let idx = match self.bucket_for_key_with_hash(hash, &k) { - TableFull => fail!(~"Internal logic error"), - FoundEntry(idx) => idx, - FoundHole(idx) => { - self.buckets[idx] = Some(Bucket{hash: hash, key: k, - value: v}); - self.size += 1; - idx - }, - }; + old_value + } - unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker - ::cast::transmute_region(self.value_for_bucket(idx)) - } + /// Return the value corresponding to the key in the map, or insert + /// and return the value if it doesn't exist. + fn find_or_insert(&mut self, k: K, v: V) -> &'self V { + if self.size >= self.resize_at { + // n.b.: We could also do this after searching, so + // that we do not resize if this call to insert is + // simply going to update a key in place. My sense + // though is that it's worse to have to search through + // buckets to find the right spot twice than to just + // resize in this corner case. + self.expand(); + } + + let hash = k.hash_keyed(self.k0, self.k1) as uint; + let idx = match self.bucket_for_key_with_hash(hash, &k) { + TableFull => fail!(~"Internal logic error"), + FoundEntry(idx) => idx, + FoundHole(idx) => { + self.buckets[idx] = Some(Bucket{hash: hash, key: k, + value: v}); + self.size += 1; + idx + }, + }; + + unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker + ::cast::transmute_region(self.value_for_bucket(idx)) } + } - /// Return the value corresponding to the key in the map, or create, - /// insert, and return a new value if it doesn't exist. - fn find_or_insert_with(&mut self, k: K, f: &fn(&K) -> V) -> &'self V { - if self.size >= self.resize_at { - // n.b.: We could also do this after searching, so - // that we do not resize if this call to insert is - // simply going to update a key in place. My sense - // though is that it's worse to have to search through - // buckets to find the right spot twice than to just - // resize in this corner case. - self.expand(); - } - - let hash = k.hash_keyed(self.k0, self.k1) as uint; - let idx = match self.bucket_for_key_with_hash(hash, &k) { - TableFull => fail!(~"Internal logic error"), - FoundEntry(idx) => idx, - FoundHole(idx) => { - let v = f(&k); - self.buckets[idx] = Some(Bucket{hash: hash, key: k, - value: v}); - self.size += 1; - idx - }, - }; - - unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker - ::cast::transmute_region(self.value_for_bucket(idx)) - } + /// Return the value corresponding to the key in the map, or create, + /// insert, and return a new value if it doesn't exist. + fn find_or_insert_with(&mut self, k: K, f: &fn(&K) -> V) -> &'self V { + if self.size >= self.resize_at { + // n.b.: We could also do this after searching, so + // that we do not resize if this call to insert is + // simply going to update a key in place. My sense + // though is that it's worse to have to search through + // buckets to find the right spot twice than to just + // resize in this corner case. + self.expand(); + } + + let hash = k.hash_keyed(self.k0, self.k1) as uint; + let idx = match self.bucket_for_key_with_hash(hash, &k) { + TableFull => fail!(~"Internal logic error"), + FoundEntry(idx) => idx, + FoundHole(idx) => { + let v = f(&k); + self.buckets[idx] = Some(Bucket{hash: hash, key: k, + value: v}); + self.size += 1; + idx + }, + }; + + unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker + ::cast::transmute_region(self.value_for_bucket(idx)) } + } - fn consume(&mut self, f: &fn(K, V)) { - let mut buckets = ~[]; - self.buckets <-> buckets; - self.size = 0; - - do vec::consume(buckets) |_, bucket| { - match bucket { - None => {}, - Some(bucket) => { - let Bucket{key: key, value: value, _} = bucket; - f(key, value) - } + fn consume(&mut self, f: &fn(K, V)) { + let mut buckets = ~[]; + self.buckets <-> buckets; + self.size = 0; + + do vec::consume(buckets) |_, bucket| { + match bucket { + None => {}, + Some(bucket) => { + let Bucket{key: key, value: value, _} = bucket; + f(key, value) } } } + } - fn get(&self, k: &K) -> &'self V { - match self.find(k) { - Some(v) => v, - None => fail!(fmt!("No entry found for key: %?", k)), - } + fn get(&self, k: &K) -> &'self V { + match self.find(k) { + Some(v) => v, + None => fail!(fmt!("No entry found for key: %?", k)), } + } - /// Return true if the map contains a value for the specified key, - /// using equivalence - fn contains_key_equiv>(&self, key: &Q) - -> bool { - match self.bucket_for_key_equiv(key) { - FoundEntry(_) => {true} - TableFull | FoundHole(_) => {false} - } + /// Return true if the map contains a value for the specified key, + /// using equivalence + fn contains_key_equiv>(&self, key: &Q) + -> bool { + match self.bucket_for_key_equiv(key) { + FoundEntry(_) => {true} + TableFull | FoundHole(_) => {false} } + } - /// Return the value corresponding to the key in the map, using - /// equivalence - fn find_equiv>(&self, k: &Q) - -> Option<&'self V> { - match self.bucket_for_key_equiv(k) { - FoundEntry(idx) => Some(self.value_for_bucket(idx)), - TableFull | FoundHole(_) => None, - } + /// Return the value corresponding to the key in the map, using + /// equivalence + fn find_equiv>(&self, k: &Q) + -> Option<&'self V> { + match self.bucket_for_key_equiv(k) { + FoundEntry(idx) => Some(self.value_for_bucket(idx)), + TableFull | FoundHole(_) => None, } } +} - impl Eq for LinearMap { - fn eq(&self, other: &LinearMap) -> bool { - if self.len() != other.len() { return false; } +impl Eq for LinearMap { + fn eq(&self, other: &LinearMap) -> bool { + if self.len() != other.len() { return false; } - for self.each |&(key, value)| { - match other.find(key) { - None => return false, - Some(v) => if value != v { return false }, - } + for self.each |&(key, value)| { + match other.find(key) { + None => return false, + Some(v) => if value != v { return false }, } - - true } - fn ne(&self, other: &LinearMap) -> bool { !self.eq(other) } + true } - pub struct LinearSet { - priv map: LinearMap - } + fn ne(&self, other: &LinearMap) -> bool { !self.eq(other) } +} - impl BaseIter for LinearSet { - /// Visit all values in order - fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) } - fn size_hint(&self) -> Option { Some(self.len()) } - } +pub struct LinearSet { + priv map: LinearMap +} - impl Eq for LinearSet { - fn eq(&self, other: &LinearSet) -> bool { self.map == other.map } - fn ne(&self, other: &LinearSet) -> bool { self.map != other.map } - } +impl BaseIter for LinearSet { + /// Visit all values in order + fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) } + fn size_hint(&self) -> Option { Some(self.len()) } +} - impl Container for LinearSet { - /// Return the number of elements in the set - fn len(&const self) -> uint { self.map.len() } +impl Eq for LinearSet { + fn eq(&self, other: &LinearSet) -> bool { self.map == other.map } + fn ne(&self, other: &LinearSet) -> bool { self.map != other.map } +} - /// Return true if the set contains no elements - fn is_empty(&const self) -> bool { self.map.is_empty() } - } +impl Container for LinearSet { + /// Return the number of elements in the set + fn len(&const self) -> uint { self.map.len() } - impl Mutable for LinearSet { - /// Clear the set, removing all values. - fn clear(&mut self) { self.map.clear() } - } + /// Return true if the set contains no elements + fn is_empty(&const self) -> bool { self.map.is_empty() } +} - impl Set for LinearSet { - /// Return true if the set contains a value - fn contains(&self, value: &T) -> bool { self.map.contains_key(value) } +impl Mutable for LinearSet { + /// Clear the set, removing all values. + fn clear(&mut self) { self.map.clear() } +} - /// Add a value to the set. Return true if the value was not already - /// present in the set. - fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()) } +impl Set for LinearSet { + /// Return true if the set contains a value + fn contains(&self, value: &T) -> bool { self.map.contains_key(value) } - /// Remove a value from the set. Return true if the value was - /// present in the set. - fn remove(&mut self, value: &T) -> bool { self.map.remove(value) } + /// Add a value to the set. Return true if the value was not already + /// present in the set. + fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()) } - /// Return true if the set has no elements in common with `other`. - /// This is equivalent to checking for an empty intersection. - fn is_disjoint(&self, other: &LinearSet) -> bool { - iter::all(self, |v| !other.contains(v)) - } + /// Remove a value from the set. Return true if the value was + /// present in the set. + fn remove(&mut self, value: &T) -> bool { self.map.remove(value) } - /// Return true if the set is a subset of another - fn is_subset(&self, other: &LinearSet) -> bool { - iter::all(self, |v| other.contains(v)) - } + /// Return true if the set has no elements in common with `other`. + /// This is equivalent to checking for an empty intersection. + fn is_disjoint(&self, other: &LinearSet) -> bool { + iter::all(self, |v| !other.contains(v)) + } - /// Return true if the set is a superset of another - fn is_superset(&self, other: &LinearSet) -> bool { - other.is_subset(self) - } + /// Return true if the set is a subset of another + fn is_subset(&self, other: &LinearSet) -> bool { + iter::all(self, |v| other.contains(v)) + } - /// Visit the values representing the difference - fn difference(&self, other: &LinearSet, f: &fn(&T) -> bool) { - for self.each |v| { - if !other.contains(v) { - if !f(v) { return } - } + /// Return true if the set is a superset of another + fn is_superset(&self, other: &LinearSet) -> bool { + other.is_subset(self) + } + + /// Visit the values representing the difference + fn difference(&self, other: &LinearSet, f: &fn(&T) -> bool) { + for self.each |v| { + if !other.contains(v) { + if !f(v) { return } } } + } - /// Visit the values representing the symmetric difference - fn symmetric_difference(&self, - other: &LinearSet, - f: &fn(&T) -> bool) { - self.difference(other, f); - other.difference(self, f); - } + /// Visit the values representing the symmetric difference + fn symmetric_difference(&self, + other: &LinearSet, + f: &fn(&T) -> bool) { + self.difference(other, f); + other.difference(self, f); + } - /// Visit the values representing the intersection - fn intersection(&self, other: &LinearSet, f: &fn(&T) -> bool) { - for self.each |v| { - if other.contains(v) { - if !f(v) { return } - } + /// Visit the values representing the intersection + fn intersection(&self, other: &LinearSet, f: &fn(&T) -> bool) { + for self.each |v| { + if other.contains(v) { + if !f(v) { return } } } + } - /// Visit the values representing the union - fn union(&self, other: &LinearSet, f: &fn(&T) -> bool) { - for self.each |v| { - if !f(v) { return } - } + /// Visit the values representing the union + fn union(&self, other: &LinearSet, f: &fn(&T) -> bool) { + for self.each |v| { + if !f(v) { return } + } - for other.each |v| { - if !self.contains(v) { - if !f(v) { return } - } + for other.each |v| { + if !self.contains(v) { + if !f(v) { return } } } } +} - pub impl LinearSet { - /// Create an empty LinearSet - fn new() -> LinearSet { - LinearSet::with_capacity(INITIAL_CAPACITY) - } +pub impl LinearSet { + /// Create an empty LinearSet + fn new() -> LinearSet { + LinearSet::with_capacity(INITIAL_CAPACITY) + } - /// Create an empty LinearSet with space for at least `n` elements in - /// the hash table. - fn with_capacity(capacity: uint) -> LinearSet { - LinearSet { map: LinearMap::with_capacity(capacity) } - } + /// Create an empty LinearSet with space for at least `n` elements in + /// the hash table. + fn with_capacity(capacity: uint) -> LinearSet { + LinearSet { map: LinearMap::with_capacity(capacity) } + } - /// Reserve space for at least `n` elements in the hash table. - fn reserve_at_least(&mut self, n: uint) { - self.map.reserve_at_least(n) - } + /// Reserve space for at least `n` elements in the hash table. + fn reserve_at_least(&mut self, n: uint) { + self.map.reserve_at_least(n) + } - /// Consumes all of the elements in the set, emptying it out - fn consume(&mut self, f: &fn(T)) { - self.map.consume(|k, _| f(k)) - } + /// Consumes all of the elements in the set, emptying it out + fn consume(&mut self, f: &fn(T)) { + self.map.consume(|k, _| f(k)) } +} + +#[test] +mod test_map { + use container::{Container, Map, Set}; + use option::{None, Some}; + use super::*; + use uint; #[test] - mod test_map { - use container::{Container, Map, Set}; - use option::{None, Some}; - use hashmap::linear::LinearMap; - use hashmap::linear; - use uint; - - #[test] - pub fn test_insert() { - let mut m = LinearMap::new(); - assert!(m.insert(1, 2)); - assert!(m.insert(2, 4)); - assert!(*m.get(&1) == 2); - assert!(*m.get(&2) == 4); - } + pub fn test_insert() { + let mut m = LinearMap::new(); + assert!(m.insert(1, 2)); + assert!(m.insert(2, 4)); + assert!(*m.get(&1) == 2); + assert!(*m.get(&2) == 4); + } - #[test] - fn test_find_mut() { - let mut m = LinearMap::new(); - assert!(m.insert(1, 12)); - assert!(m.insert(2, 8)); - assert!(m.insert(5, 14)); - let new = 100; - match m.find_mut(&5) { - None => fail!(), Some(x) => *x = new - } - assert_eq!(m.find(&5), Some(&new)); - } + #[test] + fn test_find_mut() { + let mut m = LinearMap::new(); + assert!(m.insert(1, 12)); + assert!(m.insert(2, 8)); + assert!(m.insert(5, 14)); + let new = 100; + match m.find_mut(&5) { + None => fail!(), Some(x) => *x = new + } + assert_eq!(m.find(&5), Some(&new)); + } - #[test] - pub fn test_insert_overwrite() { - let mut m = LinearMap::new(); - assert!(m.insert(1, 2)); - assert!(*m.get(&1) == 2); - assert!(!m.insert(1, 3)); - assert!(*m.get(&1) == 3); - } + #[test] + pub fn test_insert_overwrite() { + let mut m = LinearMap::new(); + assert!(m.insert(1, 2)); + assert!(*m.get(&1) == 2); + assert!(!m.insert(1, 3)); + assert!(*m.get(&1) == 3); + } - #[test] - pub fn test_insert_conflicts() { - let mut m = linear::linear_map_with_capacity(4); - assert!(m.insert(1, 2)); - assert!(m.insert(5, 3)); - assert!(m.insert(9, 4)); - assert!(*m.get(&9) == 4); - assert!(*m.get(&5) == 3); - assert!(*m.get(&1) == 2); - } + #[test] + pub fn test_insert_conflicts() { + let mut m = linear_map_with_capacity(4); + assert!(m.insert(1, 2)); + assert!(m.insert(5, 3)); + assert!(m.insert(9, 4)); + assert!(*m.get(&9) == 4); + assert!(*m.get(&5) == 3); + assert!(*m.get(&1) == 2); + } - #[test] - pub fn test_conflict_remove() { - let mut m = linear::linear_map_with_capacity(4); - assert!(m.insert(1, 2)); - assert!(m.insert(5, 3)); - assert!(m.insert(9, 4)); - assert!(m.remove(&1)); - assert!(*m.get(&9) == 4); - assert!(*m.get(&5) == 3); - } + #[test] + pub fn test_conflict_remove() { + let mut m = linear_map_with_capacity(4); + assert!(m.insert(1, 2)); + assert!(m.insert(5, 3)); + assert!(m.insert(9, 4)); + assert!(m.remove(&1)); + assert!(*m.get(&9) == 4); + assert!(*m.get(&5) == 3); + } - #[test] - pub fn test_is_empty() { - let mut m = linear::linear_map_with_capacity(4); - assert!(m.insert(1, 2)); - assert!(!m.is_empty()); - assert!(m.remove(&1)); - assert!(m.is_empty()); - } + #[test] + pub fn test_is_empty() { + let mut m = linear_map_with_capacity(4); + assert!(m.insert(1, 2)); + assert!(!m.is_empty()); + assert!(m.remove(&1)); + assert!(m.is_empty()); + } - #[test] - pub fn test_pop() { - let mut m = LinearMap::new(); - m.insert(1, 2); - assert!(m.pop(&1) == Some(2)); - assert!(m.pop(&1) == None); - } + #[test] + pub fn test_pop() { + let mut m = LinearMap::new(); + m.insert(1, 2); + assert!(m.pop(&1) == Some(2)); + assert!(m.pop(&1) == None); + } - #[test] - pub fn test_swap() { - let mut m = LinearMap::new(); - assert!(m.swap(1, 2) == None); - assert!(m.swap(1, 3) == Some(2)); - assert!(m.swap(1, 4) == Some(3)); - } + #[test] + pub fn test_swap() { + let mut m = LinearMap::new(); + assert!(m.swap(1, 2) == None); + assert!(m.swap(1, 3) == Some(2)); + assert!(m.swap(1, 4) == Some(3)); + } - #[test] - pub fn test_find_or_insert() { - let mut m = LinearMap::new::(); - assert!(m.find_or_insert(1, 2) == &2); - assert!(m.find_or_insert(1, 3) == &2); - } + #[test] + pub fn test_find_or_insert() { + let mut m = LinearMap::new::(); + assert!(m.find_or_insert(1, 2) == &2); + assert!(m.find_or_insert(1, 3) == &2); + } - #[test] - pub fn test_find_or_insert_with() { - let mut m = LinearMap::new::(); - assert!(m.find_or_insert_with(1, |_| 2) == &2); - assert!(m.find_or_insert_with(1, |_| 3) == &2); - } + #[test] + pub fn test_find_or_insert_with() { + let mut m = LinearMap::new::(); + assert!(m.find_or_insert_with(1, |_| 2) == &2); + assert!(m.find_or_insert_with(1, |_| 3) == &2); + } - #[test] - pub fn test_consume() { - let mut m = LinearMap::new(); - assert!(m.insert(1, 2)); - assert!(m.insert(2, 3)); - let mut m2 = LinearMap::new(); - do m.consume |k, v| { - m2.insert(k, v); - } - assert!(m.len() == 0); - assert!(m2.len() == 2); - assert!(m2.get(&1) == &2); - assert!(m2.get(&2) == &3); - } + #[test] + pub fn test_consume() { + let mut m = LinearMap::new(); + assert!(m.insert(1, 2)); + assert!(m.insert(2, 3)); + let mut m2 = LinearMap::new(); + do m.consume |k, v| { + m2.insert(k, v); + } + assert!(m.len() == 0); + assert!(m2.len() == 2); + assert!(m2.get(&1) == &2); + assert!(m2.get(&2) == &3); + } - #[test] - pub fn test_iterate() { - let mut m = linear::linear_map_with_capacity(4); - for uint::range(0, 32) |i| { - assert!(m.insert(i, i*2)); - } - let mut observed = 0; - for m.each |&(k, v)| { - assert!(*v == *k * 2); - observed |= (1 << *k); - } - assert!(observed == 0xFFFF_FFFF); + #[test] + pub fn test_iterate() { + let mut m = linear_map_with_capacity(4); + for uint::range(0, 32) |i| { + assert!(m.insert(i, i*2)); } - - #[test] - pub fn test_find() { - let mut m = LinearMap::new(); - assert!(m.find(&1).is_none()); - m.insert(1, 2); - match m.find(&1) { - None => fail!(), - Some(v) => assert!(*v == 2) - } + let mut observed = 0; + for m.each |&(k, v)| { + assert!(*v == *k * 2); + observed |= (1 << *k); } + assert!(observed == 0xFFFF_FFFF); + } - #[test] - pub fn test_eq() { - let mut m1 = LinearMap::new(); - m1.insert(1, 2); - m1.insert(2, 3); - m1.insert(3, 4); + #[test] + pub fn test_find() { + let mut m = LinearMap::new(); + assert!(m.find(&1).is_none()); + m.insert(1, 2); + match m.find(&1) { + None => fail!(), + Some(v) => assert!(*v == 2) + } + } - let mut m2 = LinearMap::new(); - m2.insert(1, 2); - m2.insert(2, 3); + #[test] + pub fn test_eq() { + let mut m1 = LinearMap::new(); + m1.insert(1, 2); + m1.insert(2, 3); + m1.insert(3, 4); - assert!(m1 != m2); + let mut m2 = LinearMap::new(); + m2.insert(1, 2); + m2.insert(2, 3); - m2.insert(3, 4); + assert!(m1 != m2); - assert!(m1 == m2); - } + m2.insert(3, 4); - #[test] - pub fn test_expand() { - let mut m = LinearMap::new(); + assert!(m1 == m2); + } - assert!(m.len() == 0); - assert!(m.is_empty()); + #[test] + pub fn test_expand() { + let mut m = LinearMap::new(); - let mut i = 0u; - let old_resize_at = m.resize_at; - while old_resize_at == m.resize_at { - m.insert(i, i); - i += 1; - } + assert!(m.len() == 0); + assert!(m.is_empty()); - assert!(m.len() == i); - assert!(!m.is_empty()); + let mut i = 0u; + let old_resize_at = m.resize_at; + while old_resize_at == m.resize_at { + m.insert(i, i); + i += 1; } + + assert!(m.len() == i); + assert!(!m.is_empty()); } +} #[test] - mod test_set { - use hashmap::linear; - use container::{Container, Map, Set}; - use vec; - - #[test] - fn test_disjoint() { - let mut xs = linear::LinearSet::new(); - let mut ys = linear::LinearSet::new(); - assert!(xs.is_disjoint(&ys)); - assert!(ys.is_disjoint(&xs)); - assert!(xs.insert(5)); - assert!(ys.insert(11)); - assert!(xs.is_disjoint(&ys)); - assert!(ys.is_disjoint(&xs)); - assert!(xs.insert(7)); - assert!(xs.insert(19)); - assert!(xs.insert(4)); - assert!(ys.insert(2)); - assert!(ys.insert(-11)); - assert!(xs.is_disjoint(&ys)); - assert!(ys.is_disjoint(&xs)); - assert!(ys.insert(7)); - assert!(!xs.is_disjoint(&ys)); - assert!(!ys.is_disjoint(&xs)); - } +mod test_set { + use super::*; + use container::{Container, Map, Set}; + use vec; - #[test] - fn test_subset_and_superset() { - let mut a = linear::LinearSet::new(); - assert!(a.insert(0)); - assert!(a.insert(5)); - assert!(a.insert(11)); - assert!(a.insert(7)); - - let mut b = linear::LinearSet::new(); - assert!(b.insert(0)); - assert!(b.insert(7)); - assert!(b.insert(19)); - assert!(b.insert(250)); - assert!(b.insert(11)); - assert!(b.insert(200)); - - assert!(!a.is_subset(&b)); - assert!(!a.is_superset(&b)); - assert!(!b.is_subset(&a)); - assert!(!b.is_superset(&a)); - - assert!(b.insert(5)); - - assert!(a.is_subset(&b)); - assert!(!a.is_superset(&b)); - assert!(!b.is_subset(&a)); - assert!(b.is_superset(&a)); - } + #[test] + fn test_disjoint() { + let mut xs = LinearSet::new(); + let mut ys = LinearSet::new(); + assert!(xs.is_disjoint(&ys)); + assert!(ys.is_disjoint(&xs)); + assert!(xs.insert(5)); + assert!(ys.insert(11)); + assert!(xs.is_disjoint(&ys)); + assert!(ys.is_disjoint(&xs)); + assert!(xs.insert(7)); + assert!(xs.insert(19)); + assert!(xs.insert(4)); + assert!(ys.insert(2)); + assert!(ys.insert(-11)); + assert!(xs.is_disjoint(&ys)); + assert!(ys.is_disjoint(&xs)); + assert!(ys.insert(7)); + assert!(!xs.is_disjoint(&ys)); + assert!(!ys.is_disjoint(&xs)); + } - #[test] - fn test_intersection() { - let mut a = linear::LinearSet::new(); - let mut b = linear::LinearSet::new(); - - assert!(a.insert(11)); - assert!(a.insert(1)); - assert!(a.insert(3)); - assert!(a.insert(77)); - assert!(a.insert(103)); - assert!(a.insert(5)); - assert!(a.insert(-5)); - - assert!(b.insert(2)); - assert!(b.insert(11)); - assert!(b.insert(77)); - assert!(b.insert(-9)); - assert!(b.insert(-42)); - assert!(b.insert(5)); - assert!(b.insert(3)); - - let mut i = 0; - let expected = [3, 5, 11, 77]; - for a.intersection(&b) |x| { - assert!(vec::contains(expected, x)); - i += 1 - } - assert!(i == expected.len()); - } + #[test] + fn test_subset_and_superset() { + let mut a = LinearSet::new(); + assert!(a.insert(0)); + assert!(a.insert(5)); + assert!(a.insert(11)); + assert!(a.insert(7)); + + let mut b = LinearSet::new(); + assert!(b.insert(0)); + assert!(b.insert(7)); + assert!(b.insert(19)); + assert!(b.insert(250)); + assert!(b.insert(11)); + assert!(b.insert(200)); + + assert!(!a.is_subset(&b)); + assert!(!a.is_superset(&b)); + assert!(!b.is_subset(&a)); + assert!(!b.is_superset(&a)); + + assert!(b.insert(5)); + + assert!(a.is_subset(&b)); + assert!(!a.is_superset(&b)); + assert!(!b.is_subset(&a)); + assert!(b.is_superset(&a)); + } - #[test] - fn test_difference() { - let mut a = linear::LinearSet::new(); - let mut b = linear::LinearSet::new(); - - assert!(a.insert(1)); - assert!(a.insert(3)); - assert!(a.insert(5)); - assert!(a.insert(9)); - assert!(a.insert(11)); - - assert!(b.insert(3)); - assert!(b.insert(9)); - - let mut i = 0; - let expected = [1, 5, 11]; - for a.difference(&b) |x| { - assert!(vec::contains(expected, x)); - i += 1 - } - assert!(i == expected.len()); - } + #[test] + fn test_intersection() { + let mut a = LinearSet::new(); + let mut b = LinearSet::new(); + + assert!(a.insert(11)); + assert!(a.insert(1)); + assert!(a.insert(3)); + assert!(a.insert(77)); + assert!(a.insert(103)); + assert!(a.insert(5)); + assert!(a.insert(-5)); + + assert!(b.insert(2)); + assert!(b.insert(11)); + assert!(b.insert(77)); + assert!(b.insert(-9)); + assert!(b.insert(-42)); + assert!(b.insert(5)); + assert!(b.insert(3)); + + let mut i = 0; + let expected = [3, 5, 11, 77]; + for a.intersection(&b) |x| { + assert!(vec::contains(expected, x)); + i += 1 + } + assert!(i == expected.len()); + } - #[test] - fn test_symmetric_difference() { - let mut a = linear::LinearSet::new(); - let mut b = linear::LinearSet::new(); - - assert!(a.insert(1)); - assert!(a.insert(3)); - assert!(a.insert(5)); - assert!(a.insert(9)); - assert!(a.insert(11)); - - assert!(b.insert(-2)); - assert!(b.insert(3)); - assert!(b.insert(9)); - assert!(b.insert(14)); - assert!(b.insert(22)); - - let mut i = 0; - let expected = [-2, 1, 5, 11, 14, 22]; - for a.symmetric_difference(&b) |x| { - assert!(vec::contains(expected, x)); - i += 1 - } - assert!(i == expected.len()); - } + #[test] + fn test_difference() { + let mut a = LinearSet::new(); + let mut b = LinearSet::new(); + + assert!(a.insert(1)); + assert!(a.insert(3)); + assert!(a.insert(5)); + assert!(a.insert(9)); + assert!(a.insert(11)); + + assert!(b.insert(3)); + assert!(b.insert(9)); + + let mut i = 0; + let expected = [1, 5, 11]; + for a.difference(&b) |x| { + assert!(vec::contains(expected, x)); + i += 1 + } + assert!(i == expected.len()); + } - #[test] - fn test_union() { - let mut a = linear::LinearSet::new(); - let mut b = linear::LinearSet::new(); - - assert!(a.insert(1)); - assert!(a.insert(3)); - assert!(a.insert(5)); - assert!(a.insert(9)); - assert!(a.insert(11)); - assert!(a.insert(16)); - assert!(a.insert(19)); - assert!(a.insert(24)); - - assert!(b.insert(-2)); - assert!(b.insert(1)); - assert!(b.insert(5)); - assert!(b.insert(9)); - assert!(b.insert(13)); - assert!(b.insert(19)); - - let mut i = 0; - let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]; - for a.union(&b) |x| { - assert!(vec::contains(expected, x)); - i += 1 - } - assert!(i == expected.len()); - } + #[test] + fn test_symmetric_difference() { + let mut a = LinearSet::new(); + let mut b = LinearSet::new(); + + assert!(a.insert(1)); + assert!(a.insert(3)); + assert!(a.insert(5)); + assert!(a.insert(9)); + assert!(a.insert(11)); + + assert!(b.insert(-2)); + assert!(b.insert(3)); + assert!(b.insert(9)); + assert!(b.insert(14)); + assert!(b.insert(22)); + + let mut i = 0; + let expected = [-2, 1, 5, 11, 14, 22]; + for a.symmetric_difference(&b) |x| { + assert!(vec::contains(expected, x)); + i += 1 + } + assert!(i == expected.len()); + } + + #[test] + fn test_union() { + let mut a = LinearSet::new(); + let mut b = LinearSet::new(); + + assert!(a.insert(1)); + assert!(a.insert(3)); + assert!(a.insert(5)); + assert!(a.insert(9)); + assert!(a.insert(11)); + assert!(a.insert(16)); + assert!(a.insert(19)); + assert!(a.insert(24)); + + assert!(b.insert(-2)); + assert!(b.insert(1)); + assert!(b.insert(5)); + assert!(b.insert(9)); + assert!(b.insert(13)); + assert!(b.insert(19)); + + let mut i = 0; + let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]; + for a.union(&b) |x| { + assert!(vec::contains(expected, x)); + i += 1 + } + assert!(i == expected.len()); } } diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 39e43ba6fc5e8..ac6775eb81fec 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -79,7 +79,7 @@ use comm::{Chan, GenericChan}; use prelude::*; use unstable; use ptr; -use hashmap::linear::LinearSet; +use hashmap::LinearSet; use task::local_data_priv::{local_get, local_set}; use task::rt::rust_task; use task::rt; diff --git a/src/libcore/unstable/global.rs b/src/libcore/unstable/global.rs index ef5970658a192..3187012e2a983 100644 --- a/src/libcore/unstable/global.rs +++ b/src/libcore/unstable/global.rs @@ -34,7 +34,7 @@ use ops::Drop; use unstable::{Exclusive, exclusive}; use unstable::at_exit::at_exit; use unstable::intrinsics::atomic_cxchg; -use hashmap::linear::LinearMap; +use hashmap::LinearMap; use sys::Closure; #[cfg(test)] use unstable::{SharedMutableState, shared_mutable_state}; diff --git a/src/libcore/unstable/weak_task.rs b/src/libcore/unstable/weak_task.rs index 8b24c2fa6f622..5556792c22543 100644 --- a/src/libcore/unstable/weak_task.rs +++ b/src/libcore/unstable/weak_task.rs @@ -21,7 +21,7 @@ is trying to shut down. use cell::Cell; use comm::{GenericSmartChan, stream}; use comm::{Port, Chan, SharedChan, GenericChan, GenericPort}; -use hashmap::linear::LinearMap; +use hashmap::LinearMap; use option::{Some, None}; use unstable::at_exit::at_exit; use unstable::finally::Finally; diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index 6c485df84b484..89d1eb53c8201 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -18,7 +18,7 @@ use core::os; use core::uint; use core::util; use core::vec; -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; fn not_win32(os: session::os) -> bool { match os { diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 34678d1803c17..c50eecd448976 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -10,7 +10,7 @@ use core::prelude::*; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::libc::c_uint; use core::option; use core::ptr; diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 086c6a33b3ec8..eb01964f6d692 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -18,7 +18,7 @@ use metadata::decoder; use metadata::filesearch::FileSearch; use metadata::loader; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::vec; use syntax::attr; use syntax::codemap::{span, dummy_sp}; diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index c836538e1e6c8..13447d09736e4 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -17,7 +17,7 @@ use core::prelude::*; use metadata::cstore; use metadata::decoder; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::vec; use std; use syntax::ast; diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 340ad443b5888..b7ad62ee4ed2c 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -25,7 +25,7 @@ use util::ppaux::ty_to_str; use core::flate; use core::hash::HashUtil; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::int; use core::io::{Writer, WriterUtil}; use core::io; diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 9b777332c27c3..05f5f302f5379 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -16,7 +16,7 @@ use core::prelude::*; use middle::ty::param_ty; use middle::ty; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::io::WriterUtil; use core::io; use core::uint; diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index ac74dc25fd0d7..2bf89903e1c8b 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -31,7 +31,7 @@ use middle::mem_categorization::{lp_comp, lp_deref, lp_local}; use middle::ty; use util::ppaux::ty_to_str; -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; use core::uint; use syntax::ast::m_mutbl; use syntax::ast; diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index 925659984d4bd..2965921b05a81 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -31,7 +31,7 @@ use middle::ty; use util::common::indenter; use util::ppaux::{expr_repr, region_to_str}; -use core::hashmap::linear::{LinearSet, LinearMap}; +use core::hashmap::{LinearSet, LinearMap}; use core::vec; use syntax::ast::{m_const, m_imm, m_mutbl}; use syntax::ast; diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 3f4f7469832f5..ca3365bbcabc4 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -234,7 +234,7 @@ use middle::moves; use util::common::stmt_set; use util::ppaux::note_and_explain_region; -use core::hashmap::linear::{LinearSet, LinearMap}; +use core::hashmap::{LinearSet, LinearMap}; use core::io; use core::result::{Result, Ok, Err}; use core::to_bytes; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index d610b007f3503..788d8f6de89cd 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -20,7 +20,7 @@ use core::vec; use syntax::{ast, ast_map, ast_util, visit}; use syntax::ast::*; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; // // This pass classifies expressions by their constant-ness. diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 19d3e1f431db2..d680d1547351a 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -17,7 +17,7 @@ use core::prelude::*; use middle::resolve; use middle::ty; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use syntax::codemap::span; use syntax::{ast, ast_util, visit}; diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 566a52c3894d1..7c399bf2ece68 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -31,7 +31,7 @@ use syntax::ast_util::local_def; use syntax::visit::{default_simple_visitor, mk_simple_visitor, SimpleVisitor}; use syntax::visit::visit_crate; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::ptr; pub enum LangItem { diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index ba232f55f74f6..d4cd500f04c48 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -15,7 +15,7 @@ use driver::session; use middle::ty; use util::ppaux::{ty_to_str}; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::char; use core::cmp; use core::i8; diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index e9e226d36d1f5..a91404fb47a2a 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -111,7 +111,7 @@ use middle::typeck; use middle::moves; use util::ppaux::ty_to_str; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::io::WriterUtil; use core::io; use core::ptr; diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index a93618b66246f..de52d3e6878e9 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -215,7 +215,7 @@ use middle::typeck::method_map; use util::ppaux; use util::common::indenter; -use core::hashmap::linear::{LinearSet, LinearMap}; +use core::hashmap::{LinearSet, LinearMap}; use core::vec; use syntax::ast::*; use syntax::ast_util; diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 0e47dabcce900..db3f5acf9d590 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -12,7 +12,7 @@ use core::prelude::*; use middle::resolve; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use syntax::ast::*; use syntax::ast_util::{path_to_ident, walk_pat}; use syntax::codemap::span; diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index f6025548d71c0..e6e1990717254 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -26,7 +26,7 @@ use middle::ty::{region_variance, rv_covariant, rv_invariant}; use middle::ty::{rv_contravariant}; use middle::ty; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; use core::vec; use syntax::ast_map; use syntax::codemap::span; diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 70d9dfacb6940..c4a6584dd66a3 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -77,7 +77,7 @@ use syntax::opt_vec::OptVec; use core::option::Some; use core::str::each_split_str; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; // Definition mapping pub type DefMap = @mut LinearMap; diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 12eaeb77d1103..1b5273dd3d7d3 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -167,7 +167,7 @@ use middle::trans::type_of; use middle::ty; use util::common::indenter; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use syntax::ast; use syntax::ast::ident; use syntax::ast_util::path_to_ident; diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 15238f168944d..588690b055444 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -67,7 +67,7 @@ use util::ppaux::ty_to_str; use util::ppaux; use core::hash; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; use core::int; use core::io; use core::libc::{c_uint, c_ulonglong}; diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index ab0e2f38a0b94..234812e66d9db 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -18,7 +18,7 @@ use syntax::codemap::span; use core::prelude::*; use core::cast; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::libc::{c_uint, c_ulonglong, c_char}; use core::libc; use core::option::Some; diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 6bb30a5d5b51b..04aca7b9dcdc4 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -45,7 +45,7 @@ use util::ppaux::{expr_repr, ty_to_str}; use core::cast; use core::hash; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; use core::libc::{c_uint, c_longlong, c_ulonglong}; use core::ptr; use core::str; diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index d290a8ffa5c94..69a70c5a2fd51 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -20,7 +20,7 @@ use middle::trans; use middle::ty; use util::ppaux::ty_to_str; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::libc; use core::option; use core::sys; diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index dc910f9f178e3..616a25d3c164f 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -153,7 +153,7 @@ use util::common::indenter; use util::ppaux::ty_to_str; use core::cast::transmute; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use syntax::print::pprust::{expr_to_str}; use syntax::ast; use syntax::codemap; diff --git a/src/librustc/middle/trans/reachable.rs b/src/librustc/middle/trans/reachable.rs index 8824e0b782909..fd0eb9667098b 100644 --- a/src/librustc/middle/trans/reachable.rs +++ b/src/librustc/middle/trans/reachable.rs @@ -21,7 +21,7 @@ use middle::ty; use middle::typeck; use core::prelude::*; -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; use syntax::ast; use syntax::ast::*; use syntax::ast_util::def_id_of_def; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index fddcce523f447..2b00bd0c71246 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -36,7 +36,7 @@ use core::result; use core::to_bytes; use core::uint; use core::vec; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; use std::smallintmap::SmallIntMap; use syntax::ast::*; use syntax::ast_util::{is_local, local_def}; diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index cc2cf7a23c598..dd1dcbe67b94a 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -18,7 +18,7 @@ use middle::typeck::check::{instantiate_path, lookup_def}; use middle::typeck::check::{structure_of, valid_range_bounds}; use middle::typeck::require_same_types; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; use core::vec; use syntax::ast; use syntax::ast_util; diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 320f0206fb871..8f7e8478f8adb 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -95,7 +95,7 @@ use middle::typeck::{method_self, method_static, method_trait, method_super}; use util::common::indenter; use util::ppaux::expr_repr; -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; use core::result; use core::uint; use core::vec; diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 056ccf185995b..1c144b294d219 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -110,7 +110,7 @@ use util::common::{block_query, indenter, loop_query}; use util::ppaux::{bound_region_to_str, expr_repr, pat_repr}; use util::ppaux; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::ptr; use core::result::{Result, Ok, Err}; use core::result; diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index a1eaa1f6a3394..ddce274c54207 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -28,7 +28,7 @@ use core::result::{Ok, Err}; use core::result; use core::uint; use core::vec; -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; use syntax::ast; use syntax::ast_util; use syntax::codemap::span; diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 4fc9e8d19ae1f..9f4984e02a603 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -53,7 +53,7 @@ use syntax::visit::{visit_mod}; use util::ppaux::ty_to_str; use core::result::Ok; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; use core::uint; pub struct UniversalQuantificationResult { diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index d9f00451dd57e..b190a98f8cd08 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -548,7 +548,7 @@ use util::common::indenter; use util::ppaux::note_and_explain_region; use core::cell::{Cell, empty_cell}; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; use core::result::{Err, Ok}; use core::to_bytes; use core::uint; diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 2b5a47c18c6d9..1a0a1fceb52a8 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -55,7 +55,7 @@ use middle::ty; use util::common::time; use util::ppaux; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::result; use core::vec; use std::list::List; diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 2a2d921ba8636..98eff8b50d14d 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -14,7 +14,7 @@ use syntax::ast; use syntax::codemap::{span}; use syntax::visit; -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; use core::str; use std; diff --git a/src/librustpkg/rustpkg.rc b/src/librustpkg/rustpkg.rc index ff549ad2c2261..2f1d25425ec2b 100644 --- a/src/librustpkg/rustpkg.rc +++ b/src/librustpkg/rustpkg.rc @@ -28,7 +28,7 @@ extern mod syntax(vers = "0.6"); use core::*; use core::container::Map; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::io::WriterUtil; use rustc::driver::{driver, session}; use rustc::metadata::filesearch; diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index cd64061af0392..15546e96653d8 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -10,7 +10,7 @@ use core::*; use core::hash::Streaming; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use rustc::driver::{driver, session}; use rustc::metadata::filesearch; use std::getopts::groups::getopts; diff --git a/src/libstd/json.rs b/src/libstd/json.rs index e090d6bc036d8..1b79708e59017 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -16,7 +16,7 @@ use core::prelude::*; use core::io::{WriterUtil, ReaderUtil}; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use serialize::Encodable; use serialize; @@ -1161,7 +1161,7 @@ mod tests { use super::*; use core::prelude::*; - use core::hashmap::linear::LinearMap; + use core::hashmap::LinearMap; use std::serialize::Decodable; diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index d23784953ef99..b32a9841ac6c1 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -17,7 +17,7 @@ use core::from_str::FromStr; use core::io::{Reader, ReaderUtil}; use core::io; use core::prelude::*; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::str; use core::to_bytes::IterBytes; use core::to_bytes; @@ -818,7 +818,7 @@ mod tests { use net_url::*; - use core::hashmap::linear::LinearMap; + use core::hashmap::LinearMap; #[test] pub fn test_url_parse() { diff --git a/src/libstd/serialize.rs b/src/libstd/serialize.rs index ddc84e07a3584..88ae58ee01b4c 100644 --- a/src/libstd/serialize.rs +++ b/src/libstd/serialize.rs @@ -17,7 +17,7 @@ Core encoding and decoding interfaces. #[forbid(non_camel_case_types)]; use core::prelude::*; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; use core::trie::{TrieMap, TrieSet}; use deque::Deque; use dlist::DList; diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index 6ed1364d7fcb2..6886d5d630e19 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -24,7 +24,7 @@ use core::pipes::recv; use core::prelude::*; use core::result; use core::run; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::task; use core::to_bytes; diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index f22b466efebda..04d7cbdca0c3d 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -23,7 +23,7 @@ use print::pprust; use visit; use core::cmp; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::str; use core::vec; diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 9f8dbef9b967b..71e2faa93f569 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -20,7 +20,7 @@ use diagnostic::span_handler; use parse::comments::{doc_comment_style, strip_doc_comment_decoration}; use core::vec; -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; use std; /* Constructors */ diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 93e2ad64c8c23..cae56267f5eb3 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -20,7 +20,7 @@ use parse; use parse::token; use core::vec; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; // new-style macro! tt code: // @@ -509,7 +509,7 @@ impl MapChain{ #[cfg(test)] mod test { use super::MapChain; - use core::hashmap::linear::LinearMap; + use core::hashmap::LinearMap; #[test] fn testenv () { let mut a = LinearMap::new(); diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index f74fbbc3c03f7..fcb0c76a2c78a 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -20,7 +20,7 @@ use parse::token::{Token, EOF, to_str, nonterminal}; use parse::token; use core::prelude::*; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; /* This is an Earley-like parser, without support for in-grammar nonterminals, only by calling out to the main rust parser for named nonterminals (which it diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 67c2f438269d8..de0b4c0799fba 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -18,7 +18,7 @@ use ext::tt::macro_parser::{named_match, matched_seq, matched_nonterminal}; use parse::token::{EOF, INTERPOLATED, IDENT, Token, nt_ident, ident_interner}; use parse::lexer::TokenAndSpan; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::option; use core::vec; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ceafecde3a0b1..1b845ad1dd9d4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -94,7 +94,7 @@ use opt_vec::OptVec; use core::either::Either; use core::either; -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; use core::vec; #[deriving(Eq)] diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 5fdf6f7620cc1..ff10b6070e66d 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -18,7 +18,7 @@ use util::interner; use core::cast; use core::char; -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; use core::str; use core::task; diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 159a205637b59..dd4044036ef84 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -13,7 +13,7 @@ // type, and vice versa. use core::prelude::*; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; pub struct Interner { priv map: @mut LinearMap, diff --git a/src/test/auxiliary/issue-2631-a.rs b/src/test/auxiliary/issue-2631-a.rs index fad72ee4eb360..eded285eef117 100644 --- a/src/test/auxiliary/issue-2631-a.rs +++ b/src/test/auxiliary/issue-2631-a.rs @@ -13,7 +13,7 @@ extern mod std; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; pub type header_map = LinearMap<~str, @mut ~[@~str]>; diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index d6ebf4d346bcc..c30c38e92f724 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -13,7 +13,7 @@ extern mod std; use core::io; use std::time; use std::treemap::TreeMap; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; use core::trie::TrieMap; fn timed(label: &str, f: &fn()) { diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index a3210108dcc17..2fcd82eefe61b 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -9,7 +9,7 @@ // except according to those terms. extern mod std; -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; use std::bitv::BitvSet; use std::treemap::TreeSet; use core::io::WriterUtil; diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index a156f915faca7..397c08228995c 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -24,7 +24,7 @@ use std::arc; use std::time; use std::deque::Deque; use std::par; -use core::hashmap::linear::{LinearMap, LinearSet}; +use core::hashmap::{LinearMap, LinearSet}; use core::io::WriterUtil; use core::int::abs; use core::rand::RngUtil; diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 3bc40a46cfb2c..f608c71000b29 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -15,7 +15,7 @@ extern mod std; use std::sort; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use core::io::ReaderUtil; use core::comm::{stream, Port, Chan}; use core::cmp::Ord; diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 1764ef48412cc..65d99858d1d36 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -25,7 +25,7 @@ // writes pbm image to output path use core::io::WriterUtil; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; struct cmplx { re: f64, diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs index 6dbfa5dd53847..b3cf314edd001 100644 --- a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs +++ b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs @@ -10,7 +10,7 @@ //buggy.rs -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; fn main() { let mut buggy_map :LinearMap = diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs index 788c5397e35d0..1420a67556cad 100644 --- a/src/test/compile-fail/borrowck-insert-during-each.rs +++ b/src/test/compile-fail/borrowck-insert-during-each.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::hashmap::linear::LinearSet; +use core::hashmap::LinearSet; struct Foo { n: LinearSet, diff --git a/src/test/compile-fail/for-loop-decl.rs b/src/test/compile-fail/for-loop-decl.rs index 918d8f00d7842..c7c1ea4821307 100644 --- a/src/test/compile-fail/for-loop-decl.rs +++ b/src/test/compile-fail/for-loop-decl.rs @@ -11,7 +11,7 @@ // error-pattern: mismatched types extern mod std; use std::bitv; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; struct FnInfo { vars: LinearMap diff --git a/src/test/compile-fail/map-types.rs b/src/test/compile-fail/map-types.rs index 6f71bd40affe5..00efdbbf75acc 100644 --- a/src/test/compile-fail/map-types.rs +++ b/src/test/compile-fail/map-types.rs @@ -9,7 +9,7 @@ // except according to those terms. use core::container::Map; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; // Test that trait types printed in error msgs include the type arguments. diff --git a/src/test/run-fail/unwind-misc-1.rs b/src/test/run-fail/unwind-misc-1.rs index 06a3f0113b01c..5ec4beb364d89 100644 --- a/src/test/run-fail/unwind-misc-1.rs +++ b/src/test/run-fail/unwind-misc-1.rs @@ -14,7 +14,7 @@ fn main() { let count = @mut 0u; - let mut map = core::hashmap::linear::LinearMap::new(); + let mut map = core::hashmap::LinearMap::new(); let mut arr = ~[]; for uint::range(0u, 10u) |i| { arr += ~[@~"key stuff"]; diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 4234c064e8d38..415f753a562e2 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -19,7 +19,7 @@ pub fn map(filename: ~str, emit: map_reduce::putter) { emit(filename, ~"1"); } mod map_reduce { - use core::hashmap::linear::LinearMap; + use core::hashmap::LinearMap; use core::comm::*; pub type putter = @fn(~str, ~str); diff --git a/src/test/run-pass/issue-1696.rs b/src/test/run-pass/issue-1696.rs index 5f8b8d2983072..401920789c098 100644 --- a/src/test/run-pass/issue-1696.rs +++ b/src/test/run-pass/issue-1696.rs @@ -10,7 +10,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; pub fn main() { let mut m = LinearMap::new(); diff --git a/src/test/run-pass/issue-2631-b.rs b/src/test/run-pass/issue-2631-b.rs index b22c423ed0412..42452d3a2bb0f 100644 --- a/src/test/run-pass/issue-2631-b.rs +++ b/src/test/run-pass/issue-2631-b.rs @@ -14,7 +14,7 @@ extern mod req; use req::*; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; pub fn main() { let v = ~[@~"hi"]; diff --git a/src/test/run-pass/issue-2804-2.rs b/src/test/run-pass/issue-2804-2.rs index 8934c3935c087..4f0930deaaef1 100644 --- a/src/test/run-pass/issue-2804-2.rs +++ b/src/test/run-pass/issue-2804-2.rs @@ -13,7 +13,7 @@ // Minimized version of issue-2804.rs. Both check that callee IDs don't // clobber the previous node ID in a macro expr -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; fn add_interfaces(managed_ip: ~str, device: LinearMap<~str, int>) { error!("%s, %?", managed_ip, device.get(&~"interfaces")); diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index 3d1a2c3df5d3b..a1c5f4a6757dc 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -11,7 +11,7 @@ // except according to those terms. extern mod std; -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; use std::json; enum object { diff --git a/src/test/run-pass/issue-3026.rs b/src/test/run-pass/issue-3026.rs index 022d3f6fceb05..9665113bc0cee 100644 --- a/src/test/run-pass/issue-3026.rs +++ b/src/test/run-pass/issue-3026.rs @@ -10,7 +10,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; pub fn main() { let mut buggy_map: LinearMap = LinearMap::new::(); diff --git a/src/test/run-pass/issue-3559.rs b/src/test/run-pass/issue-3559.rs index f7b7605523c25..a73f130e88981 100644 --- a/src/test/run-pass/issue-3559.rs +++ b/src/test/run-pass/issue-3559.rs @@ -29,7 +29,7 @@ fn check_strs(actual: &str, expected: &str) -> bool #[test] fn tester() { - let mut table = core::hashmap::linear::LinearMap(); + let mut table = core::hashmap::LinearMap(); table.insert(@~"one", 1); table.insert(@~"two", 2); assert!(check_strs(table.to_str(), ~"xxx")); // not sure what expected should be diff --git a/src/test/run-pass/issue-4016.rs b/src/test/run-pass/issue-4016.rs index 69cd1a2a19d86..2384b0e859393 100644 --- a/src/test/run-pass/issue-4016.rs +++ b/src/test/run-pass/issue-4016.rs @@ -11,7 +11,7 @@ // xfail-test extern mod std; -use hashmap::linear; +use hashmap; use std::json; use std::serialization::{Deserializable, deserialize}; diff --git a/src/test/run-pass/issue-4092.rs b/src/test/run-pass/issue-4092.rs index 85cb3e3207ee7..8cda78840b341 100644 --- a/src/test/run-pass/issue-4092.rs +++ b/src/test/run-pass/issue-4092.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::hashmap::linear::LinearMap; +use core::hashmap::LinearMap; pub fn main() { let mut x = LinearMap::new();