]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-12860.rs
auto merge of #13092 : sfackler/rust/buffer-vec, r=thestinger
[rust.git] / src / test / run-pass / issue-12860.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-fast
12
13 extern crate collections;
14
15 use collections::HashSet;
16
17 #[deriving(Eq, TotalEq, Hash)]
18 struct XYZ {
19     x: int,
20     y: int,
21     z: int
22 }
23
24 fn main() {
25     let mut connected = HashSet::new();
26     let mut border = HashSet::new();
27
28     let middle = XYZ{x: 0, y: 0, z: 0};
29     border.insert(middle);
30
31     while border.len() > 0 && connected.len() < 10000 {
32         let choice = *(border.iter().next().unwrap());
33         border.remove(&choice);
34         connected.insert(choice);
35
36         let cxp = XYZ{x: choice.x + 1, y: choice.y, z: choice.z};
37         let cxm = XYZ{x: choice.x - 1, y: choice.y, z: choice.z};
38         let cyp = XYZ{x: choice.x, y: choice.y + 1, z: choice.z};
39         let cym = XYZ{x: choice.x, y: choice.y - 1, z: choice.z};
40         let czp = XYZ{x: choice.x, y: choice.y, z: choice.z + 1};
41         let czm = XYZ{x: choice.x, y: choice.y, z: choice.z - 1};
42
43         if !connected.contains(&cxp) {
44             border.insert(cxp);
45         }
46         if  !connected.contains(&cxm){
47             border.insert(cxm);
48         }
49         if !connected.contains(&cyp){
50             border.insert(cyp);
51         }
52         if !connected.contains(&cym) {
53             border.insert(cym);
54         }
55         if !connected.contains(&czp){
56             border.insert(czp);
57         }
58         if !connected.contains(&czm) {
59             border.insert(czm);
60         }
61     }
62 }