Coder Social home page Coder Social logo

Comments (9)

phishman3579 avatar phishman3579 commented on May 17, 2024

I'll look into the hash/equals mismatch. It's likely because I assume the path to be linear where a Set has no such concept. I'll clean it up in the next couple of days.

Also, on the topic of Graph: are you suggesting that I move into into a 'graph' sub-package of data_structures or move it out of data structures into a package at the same level as data_structures?

from java-algorithms-implementation.

jolkdarr avatar jolkdarr commented on May 17, 2024

Ok, I wait for the fix... :)

I think I have understood now:
The class Graph is defined in data_structures with all other data types.
The graph package only contains algorithms related to graphs.

from java-algorithms-implementation.

phishman3579 avatar phishman3579 commented on May 17, 2024

OK, I have fixed the path related equals/hash method. Let me know if you believe it is fixed also. Thanks for helping make this a better repository.

Yes, the graph classes layout isn't the most straightforward.

from java-algorithms-implementation.

jolkdarr avatar jolkdarr commented on May 17, 2024

Problem still present. Given two graphs g1 and g2,
!g1.equals(g2) should imply g1.hashCode() != g2.hashCode()
g1.hashCode() == g2.hashCode() should imply g1.equals(g2)

from java-algorithms-implementation.

phishman3579 avatar phishman3579 commented on May 17, 2024

I don't think the first statement is correct, from the Java docs.
"It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results."

http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html

from java-algorithms-implementation.

jolkdarr avatar jolkdarr commented on May 17, 2024

If you don't provide hashCode/equals "consistently", you should document it in javadocs because your classes can't be used in hash maps or hash sets etc etc...

Because I actually need consistency, I have switched to the JGraphT library instead.
Location: https://github.com/jgrapht/jgrapht/tree/master/jgrapht-core/src/main/java/org/jgrapht

Thanks for your time.

from java-algorithms-implementation.

phishman3579 avatar phishman3579 commented on May 17, 2024

My point is, the class is consistent with the equals/hashCode javadoc
contract. All the hashing data structures use hashCode as their first
filter, if two objects have the same hash code then it uses equals to
determine the correct object.

Since the objects equals method ultimately determine the equality the path
objects will work as expected in all the java collection/maps.
On Jan 6, 2016 5:07 PM, "jolkdarr" [email protected] wrote:

If you don't provide hashCode/equals "consistently", you should document
it in javadocs because your classes can't be used in hash maps or hash sets
etc etc...

Because I actually need consistency, I have switched to the JGraphT
library instead.
Location:
https://github.com/jgrapht/jgrapht/tree/master/jgrapht-core/src/main/java/org/jgrapht

Thanks for your time.


Reply to this email directly or view it on GitHub
#16 (comment)
.

from java-algorithms-implementation.

jolkdarr avatar jolkdarr commented on May 17, 2024

You are right. Your classes shall not avoid collisions.
Because I use hashcodes as keys for performance reasons, I can't use that library.
With JGraphT all works as I expect.

Thank you.

from java-algorithms-implementation.

phishman3579 avatar phishman3579 commented on May 17, 2024

OK @jolkdarr thanks for the feedback. I can change the hashCode() fairly easily if that will help.

from java-algorithms-implementation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.