igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] igraph_degree(), seriously?


From: Gábor Csárdi
Subject: Re: [igraph] igraph_degree(), seriously?
Date: Thu, 21 Apr 2011 09:03:11 -0400

Hi,

there is a very thin layer on top of the igraph_t data structure,
around ten functions altogether. All the other functions access
igraph_t through this layer. This architecture makes it possible to
replace the internal graph representation without much pain, in fact
this already happened once. It is key that this layer is thin, and
orthogonal. This is why there is no igraph_degree_1() function in the
thin layer.

Having an igraph_degree_1() function one layer above (which Tamas is
about to write), makes it slower, two function calls instead of one.
This is not a serious issue, compiler optimization can be used to
inline the igraph_degree_1() function.

Finally, it is extremely simple for the user to add such a function:

int igraph_degree_1(const igraph_t *igraph, int vertex) {
  igraph_real_t v;
  igraph_vector_t vp;
  igraph_vector_view(&vp, &v, 1);
  igraph_degree(graph, &vp, igraph_vss_1(vertex), IGRAPH_ALL, IGRAPH_LOOPS);
  return v;
}

Untested, but shows the idea.

Best,
Gabor

On Wed, Apr 20, 2011 at 10:22 AM, Marco <address@hidden> wrote:
> Hi,
> I am using the igraph C library.
>
> It is not clear to me why it's so complicated (admitting I found the right
> spot in the doc) to get the degree of a node.
>
> So, here we go.
>
> I have a graph, everything is doing all right, and I need to check a
> condition based on the degree of one node.
>
> Doc tells me there's a function prototyped as:
>
> int igraph_degree(const igraph_t *graph, igraph_vector_t *res,
>                  const igraph_vs_t vids,
>                  igraph_neimode_t mode, igraph_bool_t loops);
>
> (big nods from the audience?)
>
> Ok, but I just need the degree of ONE node.
>
> *If* I understand correctly the doc this means that I have to create a
> vector, init it, then I need an igraph_vs_t to select the node (for this I
> use igraph_vss_1()) and then I need to use igraph_vector_e() to get the
> value of the degree, since a simple vector[0] wouldn't do (gcc complains out
> loud).
>
> Now, all of this to get the degree of one node?
> :)
>
> Would you please include a function that does something like:
>
> int igraph_single_degree(const igraph_t * graph, long int pos)
>
> and returns the degree of just one node?
>
> Or, maybe, I didn't understand a thing, and there's a simpler way!
>
> Thanks,
>
> marco
>
>
>
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>



-- 
Gabor Csardi <address@hidden>     MTA KFKI RMKI



reply via email to

[Prev in Thread] Current Thread [Next in Thread]