I need to implement a case-insensitive hash function. I also need to compare two strings (case-insensitive) allowing only for letters and apostrophes. I see two approaches:
Convert both strings to lowercase, and then do a normal compare and (case-sensitive) hash.
Have a case-insensitive hash and have a case-insensitive compare.
Any ideas on which is faster (speed really matters), or better ideas?
I would think it is more efficient to convert all input to lower case (or upper case) as it is inputted into the program. If your hash and comparison functions need to implement case-insensitivity then you will pay that price every time you perform a hashing or comparison operation, whereas the total number of input operations is probably far less than that.
In other words, if H is the number of hash operations your program performs, and C is the number of comparisons, and N is the number of data items inputted into the program, then if H + C > N, it is more important to maximize the speed of hashing and comparison rather than the speed of input.
I think that the differences in efficiency would be tiny and that neither option would be a bottleneck in your code. You wont get the fastest option by merely asking for an opinion. You'll get the fastest option by taking into account much of the surrounding code. For that it's either DIY or post some code.