MCPcopy Create free account
hub / github.com/esengine/esengine / topologicalSort

Function topologicalSort

packages/runtime-core/src/utils/DependencyUtils.ts:327–350  ·  view source on GitHub ↗
(
    items: T[],
    options: TopologicalSortOptions = {}
)

Source from the content-addressed store, hash-verified

325 * ```
326 */
327export function topologicalSort<T extends IDependable>(
328 items: T[],
329 options: TopologicalSortOptions = {}
330): TopologicalSortResult<T> {
331 const {
332 algorithm = 'kahn',
333 detectCycles = true,
334 resolveId = resolveDependencyId
335 } = options;
336
337 if (items.length === 0) {
338 return { sorted: [], hasCycles: false };
339 }
340
341 const result = algorithm === 'kahn'
342 ? kahnSort(items, resolveId)
343 : dfsSort(items, resolveId);
344
345 if (result.hasCycles && detectCycles) {
346 logger.warn(`Circular dependency detected among: ${result.cycleIds?.join(', ')}`);
347 }
348
349 return result;
350}
351
352// ============================================================================
353// 依赖验证 | Dependency Validation

Callers 4

_sortByDependenciesMethod · 0.90
_topologicalSortMethod · 0.90
validateDependenciesFunction · 0.85

Calls 4

kahnSortFunction · 0.85
dfsSortFunction · 0.85
warnMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected