Skip to content
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

normalize edges to use Edge[K] rather than both Edge[K] and Edge[T], … #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonbrandenburg
Copy link
Contributor

…also addressed storing duplicate edge properties within the memory store which addresses issue #110.

Currently the codebase seems to be a bit fragmented, in that there are many instances where edges are defined using Edge[K] and others using Edge[T]. While this isn't necessarily a big deal when K and T are the same type, it can become an issue when they're not. I opted to go with Edge[K] instead of Edge[T], because I figured it would be easier to guarantee the references / pointers were correct using the keys/hashes than with the vertices directly when passing them from the store to the graph. That said, if you think Edge[T] is the better choice I'd be interested to hear your ideas on how to handle that.

It should be noted, if it isn't already obvious that this will likely be a breaking change for some users of the library.

…also addressed storing duplicate edge properties within the memory store.
@dominikbraun dominikbraun self-requested a review July 17, 2023 05:42
@@ -131,25 +131,15 @@ func (d *directed[K, T]) AddEdgesFrom(g Graph[K, T]) error {
return nil
}

func (d *directed[K, T]) Edge(sourceHash, targetHash K) (Edge[T], error) {
func (d *directed[K, T]) Edge(sourceHash, targetHash K) (Edge[K], error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graph.Edge returning a T is by design! The idea is that you obtain a vertex that you can directly operate on. For example, when storing instances of type City:

route, _ := g.Edge("sunnyvale", "mountain-view")

fmt.Printf("Weather at %s: %s\n", route.Target.Name, route.Target.LoadWeatherInfo())

Requiring the user to look up the cities by their IDs first would kind of defeat the purpose of storing a T any in the first place, because then pure IDs would work as well. The memory overhead of returning these instances should be neglectable.

@@ -232,6 +232,21 @@ type EdgeProperties struct {
Data any
}

func (p *EdgeProperties) Clone() EdgeProperties {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants