HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

StringHash() absurdity

09-19-2009, 02:10 AM#1
ToukoAozaki
StringHash("BLIZZARD IS RETARDED") == StringHash("blizzard is retarded") is true.

Apparantly Blizzard did a retarded implementation of StringHash.
09-19-2009, 02:14 AM#2
Vexorian
Sounds more like they wanted to make it easier to move on from gamecache to them .
09-19-2009, 02:29 AM#3
ToukoAozaki
Quote:
Originally Posted by Vexorian
Sounds more like they wanted to make it easier to move on from gamecache to them .

Was gamecache case-insensitive? Whoa.

BTW I've written a function to deal with this. While this is quite slower than a single native call, it will prove useful when case sensitivity is important. This will be included in StringUtils library.

Collapse JASS:
    function StringHashCS takes string s returns integer
        local integer ri = 0
        local integer li = 0
        local integer length = StringLength(s)
        local string result = ""
        local string ss
        
        loop
            exitwhen ri >= length
            set ss = SubString(s, ri, ri+1)
            if ss == "\\" then
                set result = result + SubString(s, li, ri) + "\\\\"
                
                set ri = ri + 1
                set li = ri
            elseif StringCase(ss, false) != ss then
                // this is a uppercase character; make it different.
                set result = result + SubString(s, li, ri) + "\\" + ss
                
                set ri = ri + 1
                set li = ri
            else
                set ri = ri + 1
            endif
        endloop
        
        set result = result + SubString(s, li, length)
        
        return StringHash(result)
    endfunction
09-19-2009, 03:41 PM#4
Troll-Brain
Good to know.
09-20-2009, 06:30 PM#5
Strilanc
I was expecting a post about the fact that the string is hashed *before* passing it to the function, meaning there are non-equivalent strings which will overwrite each other.

Who cares about case insensitivity, when that bug-waiting-to-happen exists?
09-20-2009, 07:08 PM#6
TheDamien
StringHash also features "slash insensitivity."
09-21-2009, 01:16 PM#7
ToukoAozaki
Quote:
Originally Posted by Strilanc
I was expecting a post about the fact that the string is hashed *before* passing it to the function, meaning there are non-equivalent strings which will overwrite each other.

Who cares about case insensitivity, when that bug-waiting-to-happen exists?

What do you mean?

Edit: Oh, I see. You mean the hash collision issue. Yes, it is a problem, but there are standard ways to circumvent that problem. However, since Jass doesn't support polymorphism pretty much there was no way to incorporate that inside hashtable implementation. It has to be done manually. Should I make a library for that?

BTW StringLib doesn't have any problem from this since hash is only used to determine each bytes, and confirmed no hash collision among them.

Quote:
Originally Posted by TheDamien
StringHash also features "slash insensitivity."
While I didn't know that in the first place, the nature of my implementation addressed that problem as well.
09-21-2009, 03:16 PM#8
Troll-Brain
Well, i guess if we really need strings to save datas, game cache is the way.
09-21-2009, 05:28 PM#9
Vexorian
Quote:
Originally Posted by Troll-Brain
Well, i guess if we really need strings to save datas, game cache is the way.
How would that be better in anyway? I bet gc is slash insensitive as well.
09-21-2009, 05:43 PM#10
Troll-Brain
Quote:
Originally Posted by Vexorian
How would that be better in anyway?
game cache is case sensitive ?

Quote:
I bet gc is slash insensitive as well.
I will test it later.
09-21-2009, 05:56 PM#11
Strilanc
Quote:
Originally Posted by Troll-Brain
game cache is case sensitive ?

No it's not.

The main thing Game Cache has going for it is ... uh ... nothing. I guess it doesn't have the string collision issue, but it's vulnerable to malicious clients injecting values.
09-21-2009, 06:38 PM#12
Troll-Brain
Hmm ok, so just forgot what i've said ...
09-21-2009, 07:02 PM#13
Anitarf
People use StringHash? I thought that was mainly for backwards compatibility.
09-21-2009, 07:07 PM#14
Troll-Brain
Personally, i don't use it.
Currently i can't figure a case where strings are absolutely needed to link a data, where you can't do it with an integer instead.
But again, maybe i'm wrong ...
09-21-2009, 07:31 PM#15
Strilanc
I use it for storing and retrieving actions associated with mode commands. I have asserts to ensure there are no collisions (and the commands don't change, so it's safe).