Just XOR hashes of each line together. This is cheaper (performance wise) than string concatenation, and as far as I can see, it is not prone to collisions. Suppose each line is 5 characters long and each character takes 1 byte. In the first, you hash 15 bytes into 4 bytes (int). In the second, you concatenate all 3 lines (expensive operation) to get one line of 15 bytes, and you hash them up to 4 bytes. Both convert 15 bytes to 4, so in theory both are pretty similar in terms of collisions.
In reality, there is a little difference in the probability of collisions, but in practice this does not always matter. It depends on the data that the rows will have. If all three lines are equal and each hash has a value of 0001 (I use a prime for example only). If all 3 are equal, then xoring the first two will get you 0000 and xoring the third, and you will return to 0001 . By combining strings, this can be avoided due to some performance (if you are writing a program critical for performance, I would not concatenate strings in the inner loop).
So, in the end, I really didnโt give an answer in the end, for the simple reason that it really isnโt. It all depends on where and how it will be used.
source share