Skip to content
Open
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
19 changes: 11 additions & 8 deletions src/dsa/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ def find_node_with_highest_degree(
max_degree = -1
max_degree_node = None

# Precompute in-degree for each node
in_degree = {}
for targets in connections.values():
for tgt in targets:
in_degree[tgt] = in_degree.get(tgt, 0) + 1

for node in nodes:
degree = 0
# Count outgoing connections
degree += len(connections.get(node, []))

# Count incoming connections
for src, targets in connections.items():
if node in targets:
degree += 1
# Outgoing degree (connections from this node)
out_deg = len(connections.get(node, []))
# Incoming degree (connections to this node)
in_deg = in_degree.get(node, 0)
degree = out_deg + in_deg

if degree > max_degree:
max_degree = degree
Expand Down