-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/v4' into processor_merge
- Loading branch information
Showing
10 changed files
with
197 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
|
||
namespace SharpHoundCommonLib; | ||
|
||
/// <summary> | ||
/// A concurrent implementation of a hashset using a ConcurrentDictionary as the backing structure. | ||
/// </summary> | ||
public class ConcurrentHashSet : IDisposable{ | ||
private ConcurrentDictionary<string, byte> _backingDictionary; | ||
|
||
public ConcurrentHashSet() { | ||
_backingDictionary = new ConcurrentDictionary<string, byte>(); | ||
} | ||
|
||
public ConcurrentHashSet(StringComparer comparison) { | ||
_backingDictionary = new ConcurrentDictionary<string, byte>(comparison); | ||
} | ||
|
||
/// <summary> | ||
/// Attempts to add an item to the set. Returns true if adding was successful, false otherwise | ||
/// </summary> | ||
/// <param name="item"></param> | ||
/// <returns></returns> | ||
public bool Add(string item) { | ||
return _backingDictionary.TryAdd(item, byte.MinValue); | ||
} | ||
|
||
/// <summary> | ||
/// Attempts to remove an item from the set. Returns true of removing was successful, false otherwise | ||
/// </summary> | ||
/// <param name="item"></param> | ||
/// <returns></returns> | ||
public bool Remove(string item) { | ||
return _backingDictionary.TryRemove(item, out _); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if the given item is in the set | ||
/// </summary> | ||
/// <param name="item"></param> | ||
/// <returns></returns> | ||
public bool Contains(string item) { | ||
return _backingDictionary.ContainsKey(item); | ||
} | ||
|
||
/// <summary> | ||
/// Returns all values in the set | ||
/// </summary> | ||
/// <returns></returns> | ||
public IEnumerable<string> Values() { | ||
return _backingDictionary.Keys; | ||
} | ||
|
||
public void Dispose() { | ||
_backingDictionary = null; | ||
GC.SuppressFinalize(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.