Fallout from collection conventions
This commit is contained in:
parent
cf3b2e4fe6
commit
eec145be3f
101 changed files with 418 additions and 417 deletions
|
|
@ -30,18 +30,18 @@ trait MutableMap {
|
|||
|
||||
impl MutableMap for TreeMap<uint, uint> {
|
||||
fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); }
|
||||
fn remove(&mut self, k: &uint) -> bool { self.remove(k) }
|
||||
fn find(&self, k: &uint) -> Option<&uint> { self.find(k) }
|
||||
fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() }
|
||||
fn find(&self, k: &uint) -> Option<&uint> { self.get(k) }
|
||||
}
|
||||
impl MutableMap for HashMap<uint, uint> {
|
||||
fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); }
|
||||
fn remove(&mut self, k: &uint) -> bool { self.remove(k) }
|
||||
fn find(&self, k: &uint) -> Option<&uint> { self.find(k) }
|
||||
fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() }
|
||||
fn find(&self, k: &uint) -> Option<&uint> { self.get(k) }
|
||||
}
|
||||
impl MutableMap for TrieMap<uint> {
|
||||
fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); }
|
||||
fn remove(&mut self, k: &uint) -> bool { self.remove(k) }
|
||||
fn find(&self, k: &uint) -> Option<&uint> { self.find(k) }
|
||||
fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() }
|
||||
fn find(&self, k: &uint) -> Option<&uint> { self.get(k) }
|
||||
}
|
||||
|
||||
fn ascending<M: MutableMap>(map: &mut M, n_keys: uint) {
|
||||
|
|
|
|||
|
|
@ -197,8 +197,8 @@ fn rendezvous(nn: uint, set: Vec<Color>) {
|
|||
|
||||
creatures_met += 2;
|
||||
|
||||
to_creature.get_mut(fst_creature.name).send(snd_creature);
|
||||
to_creature.get_mut(snd_creature.name).send(fst_creature);
|
||||
to_creature[fst_creature.name].send(snd_creature);
|
||||
to_creature[snd_creature.name].send(fst_creature);
|
||||
}
|
||||
|
||||
// tell each creature to stop
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ fn sum_and_scale(a: &'static [AminoAcid]) -> Vec<AminoAcid> {
|
|||
result.push(a_i);
|
||||
}
|
||||
let result_len = result.len();
|
||||
result.get_mut(result_len - 1).p = LOOKUP_SCALE;
|
||||
result[result_len - 1].p = LOOKUP_SCALE;
|
||||
result
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -171,13 +171,13 @@ impl Table {
|
|||
next: None,
|
||||
};
|
||||
c.f(&mut *entry);
|
||||
*self.items.get_mut(index as uint) = Some(entry);
|
||||
self.items[index as uint] = Some(entry);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let entry = self.items.get_mut(index as uint).as_mut().unwrap();
|
||||
let entry = self.items[index as uint].as_mut().unwrap();
|
||||
if entry.code == key {
|
||||
c.f(&mut **entry);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ fn is_board_unfeasible(board: u64, masks: &Vec<Vec<Vec<u64>>>) -> bool {
|
|||
fn filter_masks(masks: &mut Vec<Vec<Vec<u64>>>) {
|
||||
for i in range(0, masks.len()) {
|
||||
for j in range(0, (*masks)[i].len()) {
|
||||
*masks.get_mut(i).get_mut(j) =
|
||||
masks[i][j] =
|
||||
(*masks)[i][j].iter().map(|&m| m)
|
||||
.filter(|&m| !is_board_unfeasible(m, masks))
|
||||
.collect();
|
||||
|
|
@ -217,7 +217,7 @@ fn to_vec(raw_sol: &List<u64>) -> Vec<u8> {
|
|||
let id = '0' as u8 + get_id(m);
|
||||
for i in range(0u, 50) {
|
||||
if m & 1 << i != 0 {
|
||||
*sol.get_mut(i) = id;
|
||||
sol[i] = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ fn main() {
|
|||
}
|
||||
|
||||
for (i, variant) in variant_strs.iter().enumerate() {
|
||||
println!("{} {}", variant, counts.get_mut(i).get());
|
||||
println!("{} {}", variant, counts[i].get());
|
||||
}
|
||||
println!("");
|
||||
println!("{}", ilen);
|
||||
|
|
|
|||
|
|
@ -112,14 +112,15 @@ fn read_to_end<R: Reader>(r: &mut R) -> IoResult<Vec<u8>> {
|
|||
let mut vec = Vec::with_capacity(CHUNK);
|
||||
loop {
|
||||
// workaround: very fast growing
|
||||
if vec.capacity() - vec.len() < CHUNK {
|
||||
let len = vec.len();
|
||||
if vec.capacity() - len < CHUNK {
|
||||
let cap = vec.capacity();
|
||||
let mult = if cap < 256 * 1024 * 1024 {
|
||||
16
|
||||
} else {
|
||||
2
|
||||
};
|
||||
vec.reserve_exact(mult * cap);
|
||||
vec.reserve_exact(mult * cap - len);
|
||||
}
|
||||
match r.push_at_least(1, CHUNK, &mut vec) {
|
||||
Ok(_) => {}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ impl Sudoku {
|
|||
if comps.len() == 3u {
|
||||
let row = from_str::<uint>(comps[0]).unwrap() as u8;
|
||||
let col = from_str::<uint>(comps[1]).unwrap() as u8;
|
||||
*g.get_mut(row as uint).get_mut(col as uint) =
|
||||
g[row as uint][col as uint] =
|
||||
from_str::<uint>(comps[2]).unwrap() as u8;
|
||||
}
|
||||
else {
|
||||
|
|
@ -139,10 +139,10 @@ impl Sudoku {
|
|||
|
||||
// find first remaining color that is available
|
||||
let next = avail.next();
|
||||
*self.grid.get_mut(row as uint).get_mut(col as uint) = next;
|
||||
self.grid[row as uint][col as uint] = next;
|
||||
return 0u8 != next;
|
||||
}
|
||||
*self.grid.get_mut(row as uint).get_mut(col as uint) = 0u8;
|
||||
self.grid[row as uint][col as uint] = 0u8;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ fn a() {
|
|||
// Create an immutable pointer into p's contents:
|
||||
let q: &int = &p[0];
|
||||
|
||||
*p.get_mut(0) = 5; //~ ERROR cannot borrow
|
||||
p[0] = 5; //~ ERROR cannot borrow
|
||||
|
||||
println!("{}", *q);
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ fn b() {
|
|||
|
||||
borrow(
|
||||
p.as_slice(),
|
||||
|| *p.get_mut(0) = 5); //~ ERROR cannot borrow `p` as mutable
|
||||
|| p[0] = 5); //~ ERROR cannot borrow `p` as mutable
|
||||
}
|
||||
|
||||
fn c() {
|
||||
|
|
@ -42,7 +42,7 @@ fn c() {
|
|||
// modification:
|
||||
let mut p = vec!(1);
|
||||
borrow(p.as_slice(), ||{});
|
||||
*p.get_mut(0) = 5;
|
||||
p[0] = 5;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ fn main() {
|
|||
for &x in vector.iter() {
|
||||
let cap = vector.capacity();
|
||||
vector.grow(cap, 0u); //~ ERROR cannot borrow
|
||||
*vector.get_mut(1u) = 5u; //~ ERROR cannot borrow
|
||||
vector[1u] = 5u; //~ ERROR cannot borrow
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ fn has_mut_vec_but_tries_to_change_it() {
|
|||
takes_imm_elt(
|
||||
&v[0],
|
||||
|| { //~ ERROR cannot borrow `v` as mutable
|
||||
*v.get_mut(1) = 4;
|
||||
v[1] = 4;
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pub fn main() {
|
|||
let mut a: Vec<int> = vec!(-1, -1, -1, -1);
|
||||
let mut p: int = 0;
|
||||
two(|i| {
|
||||
two(|j| { *a.get_mut(p as uint) = 10 * i + j; p += 1; })
|
||||
two(|j| { a[p as uint] = 10 * i + j; p += 1; })
|
||||
});
|
||||
assert_eq!(a[0], 0);
|
||||
assert_eq!(a[1], 1);
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ mod map_reduce {
|
|||
mapper_done => { num_mappers -= 1; }
|
||||
find_reducer(k, cc) => {
|
||||
let mut c;
|
||||
match reducers.find(&str::from_utf8(
|
||||
match reducers.get(&str::from_utf8(
|
||||
k.as_slice()).unwrap().to_string()) {
|
||||
Some(&_c) => { c = _c; }
|
||||
None => { c = 0; }
|
||||
|
|
|
|||
|
|
@ -86,8 +86,8 @@ impl AsciiArt {
|
|||
// element is:
|
||||
// 1) potentially large
|
||||
// 2) needs to be modified
|
||||
let row = self.lines.get_mut(v);
|
||||
*row.get_mut(h) = self.fill;
|
||||
let row = &mut self.lines[v];
|
||||
row[h] = self.fill;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ struct HasNested {
|
|||
|
||||
impl HasNested {
|
||||
fn method_push_local(&mut self) {
|
||||
self.nest.get_mut(0).push(0);
|
||||
self.nest[0].push(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ pub fn main() {
|
|||
assert_eq!(*(*p).borrow(), Point {x: 3, y: 5});
|
||||
|
||||
let v = Rc::new(RefCell::new(vec!(1i, 2, 3)));
|
||||
*(*(*v).borrow_mut()).get_mut(0) = 3;
|
||||
*(*(*v).borrow_mut()).get_mut(1) += 3;
|
||||
(*(*v).borrow_mut())[0] = 3;
|
||||
(*(*v).borrow_mut())[1] += 3;
|
||||
assert_eq!(((*(*v).borrow())[0],
|
||||
(*(*v).borrow())[1],
|
||||
(*(*v).borrow())[2]), (3, 5, 3));
|
||||
|
|
|
|||
|
|
@ -16,37 +16,37 @@ use std::option::Some;
|
|||
|
||||
pub fn main() {
|
||||
let mut map: HashMap<SendStr, uint> = HashMap::new();
|
||||
assert!(map.insert(Slice("foo"), 42));
|
||||
assert!(!map.insert(Owned("foo".to_string()), 42));
|
||||
assert!(!map.insert(Slice("foo"), 42));
|
||||
assert!(!map.insert(Owned("foo".to_string()), 42));
|
||||
assert!(map.insert(Slice("foo"), 42).is_none());
|
||||
assert!(map.insert(Owned("foo".to_string()), 42).is_some());
|
||||
assert!(map.insert(Slice("foo"), 42).is_some());
|
||||
assert!(map.insert(Owned("foo".to_string()), 42).is_some());
|
||||
|
||||
assert!(!map.insert(Slice("foo"), 43));
|
||||
assert!(!map.insert(Owned("foo".to_string()), 44));
|
||||
assert!(!map.insert(Slice("foo"), 45));
|
||||
assert!(!map.insert(Owned("foo".to_string()), 46));
|
||||
assert!(map.insert(Slice("foo"), 43).is_some());
|
||||
assert!(map.insert(Owned("foo".to_string()), 44).is_some());
|
||||
assert!(map.insert(Slice("foo"), 45).is_some());
|
||||
assert!(map.insert(Owned("foo".to_string()), 46).is_some());
|
||||
|
||||
let v = 46;
|
||||
|
||||
assert_eq!(map.find(&Owned("foo".to_string())), Some(&v));
|
||||
assert_eq!(map.find(&Slice("foo")), Some(&v));
|
||||
assert_eq!(map.get(&Owned("foo".to_string())), Some(&v));
|
||||
assert_eq!(map.get(&Slice("foo")), Some(&v));
|
||||
|
||||
let (a, b, c, d) = (50, 51, 52, 53);
|
||||
|
||||
assert!(map.insert(Slice("abc"), a));
|
||||
assert!(map.insert(Owned("bcd".to_string()), b));
|
||||
assert!(map.insert(Slice("cde"), c));
|
||||
assert!(map.insert(Owned("def".to_string()), d));
|
||||
assert!(map.insert(Slice("abc"), a).is_none());
|
||||
assert!(map.insert(Owned("bcd".to_string()), b).is_none());
|
||||
assert!(map.insert(Slice("cde"), c).is_none());
|
||||
assert!(map.insert(Owned("def".to_string()), d).is_none());
|
||||
|
||||
assert!(!map.insert(Slice("abc"), a));
|
||||
assert!(!map.insert(Owned("bcd".to_string()), b));
|
||||
assert!(!map.insert(Slice("cde"), c));
|
||||
assert!(!map.insert(Owned("def".to_string()), d));
|
||||
assert!(map.insert(Slice("abc"), a).is_some());
|
||||
assert!(map.insert(Owned("bcd".to_string()), b).is_some());
|
||||
assert!(map.insert(Slice("cde"), c).is_some());
|
||||
assert!(map.insert(Owned("def".to_string()), d).is_some());
|
||||
|
||||
assert!(!map.insert(Owned("abc".to_string()), a));
|
||||
assert!(!map.insert(Slice("bcd"), b));
|
||||
assert!(!map.insert(Owned("cde".to_string()), c));
|
||||
assert!(!map.insert(Slice("def"), d));
|
||||
assert!(map.insert(Owned("abc".to_string()), a).is_some());
|
||||
assert!(map.insert(Slice("bcd"), b).is_some());
|
||||
assert!(map.insert(Owned("cde".to_string()), c).is_some());
|
||||
assert!(map.insert(Slice("def"), d).is_some());
|
||||
|
||||
assert_eq!(map.find_equiv("abc"), Some(&a));
|
||||
assert_eq!(map.find_equiv("bcd"), Some(&b));
|
||||
|
|
|
|||
|
|
@ -17,49 +17,49 @@ use std::option::Some;
|
|||
|
||||
pub fn main() {
|
||||
let mut map: TreeMap<SendStr, uint> = TreeMap::new();
|
||||
assert!(map.insert(Slice("foo"), 42));
|
||||
assert!(!map.insert(Owned("foo".to_string()), 42));
|
||||
assert!(!map.insert(Slice("foo"), 42));
|
||||
assert!(!map.insert(Owned("foo".to_string()), 42));
|
||||
assert!(map.insert(Slice("foo"), 42).is_none());
|
||||
assert!(map.insert(Owned("foo".to_string()), 42).is_some());
|
||||
assert!(map.insert(Slice("foo"), 42).is_some());
|
||||
assert!(map.insert(Owned("foo".to_string()), 42).is_some());
|
||||
|
||||
assert!(!map.insert(Slice("foo"), 43));
|
||||
assert!(!map.insert(Owned("foo".to_string()), 44));
|
||||
assert!(!map.insert(Slice("foo"), 45));
|
||||
assert!(!map.insert(Owned("foo".to_string()), 46));
|
||||
assert!(map.insert(Slice("foo"), 43).is_some());
|
||||
assert!(map.insert(Owned("foo".to_string()), 44).is_some());
|
||||
assert!(map.insert(Slice("foo"), 45).is_some());
|
||||
assert!(map.insert(Owned("foo".to_string()), 46).is_some());
|
||||
|
||||
let v = 46;
|
||||
|
||||
assert_eq!(map.find(&Owned("foo".to_string())), Some(&v));
|
||||
assert_eq!(map.find(&Slice("foo")), Some(&v));
|
||||
assert_eq!(map.get(&Owned("foo".to_string())), Some(&v));
|
||||
assert_eq!(map.get(&Slice("foo")), Some(&v));
|
||||
|
||||
let (a, b, c, d) = (50, 51, 52, 53);
|
||||
|
||||
assert!(map.insert(Slice("abc"), a));
|
||||
assert!(map.insert(Owned("bcd".to_string()), b));
|
||||
assert!(map.insert(Slice("cde"), c));
|
||||
assert!(map.insert(Owned("def".to_string()), d));
|
||||
assert!(map.insert(Slice("abc"), a).is_none());
|
||||
assert!(map.insert(Owned("bcd".to_string()), b).is_none());
|
||||
assert!(map.insert(Slice("cde"), c).is_none());
|
||||
assert!(map.insert(Owned("def".to_string()), d).is_none());
|
||||
|
||||
assert!(!map.insert(Slice("abc"), a));
|
||||
assert!(!map.insert(Owned("bcd".to_string()), b));
|
||||
assert!(!map.insert(Slice("cde"), c));
|
||||
assert!(!map.insert(Owned("def".to_string()), d));
|
||||
assert!(map.insert(Slice("abc"), a).is_some());
|
||||
assert!(map.insert(Owned("bcd".to_string()), b).is_some());
|
||||
assert!(map.insert(Slice("cde"), c).is_some());
|
||||
assert!(map.insert(Owned("def".to_string()), d).is_some());
|
||||
|
||||
assert!(!map.insert(Owned("abc".to_string()), a));
|
||||
assert!(!map.insert(Slice("bcd"), b));
|
||||
assert!(!map.insert(Owned("cde".to_string()), c));
|
||||
assert!(!map.insert(Slice("def"), d));
|
||||
assert!(map.insert(Owned("abc".to_string()), a).is_some());
|
||||
assert!(map.insert(Slice("bcd"), b).is_some());
|
||||
assert!(map.insert(Owned("cde".to_string()), c).is_some());
|
||||
assert!(map.insert(Slice("def"), d).is_some());
|
||||
|
||||
assert_eq!(map.find(&Slice("abc")), Some(&a));
|
||||
assert_eq!(map.find(&Slice("bcd")), Some(&b));
|
||||
assert_eq!(map.find(&Slice("cde")), Some(&c));
|
||||
assert_eq!(map.find(&Slice("def")), Some(&d));
|
||||
assert_eq!(map.get(&Slice("abc")), Some(&a));
|
||||
assert_eq!(map.get(&Slice("bcd")), Some(&b));
|
||||
assert_eq!(map.get(&Slice("cde")), Some(&c));
|
||||
assert_eq!(map.get(&Slice("def")), Some(&d));
|
||||
|
||||
assert_eq!(map.find(&Owned("abc".to_string())), Some(&a));
|
||||
assert_eq!(map.find(&Owned("bcd".to_string())), Some(&b));
|
||||
assert_eq!(map.find(&Owned("cde".to_string())), Some(&c));
|
||||
assert_eq!(map.find(&Owned("def".to_string())), Some(&d));
|
||||
assert_eq!(map.get(&Owned("abc".to_string())), Some(&a));
|
||||
assert_eq!(map.get(&Owned("bcd".to_string())), Some(&b));
|
||||
assert_eq!(map.get(&Owned("cde".to_string())), Some(&c));
|
||||
assert_eq!(map.get(&Owned("def".to_string())), Some(&d));
|
||||
|
||||
assert!(map.pop(&Slice("foo")).is_some());
|
||||
assert!(map.remove(&Slice("foo")).is_some());
|
||||
assert_eq!(map.into_iter().map(|(k, v)| format!("{}{}", k, v))
|
||||
.collect::<Vec<String>>()
|
||||
.concat(),
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ pub fn main() {
|
|||
assert_eq!(a[2], 4);
|
||||
assert_eq!(a[4], 2);
|
||||
let mut n = 42;
|
||||
swap(&mut n, a.get_mut(0));
|
||||
swap(&mut n, &mut a[0]);
|
||||
assert_eq!(a[0], 42);
|
||||
assert_eq!(n, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub fn main() {
|
|||
assert_eq!(*b[0], 10);
|
||||
|
||||
// This should only modify the value in a, not b
|
||||
**a.get_mut(0) = 20;
|
||||
*a[0] = 20;
|
||||
|
||||
assert_eq!(*a[0], 20);
|
||||
assert_eq!(*b[0], 10);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue