Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] reducing number of links #28

Closed
xdiscovery opened this issue Mar 21, 2013 · 2 comments
Closed

[FEATURE] reducing number of links #28

xdiscovery opened this issue Mar 21, 2013 · 2 comments

Comments

@xdiscovery
Copy link

Hi, I noticed that links created as g.addLink('a','b',data) are different from ('b','a',data).

Is there a native function to compare the links within
g.getLinks(a), and if there are links present, avoid to create new ones which are equivalent?

With nodes I was able to overcome with a solution like writing all the IDs of nodes within an array, and then check with IndexOf() to see if there are already present or not.
But withj links it is different, since I should check within an array of objects, and I am stacked.

I am looking at
http://stackoverflow.com/questions/2218999/remove-duplicates-from-an-array-of-objects-in-javascript
and similar but could make a solution work yet.
Any idea?

@anvaka
Copy link
Owner

anvaka commented Mar 21, 2013

Hey there

Yes, use graph.hasLink(fromId, toId) function. Internally graph is stored as oriented, so link (a, b) and link (b, a) are different. You might wan to do something like this:

var oldLink = graph.hasLink(a, b) || graph.hasLink(b, a);
if (oldLink) {
  // the link is in the graph, do not add new link
} else {
  // there is no such link
}

@xdiscovery
Copy link
Author

Hey there, I moved on and yes, it solved, thank you!

@anvaka anvaka closed this as completed Jan 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants