Skip to content
Closed
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 @@ -90,18 +90,21 @@ def sort_chat_inputs_first(self, vertices_layers: list[list[str]]) -> list[list[
def find_node_with_highest_degree(
nodes: list[str], connections: dict[str, list[str]]
) -> str:
# Precompute incoming degree for all nodes
incoming_degree = dict.fromkeys(nodes, 0)
for targets in connections.values():
for target in targets:
if target in incoming_degree:
incoming_degree[target] += 1

max_degree = -1
max_degree_node = None

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 connections/degree
out_degree = len(connections.get(node, []))
# Total degree is outgoing + incoming
degree = out_degree + incoming_degree[node]

if degree > max_degree:
max_degree = degree
Expand Down