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

Support multiple edge types in Graph.hasEdge #8550

Merged
merged 15 commits into from Oct 19, 2022

Conversation

mattcompiles
Copy link
Contributor

@mattcompiles mattcompiles commented Oct 17, 2022

↪️ Pull Request

This PR adds some desired functionality discovered when creating #8453. @AGawrys

Currently, Graph.hasEdge only accepts a single edge type to validate against. This PR adds support for:

  • An array of possible edge types
  • The ALL_EDGE_TYPES constant, allowing edge checks to be type agnostic.

As the graph isn't currently aware of all possible edge types without doing lookups, we (@alshdavid and I) have added a new edgeTypes property to the AdjacencyList which is appended inside addEdge. To keep things simple, we never remove edge types. This shouldn't cause any issues, but does mean it's possible to search for edge types that no longer exist in the graph and edge types are never cleaned up once they have existed.

It's possible we'll decide that supporting ALL_EDGE_TYPES isn't worth tracking the extra piece of state. If that's the case it should be easy to remove that code and keep just the passed array of edge types param.

After a discussion with @AGawrys we've decided simple array support is enough and ALL_EDGE_TYPES isn't worth the complexity.

💻 Examples

graph.addEdge(a, b, 2);

graph.hasEdge(a, b, [1, 2]);

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@parcel-benchmark
Copy link

parcel-benchmark commented Oct 17, 2022

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 1.90s -87.00ms
Cached 402.00ms -21.00ms 🚀

Cold Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 341.00ms +28.00ms ⚠️
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 342.00ms +27.00ms ⚠️
dist/modern/parcel.7cdb0fad.webp 102.94kb +0.00b 343.00ms +29.00ms ⚠️
dist/legacy/index.b8ae99ba.css 94.00b +0.00b 350.00ms +29.00ms ⚠️
dist/modern/index.31cedca9.css 94.00b +0.00b 349.00ms +28.00ms ⚠️

Cached Bundles

No bundle changes detected.

React HackerNews 🚨

Timings

Description Time Difference
Cold FAILED -0.00ms
Cached FAILED -0.00ms

Cold Bundles

No bundles found, this is probably a failed build...

Cached Bundles

No bundles found, this is probably a failed build...

AtlasKit Editor 🚨

Timings

Description Time Difference
Cold FAILED -0.00ms
Cached FAILED -0.00ms

Cold Bundles

No bundles found, this is probably a failed build...

Cached Bundles

No bundles found, this is probably a failed build...

Three.js ✅

Timings

Description Time Difference
Cold 8.22s -24.00ms
Cached 340.00ms -0.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Click here to view a detailed benchmark overview.

Copy link
Contributor Author

@mattcompiles mattcompiles left a comment

Choose a reason for hiding this comment

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

@thebriando I made the changes we spoke about. Had a bit of trouble with the types, I think a lot of the serialize/deserialze types are not quite right which I ended up changing in some cases.

Let me know what you think.

packages/core/graph/src/Graph.js Outdated Show resolved Hide resolved
packages/bundlers/experimental/src/ExperimentalBundler.js Outdated Show resolved Hide resolved
@mattcompiles mattcompiles changed the title Support multiple edge types in Graph.hasEdge Support multiple edge types in Graph.hasEdge Oct 18, 2022
@AGawrys AGawrys self-requested a review October 19, 2022 00:44
@lettertwo lettertwo merged commit e168a78 into v2 Oct 19, 2022
@lettertwo lettertwo deleted the mattcompiles/has-edge-multiple-types branch October 19, 2022 18:10
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.

None yet

5 participants