Whereas MutableBkTree's add methods are implemented iteratively to handle trees of any depth, the equals, hashCode, and toString methods are currently implemented using recursively, which means they might fail on very deep trees.
A recursive implementation is straightforward, as it relies on the equals method of the MutableNode.childrenByDistance Map. An iterative implementation would need to an iterative method to determine the equality of that Map.
Whereas
MutableBkTree'saddmethods are implemented iteratively to handle trees of any depth, theequals,hashCode, andtoStringmethods are currently implemented using recursively, which means they might fail on very deep trees.A recursive implementation is straightforward, as it relies on the
equalsmethod of theMutableNode.childrenByDistanceMap. An iterative implementation would need to an iterative method to determine the equality of thatMap.