Model Module
Core graph data structures and basic operations for the yog library.
This module defines the fundamental Graph type and provides all basic operations
for creating and manipulating graphs. The graph uses an adjacency list representation
with dual indexing (both outgoing and incoming edges) for efficient traversal in both
directions.
Types
| Type | Description |
|
A simple graph data structure that can be directed or undirected.
- |
|
|
The type of graph: directed or undirected. |
|
|
Unique identifier for a node in the graph. |
Functions and values
| Function or value |
Description
|
||
|
Adds an edge to the graph with the given weight. For directed graphs, adds a single edge from src to dst. For undirected graphs, adds edges in both directions.
Example
Note: If Parameters
|
||
|
Like If
Example
Parameters
|
||
Like
Parameters
|
|||
|
Adds an edge, but if an edge already exists between The combine function receives
Example
Time Complexity: O(1) Use Cases
Parameters
val graph: obj
|
||
|
Adds a node to the graph with the given ID and data. If a node with this ID already exists, its data will be replaced.
Example
Parameters
|
||
|
|||
|
Returns the number of edges in the graph. For undirected graphs, each edge is counted once (the pair {u, v}). For directed graphs, each directed edge (u -> v) is counted once. Time Complexity: O(V)
Parameters
|
||
|
|||
|
Gets everyone connected to the node, regardless of direction. For undirected graphs, this is equivalent to
Parameters
|
||
Returns the number of nodes in the graph.
Equivalent to
|
|||
|
Returns the number of nodes in the graph (graph order). Time Complexity: O(1)
Parameters
|
||
|
|||
|
|||
|
Removes an edge from src to dst. For undirected graphs, removes edges in both directions.
Example
Time Complexity: O(1) Parameters
val graph: obj
|
||
|
Removes a node and all its connected edges (incoming and outgoing).
Example
Time Complexity: O(deg(v)) - proportional to the number of edges connected to the node, not the whole graph. Parameters
val graph: obj
|
||
|
|||
|