/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit.Abstractions/Internals/GraphValidation/TopologicalSort.cs
58 строк
1 KB
Chris Patterson
Huge push towards optimization on startup, state machines, type discovery, caching, and the consume pipeline. Rebuilt the dispatch filter as a consume context filter for message type dispatch.
27 мар 2024, 02:43
27 мар 2024, 02:43
c17b1de
Код
Авторство
О чём код?
namespace MassTransit.Internals.GraphValidation { using System.Collections.Generic; using System.Linq; public class TopologicalSort<T, TNode> where TNode : Node<T>, ITopologicalSortNodeProperties where T : notnull { readonly AdjacencyList<T, TNode> _list; readonly List<TNode> _results; readonly IEnumerable<TNode> _sourceNodes; public TopologicalSort(AdjacencyList<T, TNode> list) { _list = list; _results = new List<TNode>(); _sourceNodes = _list.SourceNodes; Sort(); } public TopologicalSort(AdjacencyList<T, TNode> list, T source) { _list = list; _results = new List<TNode>(); var sourceNode = list.GetNode(source); _sourceNodes = Enumerable.Repeat(sourceNode, 1); Sort(); } public IEnumerable<TNode> Result => _results; void Sort() { foreach (var node in _sourceNodes) { if (!node.Visited) Sort(node); } } void Sort(TNode node) { node.Visited = true; foreach (Edge<T, TNode> edge in _list.GetEdges(node)) { if (!edge.Target.Visited) Sort(edge.Target); } _results.Add(node); } } }