|
| 1 | +// GENERATED CODE BY BUCKLESCRIPT VERSION 0.5.0 , PLEASE EDIT WITH CARE |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +var Caml_builtin_exceptions = require("../caml_builtin_exceptions"); |
| 5 | +var Hashtbl = require("../hashtbl"); |
| 6 | +var Pervasives = require("../pervasives"); |
| 7 | +var Curry = require("../curry"); |
| 8 | + |
| 9 | +function Make(funarg) { |
| 10 | + var $$let = funarg[/* V */0]; |
| 11 | + var H = Hashtbl.Make([ |
| 12 | + $$let[2], |
| 13 | + $$let[1] |
| 14 | + ]); |
| 15 | + var find_default = function (htbl, x) { |
| 16 | + try { |
| 17 | + return Curry._2(H[/* find */6], htbl, x); |
| 18 | + } |
| 19 | + catch (exn){ |
| 20 | + if (exn === Caml_builtin_exceptions.not_found) { |
| 21 | + return /* false */0; |
| 22 | + } |
| 23 | + else { |
| 24 | + throw exn; |
| 25 | + } |
| 26 | + } |
| 27 | + }; |
| 28 | + var min_cutset = function (gr, first_node) { |
| 29 | + var n_labels = Curry._1(H[/* create */0], 97); |
| 30 | + var l_labels = Curry._1(H[/* create */0], 97); |
| 31 | + var already_processed = Curry._1(H[/* create */0], 97); |
| 32 | + var on_the_stack = Curry._1(H[/* create */0], 97); |
| 33 | + var cut_set = [/* [] */0]; |
| 34 | + var counter = [1]; |
| 35 | + var step2 = function (top, rest_of_stack) { |
| 36 | + if (find_default(already_processed, top)) { |
| 37 | + throw [ |
| 38 | + Caml_builtin_exceptions.assert_failure, |
| 39 | + [ |
| 40 | + "gpr_405_test.ml", |
| 41 | + 43, |
| 42 | + 6 |
| 43 | + ] |
| 44 | + ]; |
| 45 | + } |
| 46 | + if (find_default(on_the_stack, top)) { |
| 47 | + throw [ |
| 48 | + Caml_builtin_exceptions.assert_failure, |
| 49 | + [ |
| 50 | + "gpr_405_test.ml", |
| 51 | + 44, |
| 52 | + 6 |
| 53 | + ] |
| 54 | + ]; |
| 55 | + } |
| 56 | + Curry._3(H[/* add */4], on_the_stack, top, /* true */1); |
| 57 | + Curry._3(H[/* add */4], n_labels, top, counter[0]); |
| 58 | + counter[0] = counter[0] + 1 | 0; |
| 59 | + Curry._3(H[/* add */4], l_labels, top, 0); |
| 60 | + Curry._3(H[/* add */4], already_processed, top, /* true */1); |
| 61 | + var _successors = Curry._2(funarg[/* succ */1], gr, top); |
| 62 | + var _top = top; |
| 63 | + var _rest_of_stack = rest_of_stack; |
| 64 | + while(true) { |
| 65 | + var rest_of_stack$1 = _rest_of_stack; |
| 66 | + var top$1 = _top; |
| 67 | + var successors = _successors; |
| 68 | + if (successors) { |
| 69 | + var successor = successors[0]; |
| 70 | + if (find_default(already_processed, successor)) { |
| 71 | + var x = find_default(on_the_stack, successor) ? Curry._2(H[/* find */6], n_labels, successor) : Curry._2(H[/* find */6], l_labels, successor); |
| 72 | + Curry._3(H[/* add */4], l_labels, top$1, Pervasives.max(Curry._2(H[/* find */6], l_labels, top$1), x)); |
| 73 | + _successors = successors[1]; |
| 74 | + continue ; |
| 75 | + |
| 76 | + } |
| 77 | + else { |
| 78 | + return step2(successor, /* :: */[ |
| 79 | + /* tuple */[ |
| 80 | + top$1, |
| 81 | + successors |
| 82 | + ], |
| 83 | + rest_of_stack$1 |
| 84 | + ]); |
| 85 | + } |
| 86 | + } |
| 87 | + else { |
| 88 | + if (Curry._2(H[/* find */6], l_labels, top$1) === Curry._2(H[/* find */6], n_labels, top$1)) { |
| 89 | + cut_set[0] = /* :: */[ |
| 90 | + top$1, |
| 91 | + cut_set[0] |
| 92 | + ]; |
| 93 | + Curry._3(H[/* add */4], l_labels, top$1, 0); |
| 94 | + } |
| 95 | + if (Curry._2(H[/* find */6], l_labels, top$1) > Curry._2(H[/* find */6], n_labels, top$1)) { |
| 96 | + throw [ |
| 97 | + Caml_builtin_exceptions.invalid_argument, |
| 98 | + "Graph.Mincut: graph not reducible" |
| 99 | + ]; |
| 100 | + } |
| 101 | + else if (rest_of_stack$1) { |
| 102 | + var match = rest_of_stack$1[0]; |
| 103 | + var new_top = match[0]; |
| 104 | + Curry._3(H[/* add */4], on_the_stack, top$1, /* false */0); |
| 105 | + Curry._3(H[/* add */4], l_labels, new_top, Pervasives.max(Curry._2(H[/* find */6], l_labels, top$1), Curry._2(H[/* find */6], l_labels, new_top))); |
| 106 | + _rest_of_stack = rest_of_stack$1[1]; |
| 107 | + _top = new_top; |
| 108 | + _successors = match[1]; |
| 109 | + continue ; |
| 110 | + |
| 111 | + } |
| 112 | + else { |
| 113 | + return cut_set[0]; |
| 114 | + } |
| 115 | + } |
| 116 | + }; |
| 117 | + }; |
| 118 | + return step2(first_node, /* [] */0); |
| 119 | + }; |
| 120 | + return [min_cutset]; |
| 121 | +} |
| 122 | + |
| 123 | +exports.Make = Make; |
| 124 | +/* Hashtbl Not a pure module */ |
0 commit comments