Skip to content
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

(blocked on #5121) add stronger region annotations to the maps #5670

Closed
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions src/libcore/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ pub trait Mutable: Container {
fn clear(&mut self);
}

pub trait Map<K, V>: Mutable {
pub trait Map<'self, K, V>: Mutable {
/// Return true if the map contains a value for the specified key
fn contains_key(&self, key: &K) -> bool;

/// Visit all keys
fn each_key(&self, f: &fn(&K) -> bool);

/// Visit all values
fn each_value(&self, f: &fn(&V) -> bool);
fn each_value(&self, f: &fn(&'self V) -> bool);

/// Iterate over the map and mutate the contained values
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool);
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<K:Hash + IterBytes + Eq,V> Mutable for HashMap<K, V> {
}
}

impl<'self,K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
impl<'self,K:Hash + IterBytes + Eq,V> Map<'self, K, V> for HashMap<K, V> {
/// 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) {
Expand All @@ -325,12 +325,12 @@ impl<'self,K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
}

/// Visit all keys
fn each_key(&self, blk: &fn(k: &K) -> bool) {
fn each_key(&self, blk: &fn(k: &'self K) -> bool) {
self.each(|&(k, _)| blk(k))
}

/// Visit all values
fn each_value(&self, blk: &fn(v: &V) -> bool) {
fn each_value(&self, blk: &fn(v: &'self V) -> bool) {
self.each(|&(_, v)| blk(v))
}

Expand Down Expand Up @@ -564,7 +564,7 @@ pub struct HashSet<T> {

impl<T:Hash + IterBytes + Eq> BaseIter<T> for HashSet<T> {
/// Visit all values in order
fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
fn each(&self, f: &fn(&'self T) -> bool) { self.map.each_key(f) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}

Expand Down
6 changes: 3 additions & 3 deletions src/libcore/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<T> Mutable for TrieMap<T> {
}
}

impl<T> Map<uint, T> for TrieMap<T> {
impl<'self, T> Map<'self, uint, T> for TrieMap<T> {
/// Return true if the map contains a value for the specified key
#[inline(always)]
fn contains_key(&self, key: &uint) -> bool {
Expand All @@ -80,7 +80,7 @@ impl<T> Map<uint, T> for TrieMap<T> {

/// Visit all values in order
#[inline(always)]
fn each_value(&self, f: &fn(&T) -> bool) {
fn each_value(&self, f: &fn(&'self T) -> bool) {
self.each(|&(_, v)| f(v))
}

Expand Down Expand Up @@ -156,7 +156,7 @@ pub impl<T> TrieMap<T> {

/// Visit all values in reverse order
#[inline(always)]
fn each_value_reverse(&self, f: &fn(&T) -> bool) {
fn each_value_reverse(&self, f: &fn(&'self T) -> bool) {
self.each_reverse(|&(_, v)| f(v))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/smallintmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<V> Mutable for SmallIntMap<V> {
fn clear(&mut self) { self.v.clear() }
}

impl<V> Map<uint, V> for SmallIntMap<V> {
impl<'self, V> Map<'self, uint, V> for SmallIntMap<V> {
/// Return true if the map contains a value for the specified key
fn contains_key(&self, key: &uint) -> bool {
self.find(key).is_some()
Expand All @@ -82,7 +82,7 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
}

/// Visit all values in order
fn each_value(&self, blk: &fn(value: &V) -> bool) {
fn each_value(&self, blk: &fn(value: &'self V) -> bool) {
self.each(|&(_, v)| blk(v))
}

Expand Down
14 changes: 7 additions & 7 deletions src/libstd/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ impl<K: TotalOrd, V> Mutable for TreeMap<K, V> {
}
}

impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
impl<'self, K: TotalOrd, V> Map<'self, K, V> for TreeMap<K, V> {
/// Return true if the map contains a value for the specified key
fn contains_key(&self, key: &K) -> bool {
self.find(key).is_some()
}

/// Visit all keys in order
fn each_key(&self, f: &fn(&K) -> bool) { self.each(|&(k, _)| f(k)) }
fn each_key(&self, f: &fn(&'self K) -> bool) { self.each(|&(k, _)| f(k)) }

/// Visit all values in order
fn each_value(&self, f: &fn(&V) -> bool) {
fn each_value(&self, f: &fn(&'self V) -> bool) {
self.each(|&(_, v)| f(v))
}

Expand Down Expand Up @@ -181,12 +181,12 @@ pub impl<K: TotalOrd, V> TreeMap<K, V> {
fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }

/// Visit all keys in reverse order
fn each_key_reverse(&self, f: &fn(&K) -> bool) {
fn each_key_reverse(&self, f: &fn(&'self K) -> bool) {
self.each_reverse(|&(k, _)| f(k))
}

/// Visit all values in reverse order
fn each_value_reverse(&self, f: &fn(&V) -> bool) {
fn each_value_reverse(&self, f: &fn(&'self V) -> bool) {
self.each_reverse(|&(_, v)| f(v))
}

Expand Down Expand Up @@ -244,15 +244,15 @@ pub struct TreeSet<T> {
impl<T: TotalOrd> BaseIter<T> for TreeSet<T> {
/// Visit all values in order
#[inline(always)]
fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
fn each(&self, f: &fn(&'self T) -> bool) { self.map.each_key(f) }
#[inline(always)]
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}

impl<T: TotalOrd> ReverseIter<T> for TreeSet<T> {
/// Visit all values in reverse order
#[inline(always)]
fn each_reverse(&self, f: &fn(&T) -> bool) {
fn each_reverse(&self, f: &fn(&'self T) -> bool) {
self.map.each_key_reverse(f)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/bench/core-map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn timed(label: &str, f: &fn()) {
io::println(fmt!(" %s: %f", label, end - start));
}

fn ascending<M: Map<uint, uint>>(map: &mut M, n_keys: uint) {
fn ascending<M: Map<'r, uint, uint>>(map: &mut M, n_keys: uint) {
io::println(" Ascending integers:");

do timed("insert") {
Expand All @@ -45,7 +45,7 @@ fn ascending<M: Map<uint, uint>>(map: &mut M, n_keys: uint) {
}
}

fn descending<M: Map<uint, uint>>(map: &mut M, n_keys: uint) {
fn descending<M: Map<'r, uint, uint>>(map: &mut M, n_keys: uint) {
io::println(" Descending integers:");

do timed("insert") {
Expand All @@ -67,7 +67,7 @@ fn descending<M: Map<uint, uint>>(map: &mut M, n_keys: uint) {
}
}

fn vector<M: Map<uint, uint>>(map: &mut M, n_keys: uint, dist: &[uint]) {
fn vector<M: Map<'r, uint, uint>>(map: &mut M, n_keys: uint, dist: &[uint]) {

do timed("insert") {
for uint::range(0, n_keys) |i| {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/map-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ fn main() {
let x: @Map<~str, ~str> = @HashMap::new::<~str, ~str>() as
@Map<~str, ~str>;
let y: @Map<uint, ~str> = @x;
//~^ ERROR mismatched types: expected `@core::container::Map<uint,~str>`
//~^ ERROR mismatched types: expected `@core::container::Map/&<uint,~str>`
}
6 changes: 3 additions & 3 deletions src/test/run-pass/class-impl-very-parameterized-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ impl<T> Mutable for cat<T> {
fn clear(&mut self) {}
}

impl<T> Map<int, T> for cat<T> {
impl<'self, T> Map<'self, int, T> for cat<T> {
fn contains_key(&self, k: &int) -> bool { *k <= self.meows }

fn each_key(&self, f: &fn(v: &int) -> bool) {
for self.each |&(k, _)| { if !f(&k) { break; } loop;};
}

fn each_value(&self, f: &fn(v: &T) -> bool) {
for self.each |&(_, v)| { if !f(v) { break; } loop;};
fn each_value(&self, f: &fn(v: &'self T) -> bool) {
fail!();
}

fn mutate_values(&mut self, f: &fn(&int, &mut T) -> bool) {
Expand Down