BFS why this node is equal to other nodes.
(self, others: list[Node], level: int)
| 200 | return parent |
| 201 | |
| 202 | def why_equal(self, others: list[Node], level: int) -> list[Any]: |
| 203 | """BFS why this node is equal to other nodes.""" |
| 204 | others = set(others) |
| 205 | found = 0 |
| 206 | |
| 207 | parent = {} |
| 208 | queue = [self] |
| 209 | i = 0 |
| 210 | |
| 211 | while i < len(queue): |
| 212 | current = queue[i] |
| 213 | if current in others: |
| 214 | found += 1 |
| 215 | if found == len(others): |
| 216 | break |
| 217 | |
| 218 | i += 1 |
| 219 | |
| 220 | for neighbor in current.merge_graph: |
| 221 | if ( |
| 222 | level is not None |
| 223 | and current.merge_graph[neighbor].level is not None |
| 224 | and current.merge_graph[neighbor].level >= level |
| 225 | ): |
| 226 | continue |
| 227 | if neighbor not in parent: |
| 228 | queue.append(neighbor) |
| 229 | parent[neighbor] = current |
| 230 | |
| 231 | return bfs_backtrack(self, others, parent) |
| 232 | |
| 233 | def why_equal_groups( |
| 234 | self, groups: list[list[Node]], level: int |
no test coverage detected