{"action":"created","issue":{"url":"https://api.github.com/repos/thcyron/graphs/issues/1","labels_url":"https://api.github.com/repos/thcyron/graphs/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/thcyron/graphs/issues/1/comments","events_url":"https://api.github.com/repos/thcyron/graphs/issues/1/events","html_url":"https://github.com/thcyron/graphs/issues/1","id":60308954,"number":1,"title":"Implementing topological sorting is not possible","user":{"login":"purpleidea","id":135091,"avatar_url":"https://avatars.githubusercontent.com/u/135091?v=3","gravatar_id":"","url":"https://api.github.com/users/purpleidea","html_url":"https://github.com/purpleidea","followers_url":"https://api.github.com/users/purpleidea/followers","following_url":"https://api.github.com/users/purpleidea/following{/other_user}","gists_url":"https://api.github.com/users/purpleidea/gists{/gist_id}","starred_url":"https://api.github.com/users/purpleidea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/purpleidea/subscriptions","organizations_url":"https://api.github.com/users/purpleidea/orgs","repos_url":"https://api.github.com/users/purpleidea/repos","events_url":"https://api.github.com/users/purpleidea/events{/privacy}","received_events_url":"https://api.github.com/users/purpleidea/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-09T07:49:07Z","updated_at":"2015-03-12T11:58:09Z","closed_at":null,"body":"I'm quite new to golang, pointers and topological sorting, so I could be quite wrong in my analysis, so please excuse any incorrectness.\r\n\r\nI am working on some graph algorithms, and I decided to use your code as a base. In particular, I'm interested in implementing topological sorting which happens to be missing from this git repo!\r\n\r\nI tried to implement the 1962 algorithm described here: https://en.wikipedia.org/wiki/Topological_sorting\r\n\r\nFor this algorithm, it seems you need to be able to \"mark\" vertexes. Since your Vertex doesn't have additional storage fields, I tried using my own type:\r\n\r\n```\r\ntype Node struct {\r\n\tName    string\r\n\tComment string\r\n\tMarking string\r\n}\r\n```\r\n\r\nI was able to make this work, until I got to actually setting the markings. I think the reason is that throughout your code, your pass around copies of the Vertex value, as opposed to references (pointers) of it. As a result, every time I set the struct value, it is not seen, since I've only made my changes on a copy.\r\n\r\nMy knowledge of pointers is quite weak, so if I've misunderstood this, please let me know!\r\n\r\nSolutions:\r\n1) Fix this graph library so that Vertex's are passed around by pointer (reference) so that this isn't an issue.\r\n2) Maintain a separate map of unique Vertex identifier to the Node struct I want, and always do lookups/setters on this mapping. I don't think this is a very elegant.\r\n3) I've greatly misunderstood this go code, pointers, and everything else.\r\n\r\nAdditional goals:\r\nI'd like to store additional data associated with each Vertex. If I'm able to do this with this library, that's great, but at the moment it seems to be difficult.\r\n\r\nIf there is a more appropriate library that I should be using for graph operations in golang, please let me know!\r\n\r\nThanks for reading, and I'd appreciate your comments.\r\nCheers,\r\nJames\r\n"},"comment":{"url":"https://api.github.com/repos/thcyron/graphs/issues/comments/78466794","html_url":"https://github.com/thcyron/graphs/issues/1#issuecomment-78466794","issue_url":"https://api.github.com/repos/thcyron/graphs/issues/1","id":78466794,"user":{"login":"thcyron","id":13827,"avatar_url":"https://avatars.githubusercontent.com/u/13827?v=3","gravatar_id":"","url":"https://api.github.com/users/thcyron","html_url":"https://github.com/thcyron","followers_url":"https://api.github.com/users/thcyron/followers","following_url":"https://api.github.com/users/thcyron/following{/other_user}","gists_url":"https://api.github.com/users/thcyron/gists{/gist_id}","starred_url":"https://api.github.com/users/thcyron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thcyron/subscriptions","organizations_url":"https://api.github.com/users/thcyron/orgs","repos_url":"https://api.github.com/users/thcyron/repos","events_url":"https://api.github.com/users/thcyron/events{/privacy}","received_events_url":"https://api.github.com/users/thcyron/received_events","type":"User","site_admin":false},"created_at":"2015-03-12T11:58:09Z","updated_at":"2015-03-12T11:58:09Z","body":"> I was able to make this work, until I got to actually setting the markings. I think the reason is that throughout your code, your pass around copies of the Vertex value, as opposed to references (pointers) of it. As a result, every time I set the struct value, it is not seen, since I've only made my changes on a copy.\r\n\r\n`Vertex` is an `interface{}`, so it also takes pointers. Just use pointers to your data in `AddEdge` instead of values. I’m not sure if implementing topological sorting with the current code is easy, maybe there’s a reason why I skipped it when I was writing this library, I don’t remember. If you can’t get it working, I can give it a try if you like."}}