Skip to content

Commit

Permalink
Fix bug in Dijkstra's algorithm when there are unreachable vertices.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkskeller committed Sep 26, 2024
1 parent de77d89 commit 20dfe63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Compiler/dijkstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,12 @@ def dijkstra(source, edges, e_index, oram_type, n_loops=None, int_type=None):
last_edge = MemValue(basic_type(1))
i_edge = MemValue(int_type(0))
u = MemValue(basic_type(0))
running = MemValue(basic_type(1))
@for_range(n_loops or edges.size)
def f(i):
print_ln('loop %s', i)
time()
running.write(last_edge.bit_not().bit_or(Q.size > 0).bit_and(running))
u.write(if_else(last_edge, Q.pop(last_edge), u))
#visited.access(u, True, last_edge)
i_edge.write(int_type(if_else(last_edge, e_index[u], i_edge)))
Expand All @@ -261,6 +263,7 @@ def f(i):
dv, not_visited = dist.read(v)
# relying on default dv negative here
is_shorter = (alt < int_type(dv[0])) + not_visited
is_shorter *= running
dist.access(v, (basic_type(alt), u), is_shorter)
#previous.access(v, u, is_shorter)
Q.update(v, basic_type(alt), is_shorter)
Expand Down
3 changes: 3 additions & 0 deletions Compiler/path_oblivious_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ def __init__(
self.type_hiding_security = type_hiding_security
self.capacity = capacity
self.entry_size = entry_size
self.size = MemValue(sint(0))

# Print debug messages
dprint(f"[POH] __init__: Initializing a queue...")
Expand Down Expand Up @@ -1024,13 +1025,15 @@ def _insert(self, value: _secret, priority: _secret, fake: _secret) -> None:
dprint_ln("\n[POH] insert")
indent()
self.tree.insert(value, priority, fake)
self.size.iadd(fake.bit_not())
outdent()

def _extract_min(self, fake: _secret) -> _secret:
if DEBUG:
dprint_ln("\n[POH] extract_min")
indent()
value = self.tree.extract_min(fake)
self.size.iadd(-fake.bit_not())
outdent()
if TRACE:
dprint_ln("[POH] extract_min: extracted value %s", value.reveal())
Expand Down

0 comments on commit 20dfe63

Please sign in to comment.