Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'u/gh-kliem/next_out_neighbor_for_static_sparse' of git:…
Browse files Browse the repository at this point in the history
…//trac.sagemath.org/sage into public/graphs/31117_BFS
  • Loading branch information
Jonathan Kliem committed Dec 28, 2020
2 parents c342fe6 + 65e677e commit b7e8a20
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/sage/graphs/base/static_sparse_backend.pyx
Expand Up @@ -252,6 +252,54 @@ cdef class StaticSparseCGraph(CGraph):
"""
return self.has_arc_unsafe(u, v)

cdef inline int next_out_neighbor_unsafe(self, int u, int v, int* l) except -2:
"""
Return the next out-neighbor of ``u`` after ``v``.
If ``v`` is ``-1`` return the first neighbor of ``u``.
Return ``-1`` in case there does not exist such an out-neighbor.
.. NOTE::
A caller may not alter ``l``.
It is used to keep track of the current position.
"""
cdef int degree = self.g.neighbors[u+1] - self.g.neighbors[u]
if v == -1:
l[0] = -1
for i in range(l[0] + 1, degree):
if self.g.neighbors[u][i] != v:
l[0] = i
return self.g.neighbors[u][i]
else:
return -1

cdef inline int next_in_neighbor_unsafe(self, int u, int v, int* l) except -2:
"""
Return the next in-neighbor of ``u`` after ``v``.
If ``v`` is ``-1`` return the first neighbor of ``u``.
Return ``-1`` in case there does not exist such an in-neighbor.
.. NOTE::
A caller may not alter ``l``.
It is used to keep track of the current position.
"""
if not self._directed:
return self.next_out_neighbor_unsafe(u, v, l)
cdef int degree = self.g_rev.neighbors[u+1] - self.g.neighbors[u]
if v == -1:
l[0] = -1
for i in range(l[0] + 1, degree):
if self.g_rev.neighbors[u][i] != v:
l[0] = i
return self.g_rev.neighbors[u][i]
else:
return -1

cdef int out_neighbors_unsafe(self, int u, int *neighbors, int size) except -2:
cdef int degree = self.g.neighbors[u+1] - self.g.neighbors[u]
cdef int i
Expand Down

0 comments on commit b7e8a20

Please sign in to comment.