aonyx/graph
Types
Represents a graph with nodes identified by a key, containing an optional value, with edges having an associated optional label.
pub opaque type Graph(key, value, label)
Returned when trying to retrieve a node or edge that does not exist.
pub type GraphError(key) {
NodeNotFoundError(key: key)
EdgeNotFoundError(from: key, to: key)
}
Constructors
-
NodeNotFoundError(key: key)
-
EdgeNotFoundError(from: key, to: key)
Values
pub fn get_edge(
graph: Graph(a, b, c),
from: a,
to: a,
) -> Result(Edge(a, c), GraphError(a))
Returns the edge from the graph with the given from and to node keys, or an error when the edge does not exist.
pub fn get_edges(graph: Graph(a, b, c)) -> List(Edge(a, c))
Returns a list of all edges in the graph.
pub fn get_node(
graph: Graph(a, b, c),
key: a,
) -> Result(Node(a, b), GraphError(a))
Returns the node from the graph with the given key, or an error when the node does not exist.
pub fn get_nodes(graph: Graph(a, b, c)) -> List(Node(a, b))
Returns a list of all nodes in the graph.
pub fn insert_edge(
graph: Graph(a, b, c),
edge: Edge(a, c),
) -> Graph(a, b, c)
Inserts an edge into the graph. If a node does not exist in the graph, it is created. If the edge already exists, its info is updated.
pub fn insert_node(
graph: Graph(a, b, c),
node: Node(a, b),
) -> Graph(a, b, c)
Inserts a node into the graph. If a node with the same key already exists, its value is updated. If the node has incoming or outgoing edges, they are added to the graph. If any of the target nodes do not exist, they are created.
pub fn remove_edge(
graph: Graph(a, b, c),
edge: Edge(a, c),
) -> Graph(a, b, c)
Removes an edge from the graph. If one of the nodes does not exist in the graph, NodeNotFoundError is returned. If the edge does not exist, the graph remains unchanged.
pub fn remove_node(
graph: Graph(a, b, c),
node: Node(a, b),
) -> Graph(a, b, c)
Removes a node and all its edges from the graph. If the node does not exist, the graph remains unchanged.