UNPKG

1.57 kBTypeScriptView Raw
1export declare type KeyFunc<T> = (x: T) => string;
2export declare type DepFunc<T> = (x: T) => string[];
3/**
4 * Return a topological sort of all elements of xs, according to the given dependency functions
5 *
6 * Returns tranches of packages that do not have a dependency on each other.
7 *
8 * Dependencies outside the referenced set are ignored.
9 *
10 * Not a stable sort, but in order to keep the order as stable as possible, we'll sort by key
11 * among elements of equal precedence.
12 *
13 * @param xs - The elements to sort
14 * @param keyFn - Return an element's identifier
15 * @param depFn - Return the identifiers of an element's dependencies
16 */
17export declare function topologicalSort<T>(xs: Iterable<T>, keyFn: KeyFunc<T>, depFn: DepFunc<T>): Toposorted<T>;
18/**
19 * For now, model a toposorted list as a list of tranches.
20 *
21 * Modeling it like this allows for SOME parallelism between nodes,
22 * although not maximum. For example, let's say we have A, B, C with
23 * C depends-on A, and we sort to:
24 *
25 * [[A, B], [C]]
26 *
27 * Now, let's say A finishes quickly and B takes a long time: we still have
28 * to wait for B to finish before we could start C in this modeling.
29 *
30 * The better alternative would be to model a class that keeps the dependency
31 * graph and unlocks nodes as we go through them. That's a lot of effort
32 * for now, so we don't do that yet.
33 *
34 * We do declare the type `Toposorted<A>` here so that if we ever change
35 * the type, we can find all usage sites quickly.
36 */
37export declare type Toposorted<A> = readonly A[][];
38//# sourceMappingURL=toposort.d.ts.map
\No newline at end of file