< Summary

Class:SharpHoundCommonLib.ConcurrentHashSet
Assembly:SharpHoundCommonLib
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\ConcurrentHashSet.cs
Covered lines:9
Uncovered lines:13
Coverable lines:22
Total lines:60
Line coverage:40.9% (9 of 22)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%100%
.ctor(...)100%10100%
Add(...)100%10100%
Remove(...)100%100%
Contains(...)100%10100%
Values()100%100%
Dispose()100%100%

File(s)

D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\ConcurrentHashSet.cs

#LineLine coverage
 1using System;
 2using System.Collections.Concurrent;
 3using System.Collections.Generic;
 4
 5namespace SharpHoundCommonLib;
 6
 7/// <summary>
 8/// A concurrent implementation of a hashset using a ConcurrentDictionary as the backing structure.
 9/// </summary>
 10public class ConcurrentHashSet : IDisposable{
 11    private ConcurrentDictionary<string, byte> _backingDictionary;
 12
 013    public ConcurrentHashSet() {
 014        _backingDictionary = new ConcurrentDictionary<string, byte>();
 015    }
 16
 16217    public ConcurrentHashSet(StringComparer comparison) {
 8118        _backingDictionary = new ConcurrentDictionary<string, byte>(comparison);
 8119    }
 20
 21    /// <summary>
 22    /// Attempts to add an item to the set. Returns true if adding was successful, false otherwise
 23    /// </summary>
 24    /// <param name="item"></param>
 25    /// <returns></returns>
 2726    public bool Add(string item) {
 2727        return _backingDictionary.TryAdd(item, byte.MinValue);
 2728    }
 29
 30    /// <summary>
 31    /// Attempts to remove an item from the set. Returns true of removing was successful, false otherwise
 32    /// </summary>
 33    /// <param name="item"></param>
 34    /// <returns></returns>
 035    public bool Remove(string item) {
 036        return _backingDictionary.TryRemove(item, out _);
 037    }
 38
 39    /// <summary>
 40    /// Checks if the given item is in the set
 41    /// </summary>
 42    /// <param name="item"></param>
 43    /// <returns></returns>
 2744    public bool Contains(string item) {
 2745        return _backingDictionary.ContainsKey(item);
 2746    }
 47
 48    /// <summary>
 49    /// Returns all values in the set
 50    /// </summary>
 51    /// <returns></returns>
 052    public IEnumerable<string> Values() {
 053        return _backingDictionary.Keys;
 054    }
 55
 056    public void Dispose() {
 057        _backingDictionary = null;
 058        GC.SuppressFinalize(this);
 059    }
 60}