2 using System
.Collections
.Generic
;
3 using System
.Diagnostics
;
11 public Node (int depth
) : this (depth
, null) {}
13 public Node (int depth
, Node sibling
) {
15 this.child
= new Node (depth
- 1);
17 this.sibling
= sibling
;
20 public override String
ToString () {
21 return String
.Format ("Node[child={0},sibling={1}]", this.child
, this.sibling
);
26 * Usage : width [depth [collections]]
27 * - width : trigger the overflow
28 * - depth : modify the cost difference of the overflow
29 * - collections : # of collections to perform
31 public static void Main (String
[] args
) {
34 width
= Math
.Max (width
, Int32
.Parse (args
[0]));
36 // Windows x64 only has 1 MB of stack per thread which is less than other x86 64-bit OSes.
37 // Using 10000 for depth will cause a stack overflow on Windows x64. 5000 will fit.
38 int platform
= (int) Environment
.OSVersion
.Platform
;
39 bool isWin64
= !(platform
== 4 || platform
== 128) && Environment
.Is64BitProcess
;
40 int depth
= isWin64
? 5000 : 10000;
42 depth
= Math
.Max (depth
, Int32
.Parse (args
[1]));
44 int collections
= 100;
46 collections
= Math
.Max (collections
, Int32
.Parse (args
[2]));
50 for (int i
= 0; i
< width
; i
++) {
51 sibling
= new Node(depth
, sibling
);
52 if (i
> 0 && i
% 10 == 0)
56 for (int i
= 0; i
< collections
; i
++) {
58 if (i
> 0 && i
% 10 == 0)