Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphs: make init_short_digraph always sort neighbors but without the extra log complexity (2nd try) #38664

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/sage/graphs/asteroidal_triples.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ def is_asteroidal_triple_free(G, certificate=False):
# module sage.graphs.base.static_sparse_graph
cdef list int_to_vertex = list(G)
cdef short_digraph sd
init_short_digraph(sd, G, edge_labelled=False, vertex_list=int_to_vertex,
sort_neighbors=False)
init_short_digraph(sd, G, edge_labelled=False, vertex_list=int_to_vertex)

cdef bitset_t seen
bitset_init(seen, n)
Expand Down
11 changes: 6 additions & 5 deletions src/sage/graphs/base/static_sparse_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ cdef class StaticSparseCGraph(CGraph):

cdef class StaticSparseBackend(CGraphBackend):

def __init__(self, G, loops=False, multiedges=False):
def __init__(self, G, loops=False, multiedges=False, sort=True):
"""
A graph :mod:`backend <sage.graphs.base.graph_backends>` for static
sparse graphs.
Expand Down Expand Up @@ -511,10 +511,11 @@ cdef class StaticSparseBackend(CGraphBackend):
True
"""
vertices = list(G)
try:
vertices.sort()
except TypeError:
pass
if sort:
try:
vertices.sort()
except TypeError:
pass
cdef StaticSparseCGraph cg = <StaticSparseCGraph> StaticSparseCGraph(G, vertices)
self._cg = cg

Expand Down
10 changes: 1 addition & 9 deletions src/sage/graphs/base/static_sparse_graph.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,19 @@ ctypedef unsigned int uint

cdef extern from "stdlib.h":
ctypedef void const_void "const void"
void qsort(void *base, int nmemb, int size,
int(*compar)(const_void *, const_void *)) nogil

void *bsearch(const_void *key, const_void *base, size_t nmemb,
size_t size, int(*compar)(const_void *, const_void *)) nogil

cdef extern from "search.h":
void *lfind(const_void *key, const_void *base, size_t *nmemb,
size_t size, int(*compar)(const_void *, const_void *)) nogil

ctypedef struct short_digraph_s:
uint32_t * edges
uint32_t ** neighbors
PyObject * edge_labels
int m
int n
bint sorted_neighbors

ctypedef short_digraph_s short_digraph[1]

cdef int init_short_digraph(short_digraph g, G, edge_labelled=?, vertex_list=?, sort_neighbors=?) except -1
cdef int init_short_digraph(short_digraph g, G, edge_labelled=?, vertex_list=?) except -1
cdef void free_short_digraph(short_digraph g) noexcept
cdef int init_reverse(short_digraph dst, short_digraph src) except -1
cdef int out_degree(short_digraph g, int u) noexcept
Expand Down
Loading
Loading