On Monday, 15 August 2022 at 03:19:43 UTC, johntp wrote:
Your solution worked. I guess it is a little unnatural to ignore the color. I tried overriding the toHash() of Point, but I don't know enough D to get it to work. I wonder if that could be a solution.

Depends on what you're trying to do. Metadata unrelated to the value of the object i would ignore and not be part of hashing or comparisons. I've also done things for strings that held information like what original position in the array the data was (*for visually sorting testing*) and could yield me information while not interfering with the object/data in question.

Though x+y as a hash seems terrible. I'd probably do ((x+1000)**2)+y (assuming x and y are both going to be generally small ensuring the hash for location is unique. Then point(2,1) and point(1,2) have different hashes. But I'm not familiar with the exercise in question.

Reply via email to