Question: I'm trying to check if two strings are identical as quickly as possible. Can I protect myself from hash collisions without also comparing the entire string?

I've got a cache of items that are keyed by a string. I store the hash of the string, the length of the string, and the string itself. (I'm currently using [djb2](http://www.cse.yorku.ca/~oz/hash.html) to generate the hash.)

To check if an input string is a match to an item in the cache, I compute the input's hash, and compare it to the stored hash. If that matches, I compare the length of the input (which I got as a side effect of computing the hash) to the stored length. Finally, if that matches, I do a full string comparison of the input and the stored string.

Is it necessary to do that full string comparison? For example, is there a string hashing algorithm that can mathematically guarantee that no two strings *of the same length* will generate the same hash? If not, can an algorithm guarantee that two different strings of the same length will generate different hash codes if any of the first N characters differ?

Basically, any string comparison scheme that offers O(1) performance when the strings differ but better than O(n) performance when they match would be an improvement over what I'm doing now.

Answer: 
I have tried similar thing as you describe, and the main problem I see, is that u can't create `ObjectSet<T>` for derived type. So you will not have `ObjectSet<Person>` repository.
If you derive all your Entities from for example BusinessObject entity, you will be able to work only with `ObjectSet<BusinessObject>`. If you want to query only Person repository, you can write query like `Context.BusinessObjectSet.OfType<Person>().ToList()` but i think it will not generate proper SQL under the hood and will first get full BusinessObject rows and then filter out Person entities in memory. So I guess it will have huge performance impact.
One disadvantage of using inheritance in your model is that you won't be able to surface your model through WCF Data Services (OData) as it doesn't currently support derived entities.