petgraph-graphml
petgraph-graphml copied to clipboard
Put key tags before nodes/edges
I haven't read the spec but it seems that some applications assume that keys are before the rest of the data, like graph-tool and Gephi. Anyway, it's easier as a human to read the file if the keys are first.
So I just ran into this problem, and I'm now trying to think about how you could handle the fact that you can't know the keys until you iterate over the nodes. However, you also want the keys to be at the beginning of the file.
I guess the best way to do it would be to do a quick iteration over all the keys and store all of those events into an iterator or something. Send the key events through, then send the graph events through. But I also don't rust as much as I'd like so I'm not sure how that looks in this ecosystem.
I guess for some contexts, if the graph you are trying to write is extremely large, that would end up storing a lot of events in memory. So, I guess the other thought is to write the other events out to a temporary file on disk if the graph is large enough and then basically copy the contents of that temporary file to the final file. Whatever, probably premature optimization.
Just had an epiphany. What if you enforced that for those who want the keys before they have to register the keys beforehand? Then it's an option, and if you come across a key you haven't seen before, you raise a hullabaloo. But otherwise, you keep on putting the keys at the end if they don't request keys specifically being pre-registered.
Added PR #57 to solve this issue.
I released v3.1.0 which contains #57 by @Shadetheartist thus fixing this problem. Thanks for the PR.