Refactored Edge, Graph and new Vertex class. Updated public API#3
Merged
nathan-gilbert merged 8 commits intomainfrom Mar 26, 2026
Merged
Refactored Edge, Graph and new Vertex class. Updated public API#3nathan-gilbert merged 8 commits intomainfrom
nathan-gilbert merged 8 commits intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New Edge, Vertex and Graph classes
Description
Replaces the internal
defaultdict[str, list[str]]adjacency storage with a dual-index structure built on first-classVertexandEdgeobjects:_vertices: dict[str, Vertex]— O(1) lookup by name_adj: dict[str, dict[str, Edge]]— O(1) edge existence checks via_adj[u][v]Vertex is a new frozen dataclass (
__slots__) withname, optionallabel, and an immutableattrsmapping. Identity is based onnameonly. Supports ordering forsorted().Edge is a frozen dataclass (
__slots__) withsource/target, optionalweight,label, and immutableattrs. Identity is based on the structural triple(source, target, directed).Graph now stores
VertexandEdgeobjects directly instead of reconstructing them on every call. The public API has been cleaned up: metadata exposed as properties (label,directed,weighted,order,size), getter prefixes dropped (neighbors(),adjacency_matrix(),vertex(),edge()), and backward-compat methods removed (get_graph(),set_directed(),get_random_vertex()). Construction paramsinput_file/input_graph/input_matrixare now keyword-only, anddirected/weightedcan be set as constructor kwargs.Other Changes
Algorithm modules (
properties,paths,search,directed,sort), export modules (json_utils,graphviz_utils),numpy_compat,demo.py,conftest.py, and all tests updated to use the new API. No algorithm logic was changed.Type of Change
Checklist
black,isort,ruff check)uv run ty check)uv run pytest)from __future__ import annotationsincluded in new modulespre-commit run --all-files)