0

I want to hold a list of strings which performs well when searching for a specific element. As mentioned in the following cheat sheet, Dictionary scales best for this type of operation: http://courses.essex.ac.uk/ce/ce318/www/documents/references/cSharpDataStructuresCheatSheet.pdf However, I don't need a dictionary as I'm only storing strings, not key value pairs (i.e. I'm only interested in the keys). Does anyone know what data structure the dictionary uses for its keys? KeyCollection seems to only be available to Dictionary. My guess is it's using some sort of hashing algorithm, but wondered if anyone had any insight on this? Thanks in advance.

JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
  • 1
    You may also find this interesting: http://stackoverflow.com/questions/3521532/how-is-the-c-net-3-5-dictionary-implemented - you can use ILSpy (http://ilspy.net/) to investigate the structure of the classes yourself, too. It's pretty cool. – dash Sep 18 '12 at 11:08
  • Thanks for the pointer - looks interesting, useful, and free; good combination. – JohnLBevan Sep 18 '12 at 11:13

1 Answers1

4

You could use a HashSet<string>.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • According to this site: http://www.dotnetperls.com/hashset - the HashSet performs worse than Dictionary. That seems surprising if we assume the dictionary uses a hashset for its key collection. – JohnLBevan Sep 18 '12 at 13:04
  • @JohnLBevan you should see if it is enough of a problem. ~30 NS isn't bad. – Daniel A. White Sep 18 '12 at 13:53
  • True, it's not really a problem - more academic. If Dictionary has to do more than HashSet, it's wierd that it should be faster. The explanation would be that a Dictionary therefore has a faster data structure available to its keycollection, so it's strange that this isn't available as its own data structure. Thanks for your help though - much appreciated. – JohnLBevan Sep 18 '12 at 16:25