Hashed Strings

Strings gives us, humans, a way to easily manage and identify objects that are associated with it. It’s easily readable and immediately gives a description of what we’re looking for. Unfortunately, computers doesn’t think the way we do. In order for a string to be understood by a computer, it needs to convert it to bytes which ultimately are read as numbers. Managing a number of objects by giving them string identifiers is not a bad idea. But if you have thousands and thousands of objects, it’ll definitely kill your performance. This is where the Hashed String comes in. Hashed Strings gives the best of both worlds. A hashed string (optionally for debugging purposes) stores the actual string for us to read and at the same time, the Hashed string computes the raw input string then stores a hashed integral value that associates the given string.

The source code provided below is fairly straight-forward and easy to understand.

Here’s a brief explanation of the interface:

HashedString( const CHAR * const pIdentStr ) – Passing a string automatically computers the hashed value by calling HashName().
ULONG GetHashedID( void ) – Simply returns the hashed value of the given string.
void * HashName( const CHAR * pIdentStr ) – Resets the string value then re-computes the new Hashed value from the new string.

A couple of relational operators are also provided such as <, > and == for convenience. The has function was developed by Paul Hsiehs. You can find more information about his hash function in here: http://www.azillionmonkeys.com/qed/hash.html

Hash Function:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s