]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-12860.rs
auto merge of #19514 : jbranchaud/rust/add-btree-set-bitor, r=Gankro
[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
12 extern crate collections;
13
14 use std::collections::HashSet;
15
16 #[deriving(PartialEq, Eq, Hash)]
17 struct XYZ {
18     x: int,
19     y: int,
20     z: int
21 }
22
23 impl Copy for XYZ {}
24
25 fn main() {
26     let mut connected = HashSet::new();
27     let mut border = HashSet::new();
28
29     let middle = XYZ{x: 0, y: 0, z: 0};
30     border.insert(middle);
31
32     while border.len() > 0 && connected.len() < 10000 {
33         let choice = *(border.iter().next().unwrap());
34         border.remove(&choice);
35         connected.insert(choice);
36
37         let cxp = XYZ{x: choice.x + 1, y: choice.y, z: choice.z};
38         let cxm = XYZ{x: choice.x - 1, y: choice.y, z: choice.z};
39         let cyp = XYZ{x: choice.x, y: choice.y + 1, z: choice.z};
40         let cym = XYZ{x: choice.x, y: choice.y - 1, z: choice.z};
41         let czp = XYZ{x: choice.x, y: choice.y, z: choice.z + 1};
42         let czm = XYZ{x: choice.x, y: choice.y, z: choice.z - 1};
43
44         if !connected.contains(&cxp) {
45             border.insert(cxp);
46         }
47         if  !connected.contains(&cxm){
48             border.insert(cxm);
49         }
50         if !connected.contains(&cyp){
51             border.insert(cyp);
52         }
53         if !connected.contains(&cym) {
54             border.insert(cym);
55         }
56         if !connected.contains(&czp){
57             border.insert(czp);
58         }
59         if !connected.contains(&czm) {
60             border.insert(czm);
61         }
62     }
63 }