views:

172

answers:

3

I'm interested in an answer that explain the best in each situation.

In particular which is best for:

  • few values
  • lots of values
  • many values with only few extensively used
  • read only or nearly read only map
  • write-a-lot map
  • fast membership without retrieval
  • memory footprint with large value
  • others
A: 

A red-black tree would be the most natural choice.

A hash table will get you speed at the cost of memory.

You can also reach a balance between the two by creating a red-black tree of the string's hash value, as it's safe to assume the hash numbers can be compared faster than the actual strings. This would be particularly useful when the strings (and therefore the hashes) can be calculated in advance.

Shmoopty
A map/dictionary is not a data structure.Maybe with map/dictionary do you means RBTre?
Mykelyk
Indeed I did. Corrected.
Shmoopty
A: 

Map/Dictionary object should be used if store less then 100 values and do not store values with more then 100 signs. If you need more, you would better use database storage.

Number of Read/Write operations doesn't matter.

Bogdan Gusiev
Map is an interface, Dictionary is an abstract class, so neither can be instantiated. A HashMap (implements Map) is fine for much higher numbers of values than 100. A Hashtable (extends Dictionary implements Map) is very close to a HashMap, but because its thread-safe is somewhat less efficient.
Jim Ferrans
Mykelyk didn't mentioned he is talking about Java.Map and Dictionary is the abstract names that have it's own classes in each programming language.
Bogdan Gusiev
A: 

Maybe you'll find this question interesting.

Nick D