Comments (5)
This should help: https://github.com/cpettitt/graphlib/wiki/API-Reference#nodeEdges.
from graphlib.
Yes this will works, but this method has two drawbacks:
- Does not respect direction
- takes
O(|E|)
I've implemented this in other way:
var g = new Graph(); //multigraph: false
//adding first edge - with id "edge1"
g.setEdge("a", "b", {"edge1": {otherInfo: "..."}});
//get info about all edges between "a", "b"
var edgeInfo = g.edge("a", "b"); // -> {"edge1": {otherInfo: "..."}}
//adding second edge
edgeInfo["edge2"] = {"otherInfo": "..."}
//check all edges between a, b:
var edgeInfo = g.edge("a", "b"); // -> {"edge1": {otherInfo: "..."}, "edge2": {otherInfo: ""}}
This works, but it also has drawbacks:
- I need to manually handle edges object
- Algorithms such as dijkstra will not work correctly since they do not know about that surrogate edges.
UPD: with my solution dijkstra will works if edgeFn will be correctly implemented.
from graphlib.
https://github.com/cpettitt/graphlib/wiki/API-Reference#inEdges and https://github.com/cpettitt/graphlib/wiki/API-Reference#outEdges give you directionality. Storing multi-edges directly in the label will have the same worst case time complexity as the above. In practice the above might be faster - it'd have to be measured.
from graphlib.
Well i thought that this operation:
//check all edges between a, b:
var edgeInfo = g.edge("a", "b"); // -> {"edge1": {otherInfo: "..."}, "edge2": {otherInfo: ""}}
takes constant O(1)
time
What is the worst case you are talking about?
from graphlib.
@sprilukin You're right, the access itself is going to take constant time. The linear time complexity comes in when you try to scan the list. Your approach is fine, but you may or may not get a speed up in practice to compensate for having to carry additional traversal logic along with the graph (e.g. edgeFn
).
from graphlib.
Related Issues (20)
- graph.predecessors and graph.inEdges do not alway work
- Edges are not correctly handled HOT 1
- Convert Travis CI to GitHub Actions? HOT 1
- Is there webassembly version for this great library? HOT 1
- Is graphLib no longer deprecated? HOT 1
- Bug Report:Get wrong answer when running dijkstra in an undirected graph
- Release? HOT 5
- Recursive DFS implementations HOT 1
- about lodash version HOT 1
- isAcyclic and findCycles aren't working as expected
- Implement minimizing crossing algorithms
- Who owns this and is it really being maintained? HOT 3
- Replacing Dagre with Graphlib HOT 2
- Release latest version 3.0.1 to npm ? HOT 8
- Qn: Is there a documentation? HOT 1
- Feature-Add a new language translation by Chinese
- Version 2.2.0 ESM import wont work HOT 1
- Unexpected character '#' HOT 1
- `findCycles` algorithm fails for undirected graphs
- Do you have a changelog HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphlib.