I have a hashmap that has these keys: '2 + 4 + 5', '653 + 65 + 1324 + 75'. (integer values indicated by +)
Which can be a good hashcode and equals method, so keys like "2 + 4 + 5", "5 + 4 + 2", "4 + 5 + 2" ... (all permutation 2,4, 5) should return the same hashcode value, and equals should return true.
I plan to take the integer values in the key, sort them, put them in ascending order in the string and call this hashcode and equals method. Suppose if I have "5 + 2 + 4", then I would change it to "245" and call the hashcode and equals method. But it will be an expensive operation, because every time I have to do sorting. And all methods in hashmap like put, get ... will again be expensive
Are there other ways to do this in logarithmic or linear time ...
source
share