-
-
Notifications
You must be signed in to change notification settings - Fork 105
normalize edges to use Edge[K] rather than both Edge[K] and Edge[T], … #147
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
Open
jonbrandenburg
wants to merge
1
commit into
dominikbraun:main
Choose a base branch
from
jonbrandenburg:normalize-edge-usage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,7 @@ type Graph[K comparable, T any] interface { | |
| // Edge returns the edge joining two given vertices or ErrEdgeNotFound if | ||
| // the edge doesn't exist. In an undirected graph, an edge with swapped | ||
| // source and target vertices does match. | ||
| Edge(sourceHash, targetHash K) (Edge[T], error) | ||
| Edge(sourceHash, targetHash K) (Edge[K], error) | ||
|
|
||
| // Edges returns a slice of all edges in the graph. These edges are of type | ||
| // Edge[K] and hence will contain the vertex hashes, not the vertex values. | ||
|
|
@@ -213,9 +213,9 @@ type Graph[K comparable, T any] interface { | |
| // Edge represents an edge that joins two vertices. Even though these edges are | ||
| // always referred to as source and target, whether the graph is directed or not | ||
| // is determined by its traits. | ||
| type Edge[T any] struct { | ||
| Source T | ||
| Target T | ||
| type Edge[K comparable] struct { | ||
| Source K | ||
| Target K | ||
| Properties EdgeProperties | ||
| } | ||
|
|
||
|
|
@@ -232,6 +232,21 @@ type EdgeProperties struct { | |
| Data any | ||
| } | ||
|
|
||
| func (p *EdgeProperties) Clone() EdgeProperties { | ||
|
Owner
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. Good catch. |
||
|
|
||
| ep := EdgeProperties{ | ||
| Attributes: make(map[string]string), | ||
| Weight: p.Weight, | ||
| Data: p.Data, | ||
| } | ||
|
|
||
| for k, v := range p.Attributes { | ||
| ep.Attributes[k] = v | ||
| } | ||
|
|
||
| return ep | ||
| } | ||
|
|
||
| // Hash is a hashing function that takes a vertex of type T and returns a hash | ||
| // value of type K. | ||
| // | ||
|
|
||
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Graph.Edgereturning aTis by design! The idea is that you obtain a vertex that you can directly operate on. For example, when storing instances of typeCity:Requiring the user to look up the cities by their IDs first would kind of defeat the purpose of storing a
T anyin the first place, because then pure IDs would work as well. The memory overhead of returning these instances should be neglectable.