Generate a commutative hash based on three sets of numbers?

Posted by DarkAmgine on Stack Overflow See other posts from Stack Overflow or by DarkAmgine
Published on 2009-05-05T19:40:59Z Indexed on 2010/05/09 23:08 UTC
Read the original article Hit count: 220

Filed under:
|
|

I need to generate a commutative hash based on three sets of "score" structs.

Each score has a "start", an "end" and a "number".

Both start and end are usually huge numbers (8-9 digits) but number is just from 1 to 4.

I need them to be commutative so the order does not matter. I'm using XOR at the moment but it seems to be giving bad results.

Since I'm working with large large datasets, I'd prefer a performance-friendly solution. Any suggestions? Thanks =]

	public static int getCustomHash(cnvRegion c1, cnvRegion c2, cnvRegion c3)
	{
		int part1 = (c1.startLocation * c2.startLocation * c3.startLocation);
		int part2 = (c1.endLocation * c2.endLocation * c3.endLocation);
		int part3 = (c1.copyNumber + c2.copyNumber + c3.copyNumber)*23735160;
		return part1 ^ part2 ^ part3;
	}

© Stack Overflow or respective owner

Related posts about c#

Related posts about hashing