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