Posts Tagged key

String Keys vs. Int Keys

Tags: , , , , , ,

Now that we know you can use int keys with Object, it’s time to test whether or not this is any faster than String keys. Today’s article does just that and also tests int and String keys with Dictionary.

Read the rest of this article »


Using Non-String Keys with Object

Tags: , , , ,

Pop quiz: what’s the difference between an Object and a Dictionary? If you said “Dictionary can have non-String keys”, you bought into a common myth. Today’s article shows the cases where the lowly Object class will use non-String keys whether you like it or not. Read on for the details.

Read the rest of this article »


Maps With Int Keys: Array vs. Dictionary

Tags: , , , , , , , ,

Behind the scenes Array holds its values in two ways: a densely-packed array at the beginning and a sparsely-packed map after that. This means it can be used as a map where the keys are indexes and not take up a huge amount of wasted space. Dictionary can also have int keys. Which is faster? Today we’ll find out!

Read the rest of this article »


Typesafe Dictionary

Tags: , , , , ,

One of the advantages of using Dictionary instead of Object when mapping key-value pairs is that you can use whatever type of key you want, not just a String. However, a recent comment points out that the keys are still checked with the loose equality operator (==) and you can therefore get clashes like 4 == "4". For today’s article, I’ve written a TypesafeDictionary class that allows you to overcome this limitation. Read on for the implementation, performance testing, and more.

Read the rest of this article »