mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
* Make use of language features line AsyncDispose, init etc. * Fix build errors * Improve Unit Tests * Improve Unit Tests * Improve Unit Tests * Update samples * Remove obsolete benchmarks * Code cleanup * Improve unit tests * Improve Unit Tests * Fix Unit Tests * Improve Unit Tests * Improve Unit Tests * Restore unit tests * Exclude load tests from unit tests
31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
namespace MQTTnet.Server.Internal;
|
|
|
|
/// <summary>
|
|
/// Helper class that stores subscriptions by their topic hash mask.
|
|
/// </summary>
|
|
public sealed class TopicHashMaskSubscriptions
|
|
{
|
|
public Dictionary<ulong, HashSet<MqttSubscription>> SubscriptionsByHashMask { get; } = new Dictionary<ulong, HashSet<MqttSubscription>>();
|
|
|
|
public void AddSubscription(MqttSubscription subscription)
|
|
{
|
|
if (!SubscriptionsByHashMask.TryGetValue(subscription.TopicHashMask, out var subscriptions))
|
|
{
|
|
subscriptions = new HashSet<MqttSubscription>();
|
|
SubscriptionsByHashMask.Add(subscription.TopicHashMask, subscriptions);
|
|
}
|
|
subscriptions.Add(subscription);
|
|
}
|
|
|
|
public void RemoveSubscription(MqttSubscription subscription)
|
|
{
|
|
if (SubscriptionsByHashMask.TryGetValue(subscription.TopicHashMask, out var subscriptions))
|
|
{
|
|
subscriptions.Remove(subscription);
|
|
if (subscriptions.Count == 0)
|
|
{
|
|
SubscriptionsByHashMask.Remove(subscription.TopicHashMask);
|
|
}
|
|
}
|
|
}
|
|
} |