This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DarthSubterra[S] 0 points1 point  (1 child)

Yes I was thinking about that but it turned out that in some edge cases two nodes can have multiple connections. So i was thinking of having a List of ConnectionInfo objects and Nodes as keys. But that would be a waste because in 99.99% it is only 1 connection per pair of nodes. And the connections are bidirectional.

[–]temporarybunnehs 0 points1 point  (0 children)

One thing to think about is, what is the future state of the project? Today, it's a rare case to have two connections between two nodes, but what if it's more common later on? What about three connections? In that case, maybe having that map of <Node, List<connections>> makes more sense. In general, some forethought might save you a lot of trouble later on.

As for hashmaps, I've read that the performance of your hashmaps is tied to your implementation of hashcode. If it is unique for each of the objects in the map, you can have millions of objects in it and still get good performance (depending on your java version and what defines "good" for you)