Using IEqualityComparer GetHashCode with a tolerance

后端 未结 2 729
滥情空心
滥情空心 2020-12-11 10:01

I am trying to implement an IEqualityComparer that has a tolerance on a date comparison. I have also looked into this question. The problem is that I can\'t use

2条回答
  •  不思量自难忘°
    2020-12-11 10:33

    I can't see any way to generate a logical hash code for your given criteria.
    The hash code is used to determine if 2 dates should stick together. If they should group together, than they must return the same hash code.

    If your "float" is 5 days, that means that 1/1/2000 must generate the same hash code as 1/4/2000, and 1/4/2000 must generate the same hashcode as 1/8/2000 (since they are both within 5 days of each other). That implies that 1/1/2000 has the same code as 1/8/2000 (since if a=b and b=c, a=c).

    1/1/2000 and 1/8/2000 are outside the 5 day "float".

提交回复
热议问题