-
Notifications
You must be signed in to change notification settings - Fork 82
refactor: use get_nerghbors in storage instead of building adj_list #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -188,6 +188,18 @@ def delete_node(self, node_id: str): | |||||||
| else: | ||||||||
| print(f"Node {node_id} not found in the graph for deletion.") | ||||||||
|
|
||||||||
| def get_neighbors(self, node_id: str) -> List[str]: | ||||||||
| """ | ||||||||
| Get the neighbors of a node based on the specified node_id. | ||||||||
|
|
||||||||
| :param node_id: The node_id to get neighbors for | ||||||||
| :return: List of neighbor node IDs | ||||||||
| """ | ||||||||
| if self._graph.has_node(node_id): | ||||||||
| return list(self._graph.neighbors(node_id)) | ||||||||
| print(f"Node {node_id} not found in the graph.") | ||||||||
| return [] | ||||||||
|
Comment on lines
+200
to
+201
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Printing to standard output in a library function is generally discouraged. It can clutter the output of the application using the library and may not be desirable in all contexts (e.g., when running in production or as part of a larger pipeline). It's better to either use a proper logging framework or simply return an empty list, letting the caller decide how to handle the 'node not found' case. The empty list sufficiently signals that there are no neighbors, which is true if the node doesn't exist.
Suggested change
|
||||||||
|
|
||||||||
| def clear(self): | ||||||||
| """ | ||||||||
| Clear the graph by removing all nodes and edges. | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.