diff --git a/compiler/bsc/rescript_compiler_main.ml b/compiler/bsc/rescript_compiler_main.ml index 358ece0799..84c0a3f898 100644 --- a/compiler/bsc/rescript_compiler_main.ml +++ b/compiler/bsc/rescript_compiler_main.ml @@ -454,8 +454,5 @@ let _ : unit = Format.eprintf "%s@." msg; exit 2 | x -> - (* - Ext_obj.bt (); -*) Location.report_exception ppf x; exit 2 diff --git a/compiler/ext/ext_js_regex.ml b/compiler/ext/ext_js_regex.ml deleted file mode 100644 index dcb917959c..0000000000 --- a/compiler/ext/ext_js_regex.ml +++ /dev/null @@ -1,47 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -let check_from_end al = - let rec aux l seen = - match l with - | [] -> false - | e :: r -> - if e < 0 || e > 255 then false - else - let c = Char.chr e in - if c = '/' then true - else if Ext_list.exists seen (fun x -> x = c) then false - (* flag should not be repeated *) - else if c = 'i' || c = 'g' || c = 'm' || c = 'y' || c = 'u' then - aux r (c :: seen) - else false - in - aux al [] - -let js_regex_checker s = - match Ext_utf8.decode_utf8_string s with - | [] -> false - | 47 (* [Char.code '/' = 47 ]*) :: tail -> check_from_end (List.rev tail) - | _ :: _ -> false - | exception Ext_utf8.Invalid_utf8 _ -> false diff --git a/compiler/ext/ext_js_regex.mli b/compiler/ext/ext_js_regex.mli deleted file mode 100644 index a627d7b06e..0000000000 --- a/compiler/ext/ext_js_regex.mli +++ /dev/null @@ -1,27 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -(* This is a module that checks if js regex is valid or not *) - -val js_regex_checker : string -> bool diff --git a/compiler/ext/ext_topsort.ml b/compiler/ext/ext_topsort.ml deleted file mode 100644 index 7cdef010c9..0000000000 --- a/compiler/ext/ext_topsort.ml +++ /dev/null @@ -1,61 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -type edges = {id: int; deps: Vec_int.t} - -module Edge_vec = Vec.Make (struct - type t = edges - - let null = {id = 0; deps = Vec_int.empty ()} -end) - -type t = Edge_vec.t - -(** - This graph is different the graph used in [scc] graph, since - we need dynamic shrink the graph, so for each vector the first node is it self , - it will also change the input. - - TODO: error handling (cycle handling) and defensive bad input (missing edges etc) -*) - -let layered_dfs (g : t) = - let queue = Queue.create () in - let rec aux g = - let new_entries = - Edge_vec.inplace_filter_with - (fun (x : edges) -> not (Vec_int.is_empty x.deps)) - ~cb_no:(fun x acc -> Set_int.add acc x.id) - Set_int.empty g - in - if not (Set_int.is_empty new_entries) then ( - Queue.push new_entries queue; - Edge_vec.iter g (fun edges -> - Vec_int.inplace_filter - (fun x -> not (Set_int.mem new_entries x)) - edges.deps); - aux g) - in - aux g; - queue diff --git a/compiler/ext/ext_topsort.mli b/compiler/ext/ext_topsort.mli deleted file mode 100644 index 11d634cb92..0000000000 --- a/compiler/ext/ext_topsort.mli +++ /dev/null @@ -1,33 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -type edges = {id: int; deps: Vec_int.t} - -module Edge_vec : Vec_gen.S with type elt = edges - -type t = Edge_vec.t - -val layered_dfs : t -> Set_int.t Queue.t -(** the input will be modified , -*) diff --git a/compiler/ext/union_find.ml b/compiler/ext/union_find.ml deleted file mode 100644 index bba7846207..0000000000 --- a/compiler/ext/union_find.ml +++ /dev/null @@ -1,64 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -type t = {id: int array; sz: int array; mutable components: int} - -let init n = - let id = Array.make n 0 in - for i = 0 to n - 1 do - Array.unsafe_set id i i - done; - {id; sz = Array.make n 1; components = n} - -let rec find_aux id_store p = - let parent = Array.unsafe_get id_store p in - if p <> parent then find_aux id_store parent else p - -let find store p = find_aux store.id p - -let union store p q = - let id_store = store.id in - let p_root = find_aux id_store p in - let q_root = find_aux id_store q in - if p_root <> q_root then - let () = store.components <- store.components - 1 in - let sz_store = store.sz in - let sz_p_root = Array.unsafe_get sz_store p_root in - let sz_q_root = Array.unsafe_get sz_store q_root in - let bigger = sz_p_root + sz_q_root in - (* Smaller root point to larger to make - it more balanced - it will introduce a cost for small root find, - but major will not be impacted - *) - if sz_p_root < sz_q_root then ( - Array.unsafe_set id_store p q_root; - Array.unsafe_set id_store p_root q_root; - Array.unsafe_set sz_store q_root bigger (* little optimization *)) - else ( - Array.unsafe_set id_store q p_root; - Array.unsafe_set id_store q_root p_root; - Array.unsafe_set sz_store p_root bigger (* little optimization *)) - -let count store = store.components diff --git a/compiler/ext/union_find.mli b/compiler/ext/union_find.mli deleted file mode 100644 index 5638b49cdb..0000000000 --- a/compiler/ext/union_find.mli +++ /dev/null @@ -1,33 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -type t - -val init : int -> t - -val find : t -> int -> int - -val union : t -> int -> int -> unit - -val count : t -> int diff --git a/tests/ounit_tests/ounit_js_regex_checker_tests.ml b/tests/ounit_tests/ounit_js_regex_checker_tests.ml deleted file mode 100644 index 363a131c32..0000000000 --- a/tests/ounit_tests/ounit_js_regex_checker_tests.ml +++ /dev/null @@ -1,35 +0,0 @@ -let ( >:: ), ( >::: ) = OUnit.(( >:: ), ( >::: )) - -open Ext_js_regex - -let suites = - __FILE__ - >::: [ - ( "test_empty_string" >:: fun _ -> - let b = js_regex_checker "" in - OUnit.assert_equal b false ); - ( "test_normal_regex" >:: fun _ -> - let b = js_regex_checker "/abc/" in - OUnit.assert_equal b true ); - ( "test_wrong_regex_last" >:: fun _ -> - let b = js_regex_checker "/abc" in - OUnit.assert_equal b false ); - ( "test_regex_with_flag" >:: fun _ -> - let b = js_regex_checker "/ss/ig" in - OUnit.assert_equal b true ); - ( "test_regex_with_invalid_flag" >:: fun _ -> - let b = js_regex_checker "/ss/j" in - OUnit.assert_equal b false ); - ( "test_regex_invalid_regex" >:: fun _ -> - let b = js_regex_checker "abc/i" in - OUnit.assert_equal b false ); - ( "test_regex_empty_pattern" >:: fun _ -> - let b = js_regex_checker "//" in - OUnit.assert_equal b true ); - ( "test_regex_with_utf8" >:: fun _ -> - let b = js_regex_checker "/😃/" in - OUnit.assert_equal b true ); - ( "test_regex_repeated_flags" >:: fun _ -> - let b = js_regex_checker "/abc/gg" in - OUnit.assert_equal b false ); - ] diff --git a/tests/ounit_tests/ounit_tests_main.ml b/tests/ounit_tests/ounit_tests_main.ml index 249ecd5533..4c01311bb9 100644 --- a/tests/ounit_tests/ounit_tests_main.ml +++ b/tests/ounit_tests/ounit_tests_main.ml @@ -8,16 +8,13 @@ let suites = Ounit_scc_tests.suites; Ounit_list_test.suites; Ounit_hash_set_tests.suites; - Ounit_union_find_tests.suites; Ounit_bal_tree_tests.suites; Ounit_hash_stubs_test.suites; Ounit_map_tests.suites; Ounit_hashtbl_tests.suites; Ounit_string_tests.suites; - Ounit_topsort_tests.suites; Ounit_int_vec_tests.suites; Ounit_ident_mask_tests.suites; - Ounit_js_regex_checker_tests.suites; Ounit_utf8_test.suites; Ounit_unicode_tests.suites; Ounit_bsb_regex_tests.suites; diff --git a/tests/ounit_tests/ounit_topsort_tests.ml b/tests/ounit_tests/ounit_topsort_tests.ml deleted file mode 100644 index bb4ca585e7..0000000000 --- a/tests/ounit_tests/ounit_topsort_tests.ml +++ /dev/null @@ -1,48 +0,0 @@ -let ( >:: ), ( >::: ) = OUnit.(( >:: ), ( >::: )) - -let handle graph = - let len = List.length graph in - let result = Ext_topsort.Edge_vec.make len in - List.iter - (fun (id, deps) -> - Ext_topsort.Edge_vec.push result {id; deps = Vec_int.of_list deps}) - graph; - result - -let graph1 = - ( [(0, [1; 2]); (1, [2; 3]); (2, [4]); (3, []); (4, [])], - [[0]; [1]; [2]; [3; 4]] ) - -let graph2 = - ( [(0, [1; 2]); (1, [2; 3]); (2, [4]); (3, [5]); (4, [5]); (5, [])], - [[0]; [1]; [2]; [3; 4]; [5]] ) - -let graph3 = - ( [ - (0, [1; 2; 3; 4; 5]); - (1, [6; 7; 8]); - (2, [6; 7; 8]); - (3, [6; 7; 8]); - (4, [6; 7; 8]); - (5, [6; 7; 8]); - (6, []); - (7, []); - (8, []); - ], - [[0]; [1; 2; 3; 4; 5]; [6; 7; 8]] ) - -let expect loc (graph1, v) = - let graph = handle graph1 in - let queue = Ext_topsort.layered_dfs graph in - OUnit.assert_bool loc - (Queue.fold (fun acc x -> Set_int.elements x :: acc) [] queue = v) - -let ( =~ ) = OUnit.assert_equal -let suites = - __FILE__ - >::: [ - ( __LOC__ >:: fun _ -> - expect __LOC__ graph1; - expect __LOC__ graph2; - expect __LOC__ graph3 ); - ] diff --git a/tests/ounit_tests/ounit_union_find_tests.ml b/tests/ounit_tests/ounit_union_find_tests.ml deleted file mode 100644 index 83ea61ee31..0000000000 --- a/tests/ounit_tests/ounit_union_find_tests.ml +++ /dev/null @@ -1,976 +0,0 @@ -let ( >:: ), ( >::: ) = OUnit.(( >:: ), ( >::: )) - -let ( =~ ) = OUnit.assert_equal -let tinyUF = - {|10 - 4 3 - 3 8 - 6 5 - 9 4 - 2 1 - 8 9 - 5 0 - 7 2 - 6 1 - 1 0 - 6 7 - |} -let mediumUF = - {|625 - 528 503 - 548 523 - 389 414 - 446 421 - 552 553 - 154 155 - 173 174 - 373 348 - 567 542 - 44 43 - 370 345 - 546 547 - 204 229 - 404 429 - 240 215 - 364 389 - 612 611 - 513 512 - 377 376 - 468 443 - 410 435 - 243 218 - 347 322 - 580 581 - 188 163 - 61 36 - 545 546 - 93 68 - 84 83 - 94 69 - 7 8 - 619 618 - 314 339 - 155 156 - 150 175 - 605 580 - 118 93 - 385 360 - 459 458 - 167 168 - 107 108 - 44 69 - 335 334 - 251 276 - 196 197 - 501 502 - 212 187 - 251 250 - 269 270 - 332 331 - 125 150 - 391 416 - 366 367 - 65 40 - 515 540 - 248 273 - 34 9 - 480 479 - 198 173 - 463 488 - 111 86 - 524 499 - 28 27 - 323 324 - 198 199 - 146 147 - 133 158 - 416 415 - 103 102 - 457 482 - 57 82 - 88 113 - 535 560 - 181 180 - 605 606 - 481 456 - 127 102 - 470 445 - 229 254 - 169 170 - 386 385 - 383 384 - 153 152 - 541 542 - 36 37 - 474 473 - 126 125 - 534 509 - 154 129 - 591 592 - 161 186 - 209 234 - 88 87 - 61 60 - 161 136 - 472 447 - 239 240 - 102 101 - 342 343 - 566 565 - 567 568 - 41 42 - 154 153 - 471 496 - 358 383 - 423 448 - 241 242 - 292 293 - 363 364 - 361 362 - 258 283 - 75 100 - 61 86 - 81 106 - 52 27 - 230 255 - 309 334 - 378 379 - 136 111 - 439 464 - 532 533 - 166 191 - 523 522 - 210 211 - 115 140 - 347 346 - 218 217 - 561 560 - 526 501 - 174 149 - 258 259 - 77 52 - 36 11 - 307 306 - 577 552 - 62 61 - 450 425 - 569 570 - 268 293 - 79 78 - 233 208 - 571 570 - 534 535 - 527 552 - 224 199 - 409 408 - 521 520 - 621 622 - 493 518 - 107 106 - 511 510 - 298 299 - 37 62 - 224 249 - 405 380 - 236 237 - 120 121 - 393 418 - 206 231 - 287 288 - 593 568 - 34 59 - 483 484 - 226 227 - 73 74 - 276 277 - 588 587 - 288 313 - 410 385 - 506 505 - 597 598 - 337 312 - 55 56 - 300 325 - 135 134 - 4 29 - 501 500 - 438 437 - 311 312 - 598 599 - 320 345 - 211 236 - 587 562 - 74 99 - 473 498 - 278 279 - 394 369 - 123 148 - 233 232 - 252 277 - 177 202 - 160 185 - 331 356 - 192 191 - 119 118 - 576 601 - 317 316 - 462 487 - 42 43 - 336 311 - 515 490 - 13 14 - 210 235 - 473 448 - 342 341 - 340 315 - 413 388 - 514 515 - 144 143 - 146 145 - 541 566 - 128 103 - 184 159 - 488 489 - 454 455 - 82 83 - 70 45 - 221 222 - 241 240 - 412 411 - 591 590 - 592 593 - 276 301 - 452 453 - 256 255 - 397 372 - 201 200 - 232 207 - 466 465 - 561 586 - 417 442 - 409 434 - 238 239 - 389 390 - 26 1 - 510 485 - 283 282 - 281 306 - 449 474 - 324 349 - 121 146 - 111 112 - 434 435 - 507 508 - 103 104 - 319 294 - 455 480 - 558 557 - 291 292 - 553 578 - 392 391 - 552 551 - 55 80 - 538 539 - 367 392 - 340 365 - 272 297 - 266 265 - 401 376 - 279 280 - 516 515 - 178 177 - 572 571 - 154 179 - 263 262 - 6 31 - 323 348 - 481 506 - 178 179 - 526 527 - 444 469 - 273 274 - 132 133 - 275 300 - 261 236 - 344 369 - 63 38 - 5 30 - 301 300 - 86 87 - 9 10 - 344 319 - 428 427 - 400 375 - 350 375 - 235 236 - 337 336 - 616 615 - 381 380 - 58 59 - 492 493 - 555 556 - 459 434 - 368 369 - 407 382 - 166 141 - 70 95 - 380 355 - 34 35 - 49 24 - 126 127 - 403 378 - 509 484 - 613 588 - 208 207 - 143 168 - 406 431 - 263 238 - 595 596 - 218 193 - 183 182 - 195 220 - 381 406 - 64 65 - 371 372 - 531 506 - 218 219 - 144 145 - 475 450 - 547 548 - 363 362 - 337 362 - 214 239 - 110 111 - 600 575 - 105 106 - 147 148 - 599 574 - 622 623 - 319 320 - 36 35 - 258 233 - 266 267 - 481 480 - 414 439 - 169 168 - 479 478 - 224 223 - 181 182 - 351 326 - 466 441 - 85 60 - 140 165 - 91 90 - 263 264 - 188 187 - 446 447 - 607 606 - 341 316 - 143 142 - 443 442 - 354 353 - 162 137 - 281 256 - 549 574 - 407 408 - 575 550 - 171 170 - 389 388 - 390 391 - 250 225 - 536 537 - 227 228 - 84 59 - 139 140 - 485 484 - 573 598 - 356 381 - 314 315 - 299 324 - 370 395 - 166 165 - 63 62 - 507 506 - 426 425 - 479 454 - 545 570 - 376 375 - 572 597 - 606 581 - 278 277 - 303 302 - 190 165 - 230 205 - 175 200 - 529 528 - 18 17 - 458 457 - 514 513 - 617 616 - 298 323 - 162 161 - 471 472 - 81 56 - 182 207 - 539 564 - 573 572 - 596 621 - 64 39 - 571 546 - 554 555 - 388 363 - 351 376 - 304 329 - 123 122 - 135 160 - 157 132 - 599 624 - 451 426 - 162 187 - 502 477 - 508 483 - 141 140 - 303 328 - 551 576 - 471 446 - 161 160 - 465 490 - 3 2 - 138 113 - 309 284 - 452 451 - 414 413 - 540 565 - 210 185 - 350 325 - 383 382 - 2 1 - 598 623 - 97 72 - 485 460 - 315 316 - 19 20 - 31 32 - 546 521 - 320 321 - 29 54 - 330 331 - 92 67 - 480 505 - 274 249 - 22 47 - 304 279 - 493 468 - 424 423 - 39 40 - 164 165 - 269 268 - 445 446 - 228 203 - 384 409 - 390 365 - 283 308 - 374 399 - 361 386 - 94 119 - 237 262 - 43 68 - 295 270 - 400 425 - 360 335 - 122 121 - 469 468 - 189 188 - 377 352 - 367 342 - 67 42 - 616 591 - 442 467 - 558 533 - 395 394 - 3 28 - 476 477 - 257 258 - 280 281 - 517 542 - 505 504 - 302 301 - 14 15 - 523 498 - 393 368 - 46 71 - 141 142 - 477 452 - 535 510 - 237 238 - 232 231 - 5 6 - 75 50 - 278 253 - 68 69 - 584 559 - 503 504 - 281 282 - 19 44 - 411 410 - 290 265 - 579 554 - 85 84 - 65 66 - 9 8 - 484 459 - 427 402 - 195 196 - 617 618 - 418 443 - 101 126 - 268 243 - 92 117 - 290 315 - 562 561 - 255 280 - 488 487 - 578 603 - 80 79 - 57 58 - 77 78 - 417 418 - 246 271 - 95 96 - 234 233 - 530 555 - 543 568 - 396 397 - 22 23 - 29 28 - 502 527 - 12 13 - 217 216 - 522 547 - 357 332 - 543 518 - 151 176 - 69 70 - 556 557 - 247 248 - 513 538 - 204 205 - 604 605 - 528 527 - 455 456 - 624 623 - 284 285 - 27 26 - 94 95 - 486 511 - 192 167 - 372 347 - 129 104 - 349 374 - 313 314 - 354 329 - 294 293 - 377 378 - 291 290 - 433 408 - 57 56 - 215 190 - 467 492 - 383 408 - 569 594 - 209 208 - 2 27 - 466 491 - 147 122 - 112 113 - 21 46 - 284 259 - 563 538 - 392 417 - 458 433 - 464 465 - 297 298 - 336 361 - 607 582 - 553 554 - 225 200 - 186 211 - 33 34 - 237 212 - 52 51 - 620 595 - 492 517 - 585 610 - 257 282 - 520 545 - 541 540 - 269 244 - 609 584 - 109 84 - 247 246 - 562 537 - 172 197 - 166 167 - 264 265 - 129 130 - 89 114 - 204 179 - 51 76 - 415 390 - 54 53 - 219 244 - 491 490 - 494 493 - 87 62 - 158 183 - 517 518 - 358 359 - 105 104 - 285 260 - 343 318 - 348 347 - 615 614 - 169 144 - 53 78 - 494 495 - 576 577 - 23 24 - 22 21 - 41 40 - 467 466 - 112 87 - 245 220 - 442 441 - 411 436 - 256 257 - 469 494 - 441 416 - 132 107 - 468 467 - 345 344 - 608 609 - 358 333 - 418 419 - 430 429 - 130 131 - 127 128 - 115 90 - 364 365 - 296 271 - 260 235 - 229 228 - 232 257 - 189 190 - 234 235 - 195 170 - 117 118 - 487 486 - 203 204 - 142 117 - 582 583 - 561 536 - 7 32 - 387 388 - 333 334 - 420 421 - 317 292 - 327 352 - 564 563 - 39 14 - 177 152 - 144 119 - 426 401 - 248 223 - 566 567 - 53 28 - 106 131 - 473 472 - 525 526 - 327 302 - 382 381 - 222 197 - 610 609 - 522 521 - 291 316 - 339 338 - 328 329 - 31 56 - 247 222 - 185 186 - 554 529 - 393 392 - 108 83 - 514 489 - 48 23 - 37 12 - 46 45 - 25 0 - 463 462 - 101 76 - 11 10 - 548 573 - 137 112 - 123 124 - 359 360 - 489 490 - 368 367 - 71 96 - 229 230 - 496 495 - 366 365 - 86 85 - 496 497 - 482 481 - 326 301 - 278 303 - 139 114 - 71 70 - 275 276 - 223 198 - 590 565 - 496 521 - 16 41 - 501 476 - 371 370 - 511 536 - 577 602 - 37 38 - 423 422 - 71 72 - 399 424 - 171 146 - 32 33 - 157 182 - 608 583 - 474 499 - 205 206 - 539 514 - 601 600 - 419 420 - 208 183 - 537 538 - 110 85 - 105 130 - 288 289 - 455 430 - 531 532 - 337 338 - 227 202 - 120 145 - 559 534 - 261 262 - 241 216 - 379 354 - 430 405 - 241 266 - 396 421 - 317 318 - 139 164 - 310 285 - 478 477 - 532 557 - 238 213 - 195 194 - 359 384 - 243 242 - 432 457 - 422 447 - 519 518 - 271 272 - 12 11 - 478 453 - 453 428 - 614 613 - 138 139 - 96 97 - 399 398 - 55 54 - 199 174 - 566 591 - 213 188 - 488 513 - 169 194 - 603 602 - 293 318 - 432 431 - 524 523 - 30 31 - 88 63 - 172 173 - 510 509 - 272 273 - 559 558 - 494 519 - 374 373 - 547 572 - 263 288 - 17 16 - 78 103 - 542 543 - 131 132 - 519 544 - 504 529 - 60 59 - 356 355 - 341 340 - 415 414 - 285 286 - 439 438 - 588 563 - 25 50 - 463 438 - 581 556 - 244 245 - 500 475 - 93 92 - 274 299 - 351 350 - 152 127 - 472 497 - 440 415 - 214 215 - 231 230 - 80 81 - 550 525 - 511 512 - 483 458 - 67 68 - 255 254 - 589 588 - 147 172 - 454 453 - 587 612 - 343 368 - 508 509 - 240 265 - 49 48 - 184 183 - 583 558 - 164 189 - 461 436 - 109 134 - 196 171 - 156 181 - 124 99 - 531 530 - 116 91 - 431 430 - 326 325 - 44 45 - 507 482 - 557 582 - 519 520 - 167 142 - 469 470 - 563 562 - 507 532 - 94 93 - 3 4 - 366 391 - 456 431 - 524 549 - 489 464 - 397 398 - 98 97 - 377 402 - 413 412 - 148 149 - 91 66 - 308 333 - 16 15 - 312 287 - 212 211 - 486 461 - 571 596 - 226 251 - 356 357 - 145 170 - 295 294 - 308 309 - 163 138 - 364 339 - 416 417 - 402 401 - 302 277 - 349 348 - 582 581 - 176 175 - 254 279 - 589 614 - 322 297 - 587 586 - 221 246 - 526 551 - 159 158 - 460 461 - 452 427 - 329 330 - 321 322 - 82 107 - 462 461 - 495 520 - 303 304 - 90 65 - 295 320 - 160 159 - 463 464 - 10 35 - 619 594 - 403 402 - |} - -let process_str tinyUF = - match Ext_string.split tinyUF '\n' with - | number :: rest -> - let n = int_of_string number in - let store = Union_find.init n in - List.iter - (fun x -> - match Ext_string.quick_split_by_ws x with - | [a; b] -> - let a, b = (int_of_string a, int_of_string b) in - Union_find.union store a b - | _ -> ()) - rest; - Union_find.count store - | _ -> assert false - -let process_file file = - let ichan = open_in_bin file in - let n = int_of_string (input_line ichan) in - let store = Union_find.init n in - let edges = Int_vec_vec.make n in - let rec aux i = - match input_line ichan with - | exception _ -> () - | v -> - (* if i = 0 then - print_endline "processing 100 nodes start"; - *) - (match Ext_string.quick_split_by_ws v with - | [a; b] -> - let a, b = (int_of_string a, int_of_string b) in - Int_vec_vec.push edges (Vec_int.of_array [|a; b|]) - | _ -> ()); - aux ((i + 1) mod 10000) - in - aux 0; - (* indeed, [unsafe_internal_array] is necessary for real performnace *) - let internal = Int_vec_vec.unsafe_internal_array edges in - for i = 0 to Array.length internal - 1 do - let i = Vec_int.unsafe_internal_array (Array.unsafe_get internal i) in - Union_find.union store (Array.unsafe_get i 0) (Array.unsafe_get i 1) - done; - (* Union_find.union store a b *) - Union_find.count store -let suites = - __FILE__ - >::: [ - (__LOC__ >:: fun _ -> OUnit.assert_equal (process_str tinyUF) 2); - (__LOC__ >:: fun _ -> OUnit.assert_equal (process_str mediumUF) 3); - (* - __LOC__ >:: begin fun _ -> - OUnit.assert_equal (process_file "largeUF.txt") 6 - end; - *) - ]