Any implications over this String Equal function?

DaedalusDaedalus Member Posts: 36
I used and tested the following piece of code to compare strings
function stringsEqual(string x, string y) returns (bool) {
return sha3(x) == sha3(y) ? true : false;
I came up with it, to avoid having to iterate through bytes manually, and having a short helper function for string comparison. It is in fact the cheapest string comparison function I have seen so far, which is another thing I'm aiming for, lowest gas cost, albeit there's less than a 1% gas efficiency over the next best.

However, what I'm wondering is what are the implications of using sha3 to compare strings. I understand there is a theoretical chance of a collision happening, so is it against best practices to use a function like this? The chances of a collision I believe are less than the chances of the big bang ever occurring :P. And even in the case of collisions, if the string comparison ends up being between an array or list of strings, known ahead of time to not have any collisions, is this function safe, or are there further implications to it?

Sign In or Register to comment.