Relative Content

Tag Archive for dictionary

Long dictionary/map key vs shorter key + equality check for an auth cache

I’m implementing an API key based authentication scheme and I’m caching valid API key entries (hash, scope etc.) in a memory cache. For the cache key, I had been using the first 8 characters of the base 64 representation of the key hash. I did this because there are 64^8 (281,474,976,710,656) possible keys, so I thought that would be more than enough.

Efficiency of C# dictionaries

C# dictionaries are a simple way to find if something exists etc etc. I have a question though on how they work. Let’s say instead of a dictionary I use an ArrayList. Instead of using ContainsKey (or an equivalent method in another language) I loop through the ArrayList to check if something exists there (or performing binary search if data is sorted or something similar). What’s the difference in efficiency? Is the ContainsKey method using some more efficient way rather than looping through the keys and check if what I am searching exists?