c# - Generate a commutative hash based on three sets of numbers? -
I need to generate a cumulative hash based on three sets of "score" strontact.
Each score is a "starting", a "end" and a "number".
Both start and end are usually large numbers (8-9 digits), but numbers 1 to 4 are the same.
I need to commute them so that order order does not matter. I am using XOR at this time but it is giving bad results.
Since I'm working with large datasets, I prefer a display-friendly solution. Any suggestions? Thanks =]
Public Fixed 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 Part 3 = (c1.copyNumber + c2.copyNumber + c3.copyNumber) * 23735160; Back part1 ^ part2 ^ part3;
- See the method of Knuth and 64 to 32-bit mix functions.
Paul HSIH has also described his "super fasthash" function, which receives mixed reactions.
Edit Because you want your custom hash to be comuted (I think between the CNRRegen parameter) you might possibly write something like this:
Public Ink hash 6432 shaft (long key) {key = (~ key) + (key <18); // key = (key 31); Key = key * 21; // key = (key + (key gt;> 11); Key = key + (key > 22); Return key; } 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); Int hash1 = hash6432shift (((tall) part1 & lt; 0x20) | part2); Return hash-6432 ship ((Long Hash 1 & lt; 0x20) | Part 3); }
However, in the end the task of finding a hash function, which is both fast and provides good collision resistance, depending on the processing you have.
Let me give you an example:
Suppose that you have the value, the 10 digit number is large, and they are a Unix timestamp (since 01/01/1970 Represent time in seconds). In this case, there are many timestamps during the limited time period, which is more than a month to say that it is a matter of destroying the part which can not be changed, and using only a few parts of the timestamp, Changes. It is similar to saying that you are destroying low entropy parts.
v1 = 1241536920 // 5/5/2009 3:22:00 pm v2 = 1241529720 // 5 / 5/2009 1:22:00 pm v3 = 1241270520/5/2 / 2009 1:22:00 pm v4 = 1242825720 // 5/20/2009 1:22:00 PM
It is very clear that we ended safely 3-4 digits first And only use the remaining points as a hash. Also, if these values are usually done in a few minutes of each other, then you can also leave the last 2-3 digits.
In this way, you have only been left with 4 points that you haveh with a very good conflict resistance for example of our case.
My issue is that hash functions can be greatly customized if you know the statistical distribution of values that are trying to get your hash.
Comments
Post a Comment