Comments (9)
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.
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.
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.
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.
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.
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.
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/jgraphtThanks for your time.
—
Reply to this email directly or view it on GitHub
#16 (comment)
.
from java-algorithms-implementation.
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.
OK @jolkdarr thanks for the feedback. I can change the hashCode() fairly easily if that will help.
from java-algorithms-implementation.
Related Issues (20)
- Bug in Queue
- BinaryHeapArray::clear function is broken HOT 3
- There is a 404.
- The Google Group is Invisible
- tip about method BinarySearchTree.replaceNodeWithNode()
- Dsa HOT 1
- Broken KdNode equals and compareTo causes the KdTree not to return all valid results
- Interval Tree: Does it support zero length intervals, and does it support querying all overlapping intervals?
- Bug: MultiplyUsingLoopWithStringInput cant handle zero input
- Refactor: centralize type handling for simple operations such as add and subtract, and add branch coverage for this HOT 1
- The functions Matrix.add and Matrix.subtract have unneeded for loops HOT 1
- [Accidental duplicate issue, please delete me]
- Logical error with American flag sorting
- Report on possible code improvements applying design patterns
- Java data structures
- Possible bug in Prim's algorithm HOT 4
- Bug in finding the "Longest Increasing Subsequence" HOT 2
- Possible bug in ArryaQueue HOT 1
- Possible bug in Graph definition HOT 1
- Radial search for KdTree HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-algorithms-implementation.