{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaGraphs/MetaGraphs.jl/issues/13","repository_url":"https://api.github.com/repos/JuliaGraphs/MetaGraphs.jl","labels_url":"https://api.github.com/repos/JuliaGraphs/MetaGraphs.jl/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/JuliaGraphs/MetaGraphs.jl/issues/13/comments","events_url":"https://api.github.com/repos/JuliaGraphs/MetaGraphs.jl/issues/13/events","html_url":"https://github.com/JuliaGraphs/MetaGraphs.jl/pull/13","id":265834804,"number":13,"title":"[WIP] Adding Index Dictionary","user":{"login":"kescobo","id":3502975,"avatar_url":"https://avatars0.githubusercontent.com/u/3502975?v=4","gravatar_id":"","url":"https://api.github.com/users/kescobo","html_url":"https://github.com/kescobo","followers_url":"https://api.github.com/users/kescobo/followers","following_url":"https://api.github.com/users/kescobo/following{/other_user}","gists_url":"https://api.github.com/users/kescobo/gists{/gist_id}","starred_url":"https://api.github.com/users/kescobo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kescobo/subscriptions","organizations_url":"https://api.github.com/users/kescobo/orgs","repos_url":"https://api.github.com/users/kescobo/repos","events_url":"https://api.github.com/users/kescobo/events{/privacy}","received_events_url":"https://api.github.com/users/kescobo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-10-16T16:35:10Z","updated_at":"2017-10-17T17:04:09Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/JuliaGraphs/MetaGraphs.jl/pulls/13","html_url":"https://github.com/JuliaGraphs/MetaGraphs.jl/pull/13","diff_url":"https://github.com/JuliaGraphs/MetaGraphs.jl/pull/13.diff","patch_url":"https://github.com/JuliaGraphs/MetaGraphs.jl/pull/13.patch"},"body":"Based on [this discussion](https://discourse.julialang.org/t/metagraph-node-indexing-w-metadata/6439) on Discourse - this PR would add a dictionary-based index to `MetaGraph` and `MetaDiGraph` types. Currently, this works:\r\n\r\n```julia\r\ng = MetaGraph(4)\r\n\r\nfor i in 1:4\r\n    set_prop!(g, i, :name, \"node$i\")\r\nend\r\nupdate_index(g)\r\n\r\ng[\"node1\"] # 1\r\n```\r\n\r\nOpen questions:\r\n\r\n- How do deal with defaults? Using `:name` as the default index as I do now might be breaking for some people.\r\n- How (if?) to enforce uniqueness in the indexing field? Related: how to keep the index current?\r\n\r\nProbably lots of other things. If this seems like it would be useful, please let me know and I'll try to build it out. \r\n\r\nCurrent code is a proof of principle, but I tested it using the same setup as in the discourse topic, and got the following benchmark:\r\n\r\n```\r\nBenchmarkTools.Trial: \r\n  memory estimate:  29.04 MiB\r\n  allocs estimate:  376480\r\n  --------------\r\n  minimum time:     35.263 ms (12.47% GC)\r\n  median time:      40.081 ms (17.56% GC)\r\n  mean time:        40.320 ms (19.28% GC)\r\n  maximum time:     50.030 ms (29.63% GC)\r\n  --------------\r\n  samples:          124\r\n  evals/sample:     1\r\n```\r\n\r\nCompared with the following for using filters:\r\n\r\n```\r\nBenchmarkTools.Trial: \r\n  memory estimate:  22.68 GiB\r\n  allocs estimate:  160517950\r\n  --------------\r\n  minimum time:     16.994 s (32.95% GC)\r\n  median time:      16.994 s (32.95% GC)\r\n  mean time:        16.994 s (32.95% GC)\r\n  maximum time:     16.994 s (32.95% GC)\r\n  --------------\r\n  samples:          1\r\n  evals/sample:     1\r\n```\r\n\r\n[See here](https://gist.github.com/kescobo/967413b5f75ca7c6c0702b0760e80e5d) for full code and results."},"comment":{"url":"https://api.github.com/repos/JuliaGraphs/MetaGraphs.jl/issues/comments/337298804","html_url":"https://github.com/JuliaGraphs/MetaGraphs.jl/pull/13#issuecomment-337298804","issue_url":"https://api.github.com/repos/JuliaGraphs/MetaGraphs.jl/issues/13","id":337298804,"user":{"login":"kescobo","id":3502975,"avatar_url":"https://avatars0.githubusercontent.com/u/3502975?v=4","gravatar_id":"","url":"https://api.github.com/users/kescobo","html_url":"https://github.com/kescobo","followers_url":"https://api.github.com/users/kescobo/followers","following_url":"https://api.github.com/users/kescobo/following{/other_user}","gists_url":"https://api.github.com/users/kescobo/gists{/gist_id}","starred_url":"https://api.github.com/users/kescobo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kescobo/subscriptions","organizations_url":"https://api.github.com/users/kescobo/orgs","repos_url":"https://api.github.com/users/kescobo/repos","events_url":"https://api.github.com/users/kescobo/events{/privacy}","received_events_url":"https://api.github.com/users/kescobo/received_events","type":"User","site_admin":false},"created_at":"2017-10-17T17:04:09Z","updated_at":"2017-10-17T17:04:09Z","author_association":"NONE","body":"Some new checking:\r\n\r\n```julia\r\nusing MetaGraphs\r\n\r\ng = MetaGraph(4)\r\n\r\nfor i in 1:4\r\n    set_prop!(g, i, :name, \"node$i\")\r\nend\r\n\r\nset_indexing_prop!(g, :name)\r\ng[\"node1\", :name]\r\n\r\nset_prop!(g, 3, :name, \"name3\") # Error: ':name' is an indexing property, use `set_indexing_prop!()` instead\r\n\r\nset_indexing_prop!(g, 3, :name, \"name3\") # √\r\nset_indexing_prop!(g, 3, :name, \"node3\") # √\r\nset_indexing_prop!(g, 3, :name, \"node3\") # √\r\nset_indexing_prop!(g, 3, :name, \"node1\") # Error: ':name' index already contains node1\r\n```"}}
{"actor":{"display_login":"kescobo"}}