sbromberger / LightGraphs.jl

An optimized graphs package for the Julia programming language
Other
670 stars 184 forks source link

[FR] add core functions #1567

Closed BeastyBlacksmith closed 3 years ago

BeastyBlacksmith commented 3 years ago

It would be nice to have a degree property that has a more performant implementation than degree(v) = length(neighbors(graph, vertex))

sbromberger commented 3 years ago

The current implementation is O(1) in time and memory. What are you suggesting could be more performant?

sbromberger commented 3 years ago

Here's a demonstration:

julia> g = star_graph(100_000_000)
{100000000, 99999999} undirected simple Int64 graph

julia> @btime degree(g, 1)
  16.834 ns (1 allocation: 16 bytes)
99999999

julia> h = Graph(1)
{1, 0} undirected simple Int64 graph

julia> @btime degree(h, 1)
  14.319 ns (0 allocations: 0 bytes)
0
BeastyBlacksmith commented 3 years ago

aha, I just missed that function from the documentation. I'll make a PR

sbromberger commented 3 years ago

degree() is in the documentation: https://juliagraphs.org/LightGraphs.jl/latest/core/#LightGraphs.degree

BeastyBlacksmith commented 3 years ago

Thats true, but I expected it to find it among the vertex properties and in hindsight it was a bit silly to stop searching when I didn't find it there, but others might do the same

sbromberger commented 3 years ago

I think a better PR would be to ensure "Core Functions" is a sidebar item. I'm not generally inclined to have multiple references to functions in the documentation. That gets confusing and pollutes search results.

BeastyBlacksmith commented 3 years ago

Also a good idea. Changed that