Ticket #10905: trac10905-improve_via_out_neighbors_unsafe.patch

File trac10905-improve_via_out_neighbors_unsafe.patch, 1.5 KB (added by ylchapuy, 10 years ago)
  • sage/graphs/base/c_graph.pyx

    # HG changeset patch
    # User YLC <y@l.c>
    # Date 1299794632 -3600
    # Node ID ca0f05d1accdccade47df21d9672031122aeb1b1
    # Parent  407ddcc93ce72baa181c453fd219d6992158f23c
    #10905 improve via out_neighbors_unsafe
    
    diff -r 407ddcc93ce7 -r ca0f05d1accd sage/graphs/base/c_graph.pyx
    a b  
    27482748    cdef dict ggbvi = gg._backend.vertex_ints
    27492749    cdef dict ggbvl = gg._backend.vertex_labels
    27502750
    2751     cdef list outneighbors
     2751    cdef int *outneighbors
     2752    cdef int o_n_size
     2753    cdef int i
    27522754    for source in vertices:
    27532755        bitset_set_first_n(seen, 0)
    27542756        bitset_add(seen, source)
     
    27612763
    27622764        while waiting_beginning <= waiting_end:
    27632765            v = waiting_list[waiting_beginning]
    2764             outneighbors = cg.out_neighbors(v)
    2765             for u in outneighbors:
     2766            o_n_size = cg.out_degrees[v]
     2767            outneighbors = <int *>sage_malloc(o_n_size * sizeof(int))
     2768            o_n_size = cg.out_neighbors_unsafe(v, outneighbors, o_n_size)
     2769            for 0 <= i < o_n_size:
     2770                u = outneighbors[i]
    27662771                if not bitset_in(seen, u):
    27672772                    v_distances[u] = v_distances[v]+1
    27682773                    v_prec[u] = v
    27692774                    bitset_add(seen, u)
    27702775                    waiting_end += 1
    27712776                    waiting_list[waiting_end] = u
    2772 
     2777            sage_free(outneighbors)
    27732778            waiting_beginning += 1
    27742779
    27752780        tmp_distances = dict()