Skip to content

Latest commit

 

History

History
72 lines (55 loc) · 4.46 KB

File metadata and controls

72 lines (55 loc) · 4.46 KB

Graphs

The Hunt for the Missing Data Type (Hacker News)

Are Graphs hard in Rust?

Types

  • Directed/undirected
  • Simple/multi-edge
  • Hypergraphs, where an edge can connect three or more nodes
  • Ubergraphs, where edges can point to other edges

Category:Extensions and generalizations of graphs - Wikipedia

Representations

  • Adjacency matrix: [0 1 0; 0 0 1; 1 1 0]
    • Suitable for dense graphs
  • Adjacency list: [[b], [c], [a, b]]
  • Edge list: [[a, b], [b, c], [c, a], [c, b]]
  • Adjacency array
  • Doubly connected edge list (DCEL)
  • Pointer-and-struct
  • A set of these structs with references to each other

What about implementing node data? Edge data? Different types of nodes and edges? Most third party libraries roughly fall in one of two categories:

  • Offer a single rich datatype that covers all use-cases at the cost of efficiency.
    • NetworkX stores graph as a dict of dicts of dicts, so that both nodes and edges can have arbitrary data.
  • Offer separate graph types for each representation, and rely on the user to store node and edge data separately from the graph type.
    • petgraph

Implementations

Rust

pnevyk/rusty-graphs: Collection of examples for showcasing various Rust graph data structure libraries.

Python

Python Graph Libraries - Python Wiki

Tutorial

nx-guides

Representations:

  • A dict of dicts of dicts, so that both nodes and edges can have arbitrary data
  • adjacency_matrix()

MultiGraph:

  • add_edge() can specify the keys used to distinguish multiedges between a pair of nodes.