Thread: Case-insensitive hash

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    1

    Case-insensitive hash

    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?

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    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.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help it won't compile!!!!!
    By esbo in forum C Programming
    Replies: 58
    Last Post: 01-04-2009, 03:22 PM
  2. Segmentation fault!?!?!?
    By Viper187 in forum Windows Programming
    Replies: 57
    Last Post: 10-02-2008, 09:40 PM
  3. Format Precision & Scale
    By mattnewtoc in forum C Programming
    Replies: 1
    Last Post: 09-16-2008, 10:34 AM
  4. Keypress reading
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 06-16-2004, 12:16 PM
  5. returning to a spot in the code
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 09-22-2001, 05:24 AM