notgiven688 / CcHashSet

Single-file generic C# implementation of a concurrent (allowing add/remove operations from different threads) HashSet.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CcHashSet


Single-file generic and performant C# implementation of a concurrent (allowing add/remove operations from different threads) HashSet.

Usage

CcHashSet<string> cch = new CcHashSet<string>();

cch.Add("abc");
cch.Add("def");
cch.Add("ghi");
cch.Add("abc");

Console.WriteLine(cch.Count);

cch.Remove("abc");

foreach(string str in cch)
    Console.WriteLine(str);


// outputs:
// 3
// ghi
// def

Benchmark

Intel(R) Xeon(R) CPU E5-4650L 0 @ 2.60GHz
dotnet --version 5.0.400
Linux

Adding 4n (int,int)-structs to the hashset and removing 4n (int,int)-structs from the same hashset afterwards. The structs are composed of pseudo-random numbers in the range of [1, n/1000].

a) In Serial using System.Collections.Generic.HashSet
b) In Serial using CcHashSet.
c) In Parallel utilizing 4 Threads using CcHashSet.
d) In Parallel utilizing 4 Threads using the System.Collections.Concurrent.ConcurrentDictionary.

Times in ms:

n (a) (b) (c) (d)
40,000 23 36 26 22
100,000 45 85 47 47
3,000,000 4992 4979 1993 7574
10,000,000 18301 19590 7716 47080

About

Single-file generic C# implementation of a concurrent (allowing add/remove operations from different threads) HashSet.

License:MIT License


Languages

Language:C# 100.0%