import type { Fn } from "@thi.ng/api" ; import { sortByCachedKey } from "@thi.ng/arrays/sort-cached" ; import { DisjointSet } from "./disjoint-set.js" ; remarks Edges can be of any type, but requires unsigned integer vertex IDs. The
 * latter can be extracted via the user supplied `verts` function. The edge
 * weights are extracted via the `cost` function.
 *
 * The `maxID` arg should equal or greater than the largest vertex ID referenced
 * by the given edges.
 *
 * The function returns a new array of the original edges, satisfying the MST
 * criteria. The result edges will be in ascending order, based on the supplied
 * cost function. The cost function is called once for each edge and return
 * values will be cached prior to sorting (see
 *  {@link @thi.ng/arrays#sortByCachedKey} for details).
 *
 * Reference:  https example thi param edges param maxID param cost param verts typeParam export const mst = < T > ( edges , maxID , cost , verts ) => { const graph = new DisjointSet ( maxID + 1 ) ; const res = [ ] ; for ( let e of sortByCachedKey ( edges , cost ) ) { const v = verts ( e ) ; if ( ! graph . unified ( v [ 0 ] , v [ 1 ] ) ) { graph . union ( v [ 0 ] , v [ 1 ] ) ; res . push ( e ) ; } } return res ; } ;