I know that the HashSet.contains() method uses the .equals method to check equality as in it checks the pointer to see whether they’re equal.
I need it to check the actual object at the pointer for equality – in my specific case, I need to see whether a “Node” being opened (an int[] array) already exists in the HashSet. This is essential for my search algorithm so that the implementation of my Bi-directional Iterative Deepening Search isn’t as naive.
I’d still like linear search time if possible, or perhaps I should use a different class?
Thanks for your help.
Reference equality is just the default implementation of .equals(). You can put your arrays in a wrapper class that overrides equals and hashCode to check the contents. NB: In order for this to work the contents must not change after you put them in the set.