Use HashSet instead of "seen" Hashtable.

In our code (originally created in .Net 1.1)  there are a few examples of "seen" Hashtable pattern
 
Hashtable seen = new Hashtable();
for (int i = 0; i < nCount; i++)
{
    if (seen[key] == null)
    {
        //Do the changes
        seen.Add(key, key);
    }
}
 
It's better to use type-safe HashSet:
 
HashSet<string> seen = new HashSet<string>();
for (int i = 0; i < nCount; i++)
{
    if (!seen.Contains(key))
    {
        //Do the changes
        seen.Add(key);
    }
}
posted @ Wednesday, May 13, 2009 12:09 AM
Print

Comments on this entry:

# re: Use HashSet instead of "seen" Hashtable.

Left by web development company at 8/20/2009 7:48 AM
Gravatar
That was inspiring,

Hashtable is a great class you can use it whenever you want to encrease the performance

Thanks for bringing this up

Your comment:



(not displayed)

 
 
 
 
 

Live Comment Preview:

 
«April»
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910