Created
July 12, 2010 19:48
-
-
Save schani/472970 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| public class Node { | |
| Node n1, n2, n3, n4; | |
| public void connect (Node _n1, Node _n2, Node _n3, Node _n4) { | |
| n1 = _n1; | |
| n2 = _n2; | |
| n3 = _n3; | |
| n4 = _n4; | |
| } | |
| public int countNodes () { | |
| Queue<Node> q = new Queue<Node> (); | |
| HashSet<Node> s = new HashSet<Node> (); | |
| /* | |
| q.Enqueue (this); | |
| while (q.Count > 0) { | |
| Node n = q.Dequeue (); | |
| if (s.Contains (n)) | |
| continue; | |
| s.Add (n); | |
| q.Enqueue (n.n1); | |
| q.Enqueue (n.n2); | |
| q.Enqueue (n.n3); | |
| q.Enqueue (n.n4); | |
| } | |
| */ | |
| return s.Count; | |
| } | |
| public static Node randomGraph (int size, Random r) { | |
| Node[] nodes = new Node [size]; | |
| for (int i = 0; i < size; ++i) | |
| nodes [i] = new Node (); | |
| for (int i = 0; i < size; ++i) | |
| nodes [i].connect (nodes [r.Next (size)], | |
| nodes [r.Next (size)], | |
| nodes [r.Next (size)], | |
| nodes [r.Next (size)]); | |
| return nodes [0]; | |
| } | |
| public static int Main () { | |
| Random r = new Random (31415); | |
| Node g = randomGraph (4000000, r); | |
| Console.WriteLine ("long graph constructed"); | |
| for (int i = 0; i < 30; ++i) | |
| randomGraph (500000, r); | |
| Console.WriteLine ("done"); | |
| Console.WriteLine ("nodes: " + g.countNodes ()); | |
| return 0; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment