Skip to content

GraphHasEdge

Description

Check whether graph contains directed edge from -> to.

from and to must both be live node ids. This query treats stale ids as programmer error and aborts instead of quietly collapsing them to “not found”.

Parameters

Name Direction Description
g in Graph to query.
from in Source node id.
to in Destination node id.

Success

true when the directed edge exists.

Failure

false

Usage example (Cross-references)

Usage examples (Cross-references)
        result = result && (GraphInDegree(&graph, a) == 1);
        result = result && (GraphInDegree(&graph, c) == 0);
        result = result && GraphHasEdge(&graph, c, a);
        result = result && (GraphPredecessorAt(&graph, a, 0) == c);
        }
    
        bool result = GraphHasEdge(&graph, a, b);
        result      = result && GraphMarkEdgeForRemoval(&graph, b, c);
        result      = result && !GraphMarkEdgeForRemoval(&graph, b, c);
    
        result = result && (committed == 2);
        result = result && !GraphHasEdge(&graph, a, b);
        result = result && GraphHasEdge(&graph, a, c);
        result = result && !GraphHasEdge(&graph, b, c);
        result = result && (committed == 2);
        result = result && !GraphHasEdge(&graph, a, b);
        result = result && GraphHasEdge(&graph, a, c);
        result = result && !GraphHasEdge(&graph, b, c);
        result = result && (GraphEdgeCount(&graph) == 1);
        result = result && !GraphHasEdge(&graph, a, b);
        result = result && GraphHasEdge(&graph, a, c);
        result = result && !GraphHasEdge(&graph, b, c);
        result = result && (GraphEdgeCount(&graph) == 1);
        result = result && (GraphOutDegree(&graph, a) == 1);
        result      = result && !GraphUnmarkEdgeForRemoval(&graph, a, b);
        result      = result && (GraphCommitChanges(&graph) == 0);
        result      = result && GraphHasEdge(&graph, a, b);
        result      = result && (GraphEdgeCount(&graph) == 1);
        result      = result && GraphEdgeMarkedForRemoval(&graph, a, c);
        result      = result && (GraphCommitChanges(&graph) == 1);
        result      = result && GraphHasEdge(&graph, a, b);
        result      = result && !GraphHasEdge(&graph, a, c);
        result      = result && (GraphOutDegree(&graph, a) == 1);
        result      = result && (GraphCommitChanges(&graph) == 1);
        result      = result && GraphHasEdge(&graph, a, b);
        result      = result && !GraphHasEdge(&graph, a, c);
        result      = result && (GraphOutDegree(&graph, a) == 1);
        result      = result && (GraphInDegree(&graph, b) == 1);
        result      = result && GraphContainsNode(&graph, a);
        result      = result && GraphContainsNode(&graph, c);
        result      = result && GraphHasEdge(&graph, a, c);
        result      = result && (GraphOutDegree(&graph, a) == 1);
        result      = result && (GraphEdgeCount(&graph) == 1);
    
    static bool test_graph_has_edge_query(void) {
        WriteFmt("Testing GraphHasEdge\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        GraphAddEdge(&graph, green, blue);
    
        bool result = GraphHasEdge(&graph, red, green);
        result      = result && GraphHasEdge(&graph, green, blue);
        result      = result && !GraphHasEdge(&graph, blue, green);
    
        bool result = GraphHasEdge(&graph, red, green);
        result      = result && GraphHasEdge(&graph, green, blue);
        result      = result && !GraphHasEdge(&graph, blue, green);
        result      = result && !GraphHasEdge(&graph, red, blue);
        bool result = GraphHasEdge(&graph, red, green);
        result      = result && GraphHasEdge(&graph, green, blue);
        result      = result && !GraphHasEdge(&graph, blue, green);
        result      = result && !GraphHasEdge(&graph, red, blue);
        result      = result && (ZstrCompare(*GraphNodePtrAt(&graph, red), "red") == 0);
        result      = result && GraphHasEdge(&graph, green, blue);
        result      = result && !GraphHasEdge(&graph, blue, green);
        result      = result && !GraphHasEdge(&graph, red, blue);
        result      = result && (ZstrCompare(*GraphNodePtrAt(&graph, red), "red") == 0);
    // a silent `false` instead of aborting on the caller bug.
    static bool test_has_edge_rejects_invalid_destination_deadend(void) {
        WriteFmt("Testing GraphHasEdge rejects an invalid destination id (should abort)\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        GraphNodeId bogus_to = make_raw_node_id(5, 1);
    
        (void)GraphHasEdge(&graph, a, bogus_to);
    
        GraphDeinit(&graph);
Last updated on