Giter VIP home page Giter VIP logo

Comments (5)

cpettitt avatar cpettitt commented on June 26, 2024

This should help: https://github.com/cpettitt/graphlib/wiki/API-Reference#nodeEdges.

from graphlib.

sprilukin avatar sprilukin commented on June 26, 2024

Yes this will works, but this method has two drawbacks:

  1. Does not respect direction
  2. 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:

  1. I need to manually handle edges object
  2. 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.

cpettitt avatar cpettitt commented on June 26, 2024

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.

sprilukin avatar sprilukin commented on June 26, 2024

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.

cpettitt avatar cpettitt commented on June 26, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.