]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/issue-12860.rs
Imported Upstream version 1.0.0-alpha.2
[rustc.git] / src / test / run-pass / issue-12860.rs
CommitLineData
1a4d82fc
JJ
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
12extern crate collections;
13
14use std::collections::HashSet;
15
85aaf69f 16#[derive(Copy, PartialEq, Eq, Hash)]
1a4d82fc
JJ
17struct XYZ {
18 x: int,
19 y: int,
20 z: int
21}
22
1a4d82fc
JJ
23fn main() {
24 let mut connected = HashSet::new();
25 let mut border = HashSet::new();
26
27 let middle = XYZ{x: 0, y: 0, z: 0};
28 border.insert(middle);
29
30 while border.len() > 0 && connected.len() < 10000 {
31 let choice = *(border.iter().next().unwrap());
32 border.remove(&choice);
33 connected.insert(choice);
34
35 let cxp = XYZ{x: choice.x + 1, y: choice.y, z: choice.z};
36 let cxm = XYZ{x: choice.x - 1, y: choice.y, z: choice.z};
37 let cyp = XYZ{x: choice.x, y: choice.y + 1, z: choice.z};
38 let cym = XYZ{x: choice.x, y: choice.y - 1, z: choice.z};
39 let czp = XYZ{x: choice.x, y: choice.y, z: choice.z + 1};
40 let czm = XYZ{x: choice.x, y: choice.y, z: choice.z - 1};
41
42 if !connected.contains(&cxp) {
43 border.insert(cxp);
44 }
45 if !connected.contains(&cxm){
46 border.insert(cxm);
47 }
48 if !connected.contains(&cyp){
49 border.insert(cyp);
50 }
51 if !connected.contains(&cym) {
52 border.insert(cym);
53 }
54 if !connected.contains(&czp){
55 border.insert(czp);
56 }
57 if !connected.contains(&czm) {
58 border.insert(czm);
59 }
60 }
61}