Dictionary with no "payload" in .Net

Sometimes I need to check for duplicate identifiers in a set of values, and usually I use a dictionary for this - using only the keys and leaving the values ​​empty.

Please note that this is a tough and highly optimized code, so please don't cry about “premature optimization”! Assuming that the scenarios in which the CPU and RAM are compressed to the limit, I wanted to collect opinions on more optimal solutions; presumably, something like the Lookup class, will avoid unnecessary RAM allocations and thus be a little faster. Are there such classes as a third party, and perhaps some class that I missed in BCL?

I understand that Google has released code for fast and compact classes of dictionaries - maybe there is something there that can be ported to C # /. Net?

Thank.

+3
source share
1 answer

Use the HashSet class in .NET 3.5.

HashSet<int> set = new HashSet<int>() { 1, 2, 3 };
set.Add(5);
for (int index = 0; index < 10; index++)
{
    Console.WriteLine("{0} : {1}", index, set.Contains(index));
}
+6
source

Source: https://habr.com/ru/post/1729985/


All Articles