/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit.Abstractions/Internals/GraphValidation/NodeTable.cs
42 строки
1 KB
Chris Patterson
Adding multiple framework support for net461, netstandard2.0, netstandard2.1, and net6.0 where appropriate
07 май 2022, 04:26
07 май 2022, 04:26
71bb847
Код
Авторство
О чём код?
namespace MassTransit.Internals.GraphValidation { using System.Collections.Generic; /// <summary> /// Maintains an index of nodes so that regular ints can be used to execute algorithms /// against objects with int-compare speed vs. .Equals() speed /// </summary> /// <typeparam name="T"></typeparam> public class NodeTable<T> where T : notnull { readonly IDictionary<T, int> _nodes; int _count; public NodeTable(int capacity) { _nodes = new Dictionary<T, int>(capacity); } /// <summary> /// Returns the index for the specified key, which can be any type that supports /// equality comparison /// </summary> /// <param name="key">The key to retrieve</param> /// <returns>The index that uniquely relates to the specified key</returns> public int this[T key] { get { if (_nodes.TryGetValue(key, out var value)) return value; value = ++_count; _nodes.Add(key, value); return value; } } } }