[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Using dynamics vectors to storage my graph's edges
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] Using dynamics vectors to storage my graph's edges |
Date: |
Thu, 16 Jul 2009 11:21:26 +0200 |
Hi Christian,
your code does not compile with gcc 4.3.3 (or g++ 4.3.3), which
compiler do you actually use? On which platform? On Linux I get
address@hidden:/tmp$ gcc test.c -I
/home/csardi/works/igraph/0.5-main/include/ -ligraph -L
/home/csardi/works/igraph/0.5-main/src/.libs/ -o test
test.c: In function ‘main’:
test.c:31: warning: incompatible implicit declaration of built-in
function ‘calloc’
test.c:79: error: ‘for’ loop initial declaration used outside C99 mode
test.c:91: error: ‘EXIT_SUCCESS’ undeclared (first use in this function)
test.c:91: error: (Each undeclared identifier is reported only once
test.c:91: error: for each function it appears in.)
address@hidden:/tmp$ g++ test.c -I
/home/csardi/works/igraph/0.5-main/include/ -ligraph -L
/home/csardi/works/igraph/0.5-main/src/.libs/ -o test
test.c: In function ‘int main(int, char**)’:
test.c:31: error: ‘calloc’ was not declared in this scope
test.c:91: error: ‘EXIT_SUCCESS’ was not declared in this scope
After defining EXIT_SUCCESS, including stdlib.h and getting rid of the
c++ style loop variable, I could compile it. See more below.
On Wed, Jul 15, 2009 at 11:59 PM, Christian
Gonzalez<address@hidden> wrote:
> Hello everybody,
>
> I'm trying to use "dynamics vector" to store my graph's edges, because I
> have a lot of edges. But the "igraph library" doesn't handle it. there is
> some way to store my edges in the heap memory?
>
>
> this is my code.
[...]
> if ( (ptr_edges = calloc(9 * 2, sizeof(igraph_real_t))) == NULL)
This should be != NULL instead of == NULL, I guess. Btw, why don't you
quit or report an error if calloc returns with an error?
[...]
> *(ptr_edges+0) = 100; *(ptr_edges+1) = 200;
> *(ptr_edges+2) = 100; *(ptr_edges+3) = 300;
> *(ptr_edges+4) = 200; *(ptr_edges+5) = 400;
> *(ptr_edges+6) = 300; *(ptr_edges+7) = 600;
> *(ptr_edges+8) = 300; *(ptr_edges+9) = 500;
Why do you fill the vector this way? You don't need to define it as a
view, you can add elements to the vector directly, e.g.
VECTOR(edges)[0]=100; VECTOR(edges)[1]=200;
etc.
> igraph_vector_view(&edges, ptr_edges, sizeof(9 * 2,
> sizeof(igraph_real_t))/sizeof(igraph_real_t));
This does not make sense, one 'sizeof' is not needed, just think about
it. This should be
igraph_vector_view(&edges, ptr_edges, 9*2);
[...]
> igraph_vector_fill(&weights, w);
If all the weights are the same, then you can just pass a null pointer
instead of the weights vector.
[...]
> igraph_destroy(&graph);
> igraph_vector_destroy(&result);
> igraph_vector_destroy(&weights);
> igraph_vector_ptr_destroy(&result_vector);
You forgot to free ptr_edges.
> return EXIT_SUCCESS;
> }
>
> this is my output:
>
> address@hidden igraphtest]$ build/myigraph
> vertices: 0, lados: 0
> Error at iterators.c:709 :Cannot create iterator, invalid vertex id, Invalid
> vertex id
> Abortado
[...]
Best,
Gabor
--
Gabor Csardi <address@hidden> UNIL DGM