Skip to main content

Module graph_query

Module graph_query 

Source
Expand description

GraphQuery: portable, composable graph query interface.

Ported from Pattern.Graph.GraphQuery in the Haskell reference implementation.

§Overview

GraphQuery<V> is a struct-of-closures representing the complete query interface over a graph. Algorithms operate against this interface, not against any specific backing representation. This enables the same algorithm code to run against PatternGraph, database-backed stores, or any other structure that can produce the nine required closures.

§Structural Invariants

Implementations of GraphQuery<V> must uphold these invariants:

  1. query_source(r) = Some(s) implies s ∈ query_nodes()
  2. query_target(r) = Some(t) implies t ∈ query_nodes()
  3. r ∈ query_incident_rels(n) implies query_source(r) = Some(n) || query_target(r) = Some(n)
  4. query_degree(n) == query_incident_rels(n).len() (default; may be faster indexed)
  5. query_node_by_id(n.value.identify()) = Some(n) for all n ∈ query_nodes()
  6. query_relationship_by_id(r.value.identify()) = Some(r) for all r ∈ query_relationships()
  7. query_containers returns only direct containers — not transitive containment

Structs§

GraphQuery
Portable graph query interface: a struct of nine closures.

Enums§

TraversalDirection
Which direction along a directed relationship is being traversed.

Functions§

directed
Forward cost 1.0, Backward cost INFINITY — follow edge direction only.
directed_reverse
Forward cost INFINITY, Backward cost 1.0 — follow edges in reverse only.
frame_query
Restrict a GraphQuery<V> to elements satisfying include.
memoize_incident_rels
Wrap query_incident_rels and query_degree with an eager HashMap cache.
undirected
Uniform cost 1.0 in both directions — treat all edges as bidirectional.

Type Aliases§

TraversalWeight
A cost function for traversing a relationship in a given direction.