-
Notifications
You must be signed in to change notification settings - Fork 68
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
Add more advanced ways of iterating nodes and links #13
Comments
I think it's a good idea. I didn't want to do it some time ago because I was worried about memory pressure that new objects would introduce on garbage collector. Today this seem to be a case of premature optimization, so I think it is worth reconsidering. By the way, even today you can suspend execution somewhere in the middle of the cycle if you return truthy object from the visitor. |
Well, I meant an impossibility of getting the next element whenever you want, not only when the previous loop finishes :) About the possibility of breaking the internal graph structure by user: it is also real for now. As user can freely interact with I found out my question to be premature. A very important thing I missed out is that such iterator as I suggest to expose to users cannot be efficiently created for objects, as objects do not expose any ways to get their keys except It's worth investigating how another graph libraries store graphs... For ECMAScript 6+ a For older environments it is, um, a problem... Of course the best way is just to leave everything as it is, but new features often require paying by some part of performance. A new hashtable implementation can be written.
These operations also should be atomic. With such data structure it's possible to create an iterator object that simply stores an array index inside. For consistency, when user calls P.S. There is a TODO |
Hi @anvaka!
Thank you for your huge work on the
ngraph
packages family. It is cool, except there is a vital thing not implemented yet - so is a convenient and universal way to iterate through nodes/links. The existing way of iteration via callback provided to internal foreach cycle is not enough, as:The
ngraph.graph
package controls the iteration and one cannot suspend execution somewhere in the middle of the cycle.It requires an intermediate array to write graph elements to if one wants to pass them anywhere else.
#1 is a pretty similar issue, @ZigGreen probably wanted the same thing - a convenient way to iterate through elements.
I suppose adding methods that will return ECMAScript 6 iterators a cool way to deal with this problem. An iterator is a simple object so it is completely compatible with vanilla JavaScript.
Everyone who is happy to afford using ECMAScript 6 features can then use
for..of
and*yield
syntax with the returned iterator. For everybody else we could create a simplengraph.iteration
package with common functional methods, such asmap
/filter
/forEach
, written on vanilla JS.Another benefit of this approach is that the internal
nodes
object won't be able to be changed by user.The only possible problem may be a concurrency issue... or not?
What do you think about it?
The text was updated successfully, but these errors were encountered: