Zog.ResourceGraph (Zog v0.4.0)

View Source

Native graph resource backed by Zog (Zig) via Zigler.

Unlike the Copy-In/Copy-Out pattern, ResourceGraph keeps the Zig ArrayGraph or GraphMap alive as a NIF resource between calls. Build once, run many algorithms, destroy when done.

Backends

Zog supports two native graph backends, selectable via the :backend option:

  • :soa (default) - Structure of Arrays (ArrayGraph).
    • Structure: Stores nodes and edges in flat, contiguous memory slices.
    • Performance: Provides maximum execution speed and optimal cache locality.
    • Use Case: Recommended for read-heavy, build-once-run-many query workloads where the topology does not change between NIF calls.
  • :hash_graph - Hash Map Graph (GraphMap).
    • Structure: Stores nodes and edges using standard hash tables with buckets and dynamic resizing.
    • Performance: Incurs significant overhead due to pointer-heavy hashing, collision resolution, and lack of cache locality.
    • Use Case: Use only if your workload relies on dynamic graph mutation (adding or deleting nodes/edges natively) between algorithm executions.

Examples

Create a resource graph using the high-performance :soa backend:

graph = Zog.directed() |> Zog.add_edge("A", "B", 1.0)
res = Zog.ResourceGraph.new(graph, backend: :soa)
# compute centralities...
Zog.ResourceGraph.destroy(res)

Create a resource graph using the :hash_graph backend:

res = Zog.ResourceGraph.read_edgelist("edges.txt", backend: :hash_graph)
# compute centralities...
Zog.ResourceGraph.destroy(res)

Summary

Types

t()

A native graph resource together with its label mapping.

Functions

Returns true if the directed ResourceGraph contains no directed cycles.

Analyzes an undirected ResourceGraph natively to find all bridges and articulation points.

Computes the Approximate Neighborhood Function (ANF) and effective diameter. Returns {:ok, %{neighborhood_sizes: [float()], effective_diameter: float()}} or {:error, any()}.

Checks if the native resource graph is an arborescence.

Finds the root label of an arborescence in the native resource graph, or nil.

Degree assortativity.

Computes the shortest path and its weight between two nodes using A* algorithm directly on the native graph resource.

Average clustering coefficient.

Returns the average path length of a ResourceGraph.

Computes the shortest path and its weight between two nodes using Bellman-Ford algorithm directly on the native graph resource.

Weighted betweenness centrality.

Unweighted betweenness centrality.

Checks whether a ResourceGraph is bipartite (2-colourable) natively.

Returns the bipartite partition of a ResourceGraph as two MapSets of node labels, or {:error, :not_bipartite} if the graph is not 2-colourable.

Computes maximum cardinality matching on general (non-bipartite) graphs using Edmonds' Blossom algorithm.

Checks if the native resource graph is a branching.

Closeness centrality.

Checks if the native resource graph is complete.

Contracts two nodes in a ResourceGraph into a single node.

Calculates all core numbers for all nodes in the ResourceGraph.

Returns true if the directed ResourceGraph contains at least one directed cycle.

Explicitly destroys a native graph resource, freeing its memory.

Returns the diameter of a ResourceGraph.

Computes the shortest path and its weight between two nodes using Dijkstra's algorithm directly on the native graph resource.

Returns a map from node label to eccentricity for a ResourceGraph.

Returns the ego graph of center from a ResourceGraph.

Eigenvector centrality.

Finds an Eulerian circuit in the native graph.

Finds an Eulerian path in the native graph.

Finds node mapping dict %{g1_label => g2_label} if isomorphic, or nil.

Floyd-Warshall all-pairs shortest paths.

Checks if the native resource graph is a forest.

Builds a native graph resource directly from a Graph (from libgraph).

Builds a native graph resource directly from a Yog.Graph.

Computes the global minimum cut of the undirected network using the Stoer-Wagner algorithm.

Checks if the native graph contains an Eulerian circuit.

Checks if the native graph contains an Eulerian path.

Calculates the Weisfeiler-Lehman structural graph hash for a ResourceGraph.

Computes all health metrics at once on a ResourceGraph.

Calculates HITS hub and authority scores for a ResourceGraph.

Calculates weighted bipartite matching using the O(V³) Hungarian (Kuhn-Munkres) algorithm.

Checks if two native resource graphs are isomorphic using exact VF2 matching.

Johnson's Algorithm for all-pairs shortest paths.

Katz centrality.

Label Propagation community detection.

Leiden community detection.

Leiden hierarchical community detection.

Local clustering coefficient for each node.

Louvain community detection.

Computes the maximum flow and minimum cut natively on a ResourceGraph.

Computes a maximum bipartite matching on a ResourceGraph using the Hopcroft-Karp algorithm.

Computes modularity for a given community partition.

Builds a native graph resource from a SoA.

Graph density.

Returns a list of node degrees directly corresponding to internal u32 node IDs.

PageRank centrality.

Returns the radius of a ResourceGraph.

Checks if a target node is reachable from a start node using BFS traversal directly on the native graph resource.

Reads a graph from an adjacency list file directly in native memory.

Reads a graph from an edge list file directly in native memory.

Reads a graph from a Trivial Graph Format (TGF) file directly in native memory.

Checks if the native resource graph is k-regular.

Finds strongly connected components in the ResourceGraph natively. Returns a list of lists of node labels.

Extracts an induced subgraph from a ResourceGraph containing only the specified node labels and the edges between them.

Converts a native graph resource back to a Graph (from libgraph).

Converts a native graph resource back to a Yog.Graph.

Computes a topological ordering of the directed ResourceGraph.

Computes the transitive closure of a ResourceGraph.

Computes the transitive reduction of a ResourceGraph.

Checks if the native resource graph is a tree.

Triangle count.

Walktrap community detection.

Hierarchical Walktrap community detection.

Finds weakly connected components in the ResourceGraph natively. Returns a list of lists of node labels.

Computes the k shortest loopless paths and their weights between two nodes using Yen's algorithm directly on the native graph resource.

Types

t()

@type t() :: %{resource: reference(), builder: Zog.SoA.t()}

A native graph resource together with its label mapping.

Functions

acyclic?(map)

@spec acyclic?(t()) :: boolean()

Returns true if the directed ResourceGraph contains no directed cycles.

alpha_centrality(map, opts \\ [])

@spec alpha_centrality(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => float()} | [float()]

Alpha centrality.

Options

  • :alpha - Attenuation factor (defaults to 0.5).
  • :initial - Initial values (defaults to 1.0).
  • :max_iterations - Maximum iteration steps (defaults to 100).
  • :tolerance - Convergence tolerance (defaults to 0.0001).
  • :raw - If true, returns a list of scores directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

alpha_centrality(arg1, arg2, arg3, arg4, arg5)

@spec alpha_centrality(
  reference(),
  float(),
  float(),
  0..18_446_744_073_709_551_615,
  float()
) :: [
  float()
]

analyze(map, opts \\ [])

@spec analyze(
  t(),
  keyword()
) :: %{
  bridges: [{Zog.SoA.label(), Zog.SoA.label()}],
  articulation_points: [Zog.SoA.label()]
}

Analyzes an undirected ResourceGraph natively to find all bridges and articulation points.

anf(map, opts \\ [])

@spec anf(
  t(),
  keyword()
) ::
  {:ok, %{neighborhood_sizes: [float()], effective_diameter: float()}}
  | {:error, any()}

Computes the Approximate Neighborhood Function (ANF) and effective diameter. Returns {:ok, %{neighborhood_sizes: [float()], effective_diameter: float()}} or {:error, any()}.

Options

  • :max_steps - Maximum number of steps to traverse (defaults to 30).
  • :m - Number of registers (trials) per node (defaults to 64).

arborescence?(map)

Checks if the native resource graph is an arborescence.

arborescence_root(map)

Finds the root label of an arborescence in the native resource graph, or nil.

assortativity(map)

@spec assortativity(t()) :: float()

Degree assortativity.

astar(map, start_label, goal_label, x_coords, y_coords, heuristic \\ :euclidean, opts \\ [])

@spec astar(
  t(),
  Zog.SoA.label(),
  Zog.SoA.label(),
  map() | list(),
  map() | list(),
  atom(),
  keyword()
) ::
  {:ok, {[Zog.SoA.label()], float()}} | {:error, :no_path}

Computes the shortest path and its weight between two nodes using A* algorithm directly on the native graph resource.

average_clustering_coefficient(map)

@spec average_clustering_coefficient(t()) :: float()

Average clustering coefficient.

average_path_length(res_graph)

@spec average_path_length(t()) :: float()

Returns the average path length of a ResourceGraph.

bellman_ford(map, start_label, goal_label, opts \\ [])

@spec bellman_ford(t(), Zog.SoA.label(), Zog.SoA.label(), keyword()) ::
  {:ok, {[Zog.SoA.label()], float()}}
  | {:error, :no_path}
  | {:error, :negative_cycle}

Computes the shortest path and its weight between two nodes using Bellman-Ford algorithm directly on the native graph resource.

betweenness_f64(map, opts \\ [])

@spec betweenness_f64(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => float()} | [float()]

Weighted betweenness centrality.

Options

  • :raw - If true, returns a list of scores directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

betweenness_unweighted(map, opts \\ [])

@spec betweenness_unweighted(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => float()} | [float()]

Unweighted betweenness centrality.

Options

  • :raw - If true, returns a list of scores directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

bipartite_check(map, opts \\ [])

@spec bipartite_check(
  t(),
  keyword()
) :: boolean()

Checks whether a ResourceGraph is bipartite (2-colourable) natively.

Returns true when the graph is bipartite, false otherwise.

bipartite_partition(map, opts \\ [])

@spec bipartite_partition(
  t(),
  keyword()
) ::
  {:ok, MapSet.t(Zog.SoA.label()), MapSet.t(Zog.SoA.label())}
  | {:error, :not_bipartite}

Returns the bipartite partition of a ResourceGraph as two MapSets of node labels, or {:error, :not_bipartite} if the graph is not 2-colourable.

Returns {:ok, set_a, set_b}.

blossom_maximum_matching(map, opts \\ [])

@spec blossom_maximum_matching(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => Zog.SoA.label()}

Computes maximum cardinality matching on general (non-bipartite) graphs using Edmonds' Blossom algorithm.

Returns matching map %{u => v, v => u}.

branching?(map)

Checks if the native resource graph is a branching.

closeness_f64(map, opts \\ [])

@spec closeness_f64(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => float()} | [float()]

Closeness centrality.

Options

  • :raw - If true, returns a list of scores directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

complete?(map)

Checks if the native resource graph is complete.

contract(res_graph, label1, label2, opts \\ [])

@spec contract(t(), Zog.SoA.label(), Zog.SoA.label(), keyword()) :: t()

Contracts two nodes in a ResourceGraph into a single node.

See Zog.Transform.contract/4 for options.

core_numbers(map, opts \\ [])

@spec core_numbers(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => integer()} | [integer()]

Calculates all core numbers for all nodes in the ResourceGraph.

Options

  • :raw - If true, returns a list of core numbers directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

cyclic?(map)

@spec cyclic?(t()) :: boolean()

Returns true if the directed ResourceGraph contains at least one directed cycle.

density(map)

@spec density(t()) :: float()
@spec density(t()) :: float()

destroy(map)

@spec destroy(t()) :: :ok

Explicitly destroys a native graph resource, freeing its memory.

diameter(res_graph)

@spec diameter(t()) :: float()

Returns the diameter of a ResourceGraph.

dijkstra(map, start_label, goal_label, opts \\ [])

@spec dijkstra(t(), Zog.SoA.label(), Zog.SoA.label(), keyword()) ::
  {:ok, {[Zog.SoA.label()], float()}} | {:error, :no_path}

Computes the shortest path and its weight between two nodes using Dijkstra's algorithm directly on the native graph resource.

eccentricity(res_graph, opts \\ [])

@spec eccentricity(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => float()} | [float()]

Returns a map from node label to eccentricity for a ResourceGraph.

edge_count(map)

@spec edge_count(t()) :: non_neg_integer()

ego_graph(res_graph, center, opts \\ [])

@spec ego_graph(t(), Zog.SoA.label(), keyword()) :: t()

Returns the ego graph of center from a ResourceGraph.

The returned ResourceGraph contains the center node, all nodes within :radius hops (default 1), and all edges between those nodes. Edges are treated as undirected when expanding the neighbourhood.

Options

  • :radius - number of hops to include (default 1)

eigenvector(map, opts \\ [])

@spec eigenvector(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => float()} | [float()]

Eigenvector centrality.

Options

  • :max_iterations - Maximum iteration steps (defaults to 100).
  • :tolerance - Convergence tolerance (defaults to 0.0001).
  • :raw - If true, returns a list of scores directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

eigenvector(arg1, arg2, arg3)

@spec eigenvector(reference(), 0..18_446_744_073_709_551_615, float()) :: [float()]

eulerian_circuit(map, opts \\ [])

@spec eulerian_circuit(
  t(),
  keyword()
) :: {:ok, [Zog.SoA.label()]} | {:error, :no_eulerian_circuit}

Finds an Eulerian circuit in the native graph.

eulerian_path(map, opts \\ [])

@spec eulerian_path(
  t(),
  keyword()
) :: {:ok, [Zog.SoA.label()]} | {:error, :no_eulerian_path}

Finds an Eulerian path in the native graph.

find_isomorphism(map1, map2)

Finds node mapping dict %{g1_label => g2_label} if isomorphic, or nil.

floyd_warshall(map)

@spec floyd_warshall(t()) :: {:ok, [[float()]]} | {:error, :negative_cycle}

Floyd-Warshall all-pairs shortest paths.

forest?(map)

Checks if the native resource graph is a forest.

from_libgraph(libgraph, opts \\ [])

@spec from_libgraph(
  Graph.t(),
  keyword()
) :: t()

Builds a native graph resource directly from a Graph (from libgraph).

from_yog(yog_graph, opts \\ [])

@spec from_yog(
  Yog.graph(),
  keyword()
) :: t()

Builds a native graph resource directly from a Yog.Graph.

global_min_cut(map, opts \\ [])

@spec global_min_cut(
  t(),
  keyword()
) :: %{
  cut_value: float(),
  source_side: [Zog.SoA.label()],
  sink_side: [Zog.SoA.label()]
}

Computes the global minimum cut of the undirected network using the Stoer-Wagner algorithm.

harmonic_centrality_f64(map, opts \\ [])

@spec harmonic_centrality_f64(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => float()} | [float()]

Harmonic centrality.

Options

  • :raw - If true, returns a list of scores directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

has_eulerian_circuit?(map)

@spec has_eulerian_circuit?(t()) :: boolean()

Checks if the native graph contains an Eulerian circuit.

has_eulerian_path?(map)

@spec has_eulerian_path?(t()) :: boolean()

Checks if the native graph contains an Eulerian path.

hash(map, opts \\ [])

@spec hash(
  t(),
  keyword()
) :: String.t()

Calculates the Weisfeiler-Lehman structural graph hash for a ResourceGraph.

Returns a 32-character hexadecimal MD5 hash string.

health_metrics(map, opts \\ [])

@spec health_metrics(
  t(),
  keyword()
) :: %{
  eccentricity: %{required(Zog.SoA.label()) => float()} | [float()],
  diameter: float(),
  radius: float(),
  average_path_length: float()
}

Computes all health metrics at once on a ResourceGraph.

Returns a map with :eccentricity, :diameter, :radius, and :average_path_length. The :eccentricity value is a map from node labels to eccentricity values.

Options

  • :raw - If true, returns eccentricity as a list directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

hits(map, opts \\ [])

@spec hits(
  t(),
  keyword()
) :: %{
  hubs: %{required(Zog.SoA.label()) => float()},
  authorities: %{required(Zog.SoA.label()) => float()}
}

Calculates HITS hub and authority scores for a ResourceGraph.

Returns %{hubs: %{label => score}, authorities: %{label => score}}.

Options

  • :max_iterations - Maximum power iterations (default: 100).
  • :tolerance - Convergence threshold for L2 norm (default: 1.0e-6).

hungarian(map, opts \\ [])

@spec hungarian(
  t(),
  keyword()
) :: {float(), %{required(Zog.SoA.label()) => Zog.SoA.label()}}

Calculates weighted bipartite matching using the O(V³) Hungarian (Kuhn-Munkres) algorithm.

Returns {cost, matching} where matching is a map of {u => v, v => u}. Raises ArgumentError if the graph is not bipartite.

Options

  • :optimization - :min (default) or :max.

is_arborescence?(res_graph)

is_branching?(res_graph)

is_complete?(res_graph)

is_forest?(res_graph)

is_isomorphic?(g1, g2)

is_regular?(res_graph, k)

is_tree?(res_graph)

isomorphic?(map1, map2)

Checks if two native resource graphs are isomorphic using exact VF2 matching.

johnsons(map)

@spec johnsons(t()) :: {:ok, [[float()]]} | {:error, :negative_cycle}

Johnson's Algorithm for all-pairs shortest paths.

k_shortest_paths(map, start_label, goal_label, k, opts \\ [])

Alias for yen_k_shortest/5.

katz(map, opts \\ [])

@spec katz(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => float()} | [float()]

Katz centrality.

Options

  • :alpha - Attenuation factor (defaults to 0.1).
  • :beta - Weight parameter (defaults to 1.0).
  • :max_iterations - Maximum iteration steps (defaults to 100).
  • :tolerance - Convergence tolerance (defaults to 0.0001).
  • :raw - If true, returns a list of scores directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

katz(arg1, arg2, arg3, arg4, arg5)

@spec katz(reference(), float(), float(), 0..18_446_744_073_709_551_615, float()) :: [
  float()
]

kruskal(graph, opts \\ [])

@spec kruskal(
  t(),
  keyword()
) :: {:ok, [Yog.MST.edge()]}

label_propagation(map, opts \\ [])

@spec label_propagation(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => non_neg_integer()} | [non_neg_integer()]

Label Propagation community detection.

Options

  • :max_iterations - Maximum iteration steps (defaults to 100).
  • :seed - Random seed (defaults to 0).
  • :raw - If true, returns a list of community IDs directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

label_propagation(arg1, arg2, arg3)

@spec label_propagation(
  reference(),
  0..18_446_744_073_709_551_615,
  0..18_446_744_073_709_551_615
) :: [
  0..18_446_744_073_709_551_615
]

leiden(map, opts \\ [])

@spec leiden(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => non_neg_integer()} | [non_neg_integer()]

Leiden community detection.

Options

  • :min_modularity_gain - Minimum modularity gain to stop iterations (defaults to 0.000001).
  • :max_iterations - Maximum iteration steps (defaults to 100).
  • :seed - Random seed for execution (defaults to 42).
  • :theta - Resolution parameter theta (defaults to 1.0).
  • :raw - If true, returns a list of community IDs directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

leiden(arg1, arg2, arg3, arg4, arg5)

@spec leiden(
  reference(),
  float(),
  0..18_446_744_073_709_551_615,
  0..18_446_744_073_709_551_615,
  float()
) :: [0..18_446_744_073_709_551_615]

leiden_hierarchical(map, opts \\ [])

@spec leiden_hierarchical(
  t(),
  keyword()
) :: Zog.Community.Dendrogram.t() | [[non_neg_integer()]]

Leiden hierarchical community detection.

Options

  • :min_modularity_gain - Minimum modularity gain to stop iterations (defaults to 0.000001).
  • :max_iterations - Maximum iteration steps (defaults to 100).
  • :seed - Random seed for execution (defaults to 42).
  • :theta - Resolution parameter theta (defaults to 1.0).
  • :raw - If true, returns a raw list of lists of community assignments for each level instead of a Dendrogram struct.

leiden_hierarchical(arg1, arg2, arg3, arg4, arg5)

@spec leiden_hierarchical(
  reference(),
  float(),
  0..18_446_744_073_709_551_615,
  0..18_446_744_073_709_551_615,
  float()
) :: [[0..18_446_744_073_709_551_615]]

local_clustering_coefficient(map, opts \\ [])

@spec local_clustering_coefficient(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => float()} | [float()]

Local clustering coefficient for each node.

Options

  • :raw - If true, returns a list of coefficients directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

louvain(map, opts \\ [])

@spec louvain(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => non_neg_integer()} | [non_neg_integer()]

Louvain community detection.

Options

  • :min_modularity_gain - Minimum modularity gain to stop iterations (defaults to 0.000001).
  • :max_iterations - Maximum iteration steps (defaults to 100).
  • :seed - Random seed for execution (defaults to 42).
  • :raw - If true, returns a list of community IDs directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

louvain(arg1, arg2, arg3, arg4)

@spec louvain(
  reference(),
  float(),
  0..18_446_744_073_709_551_615,
  0..18_446_744_073_709_551_615
) :: [
  0..18_446_744_073_709_551_615
]

max_flow(graph, source, sink, algorithm_or_opts \\ :edmonds_karp, opts \\ [])

@spec max_flow(t(), Zog.SoA.label(), Zog.SoA.label(), atom() | keyword(), keyword()) ::
  %{
    max_flow: float(),
    residual_graph: Zog.SoA.t(),
    source_side: [Zog.SoA.label()],
    sink_side: [Zog.SoA.label()]
  }

Computes the maximum flow and minimum cut natively on a ResourceGraph.

maximum_bipartite_matching(map, opts \\ [])

@spec maximum_bipartite_matching(
  t(),
  keyword()
) :: {:ok, [{Zog.SoA.label(), Zog.SoA.label()}]} | {:error, :not_bipartite}

Computes a maximum bipartite matching on a ResourceGraph using the Hopcroft-Karp algorithm.

Returns {:ok, pairs} where pairs is a list of {left_label, right_label} tuples. Returns {:error, :not_bipartite} if the graph is not bipartite.

modularity(map, community_map)

@spec modularity(t(), %{required(Zog.SoA.label()) => non_neg_integer()}) :: float()

Computes modularity for a given community partition.

modularity_f64(arg1, arg2)

@spec modularity_f64(reference(), [0..18_446_744_073_709_551_615] | <<_::_*64>>) ::
  float()

new(builder, opts \\ [])

@spec new(
  Zog.SoA.t(),
  keyword()
) :: t()

Builds a native graph resource from a SoA.

Options

  • :backend - Choose the native graph backend, either :soa or :hash_graph (defaults to :soa).

new(arg1, arg2, arg3, arg4, arg5)

@spec new(
  0..18_446_744_073_709_551_615,
  [0..4_294_967_295] | <<_::_*32>>,
  [0..4_294_967_295] | <<_::_*32>>,
  [float()] | <<_::_*64>>,
  term()
) :: reference()

nif_analyze_connectivity(arg1)

@spec nif_analyze_connectivity(reference()) :: term()

nif_anf(arg1, arg2, arg3)

@spec nif_anf(
  reference(),
  0..18_446_744_073_709_551_615,
  0..18_446_744_073_709_551_615
) :: term()

nif_arborescence_root(arg1)

@spec nif_arborescence_root(reference()) :: term()

nif_assortativity(arg1)

@spec nif_assortativity(reference()) :: float()

nif_astar(arg1, arg2, arg3, arg4, arg5, arg6)

@spec nif_astar(
  reference(),
  0..4_294_967_295,
  0..4_294_967_295,
  [float()] | <<_::_*64>>,
  [float()] | <<_::_*64>>,
  term()
) :: term()

nif_average_clustering_coefficient(arg1)

@spec nif_average_clustering_coefficient(reference()) :: float()

nif_bellman_ford(arg1, arg2, arg3)

@spec nif_bellman_ford(reference(), 0..4_294_967_295, 0..4_294_967_295) :: term()

nif_betweenness_f64(arg1)

@spec nif_betweenness_f64(reference()) :: [float()]

nif_betweenness_unweighted(arg1)

@spec nif_betweenness_unweighted(reference()) :: [float()]

nif_blossom_maximum_matching(arg1)

@spec nif_blossom_maximum_matching(reference()) :: term()

nif_closeness_f64(arg1)

@spec nif_closeness_f64(reference()) :: [float()]

nif_core_numbers(arg1)

@spec nif_core_numbers(reference()) :: [0..4_294_967_295]

nif_density(arg1)

@spec nif_density(reference()) :: float()

nif_destroy(arg1)

@spec nif_destroy(reference()) :: :ok

nif_dijkstra(arg1, arg2, arg3)

@spec nif_dijkstra(reference(), 0..4_294_967_295, 0..4_294_967_295) :: term()

nif_edge_count(arg1)

@spec nif_edge_count(reference()) :: 0..18_446_744_073_709_551_615

nif_eulerian_path(arg1, arg2, arg3)

@spec nif_eulerian_path(reference(), boolean(), boolean()) :: term()

nif_find_isomorphism(arg1, arg2, arg3)

@spec nif_find_isomorphism(reference(), reference(), boolean()) :: term()

nif_floyd_warshall(arg1)

@spec nif_floyd_warshall(reference()) :: term()

nif_global_min_cut(arg1)

@spec nif_global_min_cut(reference()) :: term()

nif_harmonic_centrality_f64(arg1)

@spec nif_harmonic_centrality_f64(reference()) :: [float()]

nif_has_eulerian_circuit(arg1, arg2)

@spec nif_has_eulerian_circuit(reference(), boolean()) :: boolean()

nif_has_eulerian_path(arg1, arg2)

@spec nif_has_eulerian_path(reference(), boolean()) :: boolean()

nif_health_metrics(arg1)

@spec nif_health_metrics(reference()) :: term()

nif_hits(arg1, arg2, arg3)

@spec nif_hits(reference(), 0..18_446_744_073_709_551_615, float()) :: term()

nif_hungarian(arg1, arg2)

@spec nif_hungarian(reference(), boolean()) :: term()

nif_is_acyclic(arg1)

@spec nif_is_acyclic(reference()) :: boolean()

nif_is_arborescence(arg1)

@spec nif_is_arborescence(reference()) :: boolean()

nif_is_bipartite(arg1)

@spec nif_is_bipartite(reference()) :: term()

nif_is_branching(arg1)

@spec nif_is_branching(reference()) :: boolean()

nif_is_complete(arg1, arg2)

@spec nif_is_complete(reference(), boolean()) :: boolean()

nif_is_forest(arg1, arg2)

@spec nif_is_forest(reference(), boolean()) :: boolean()

nif_is_reachable(arg1, arg2, arg3)

@spec nif_is_reachable(reference(), 0..4_294_967_295, 0..4_294_967_295) :: term()

nif_is_regular(arg1, arg2, arg3)

@spec nif_is_regular(reference(), 0..4_294_967_295, boolean()) :: boolean()

nif_is_tree(arg1, arg2)

@spec nif_is_tree(reference(), boolean()) :: boolean()

nif_isomorphic(arg1, arg2, arg3)

@spec nif_isomorphic(reference(), reference(), boolean()) :: boolean()

nif_johnsons(arg1)

@spec nif_johnsons(reference()) :: term()

nif_kruskal(arg1)

@spec nif_kruskal(reference()) :: term()

nif_local_clustering_coefficient(arg1)

@spec nif_local_clustering_coefficient(reference()) :: [float()]

nif_max_flow(arg1, arg2, arg3)

@spec nif_max_flow(reference(), 0..4_294_967_295, 0..4_294_967_295) :: term()

nif_maximum_bipartite_matching(arg1)

@spec nif_maximum_bipartite_matching(reference()) :: term()

nif_node_count(arg1)

@spec nif_node_count(reference()) :: 0..18_446_744_073_709_551_615

nif_node_degrees(arg1)

@spec nif_node_degrees(reference()) :: [0..4_294_967_295]

nif_push_relabel(arg1, arg2, arg3)

@spec nif_push_relabel(reference(), 0..4_294_967_295, 0..4_294_967_295) :: term()

nif_read_adjlist(arg1, arg2, arg3, arg4)

@spec nif_read_adjlist([byte()] | binary(), boolean(), term(), boolean()) :: term()

nif_read_edgelist(arg1, arg2, arg3, arg4)

@spec nif_read_edgelist([byte()] | binary(), boolean(), term(), boolean()) :: term()

nif_read_tgf(arg1, arg2, arg3, arg4)

@spec nif_read_tgf([byte()] | binary(), boolean(), term(), boolean()) :: term()

nif_strongly_connected_components(arg1)

@spec nif_strongly_connected_components(reference()) :: [0..4_294_967_295]

nif_subgraph(arg1, arg2)

@spec nif_subgraph(reference(), [0..4_294_967_295] | <<_::_*32>>) :: reference()

nif_topological_sort(arg1, arg2)

@spec nif_topological_sort(reference(), term()) :: term()

nif_triangle_count(arg1)

@spec nif_triangle_count(reference()) :: 0..18_446_744_073_709_551_615

nif_walktrap(arg1, arg2, arg3, arg4)

@spec nif_walktrap(
  reference(),
  0..18_446_744_073_709_551_615,
  boolean(),
  0..18_446_744_073_709_551_615
) ::
  [0..18_446_744_073_709_551_615]

nif_walktrap_hierarchical(arg1, arg2)

@spec nif_walktrap_hierarchical(reference(), 0..18_446_744_073_709_551_615) :: [
  [0..18_446_744_073_709_551_615]
]

nif_weakly_connected_components(arg1)

@spec nif_weakly_connected_components(reference()) :: [0..4_294_967_295]

nif_weisfeiler_lehman_hash(arg1, arg2)

@spec nif_weisfeiler_lehman_hash(reference(), 0..18_446_744_073_709_551_615) :: term()

nif_yen_k_shortest(arg1, arg2, arg3, arg4)

@spec nif_yen_k_shortest(
  reference(),
  0..4_294_967_295,
  0..4_294_967_295,
  0..18_446_744_073_709_551_615
) ::
  term()

node_count(map)

@spec node_count(t()) :: non_neg_integer()

Graph density.

node_degrees(map)

@spec node_degrees(t()) :: [integer()]

Returns a list of node degrees directly corresponding to internal u32 node IDs.

pagerank(map, opts \\ [])

@spec pagerank(
  t(),
  keyword()
) :: %{required(Zog.SoA.label()) => float()} | [float()]

PageRank centrality.

Options

  • :damping - PageRank damping factor (defaults to 0.85).
  • :max_iterations - Maximum iteration steps (defaults to 100).
  • :tolerance - Convergence tolerance (defaults to 0.0001).
  • :raw - If true, returns a list of scores directly corresponding to internal u32 node IDs instead of mapping to Elixir labels.

pagerank(arg1, arg2, arg3, arg4)

@spec pagerank(reference(), float(), 0..18_446_744_073_709_551_615, float()) :: [
  float()
]

radius(res_graph)

@spec radius(t()) :: float()

Returns the radius of a ResourceGraph.

reachable?(map, start_label, goal_label, opts \\ [])

@spec reachable?(t(), Zog.SoA.label(), Zog.SoA.label(), keyword()) :: boolean()

Checks if a target node is reachable from a start node using BFS traversal directly on the native graph resource.

read_adjlist(path, opts \\ [])

@spec read_adjlist(
  Path.t(),
  keyword()
) :: t()

Reads a graph from an adjacency list file directly in native memory.

Options

  • :directed - Boolean flag representing if the graph is directed (defaults to true).
  • :backend - Choose the native graph backend, either :soa or :hash_graph (defaults to :soa).
  • :integer_labels - If true, parses labels as integers directly in Zig, bypassing string hash-map lookups (defaults to false). Note that sparse ID spaces will result in placeholder nodes being created up to max_id, meaning node_count will return max_id + 1 rather than the count of unique active nodes.

read_edgelist(path, opts \\ [])

@spec read_edgelist(
  Path.t(),
  keyword()
) :: t()

Reads a graph from an edge list file directly in native memory.

Options

  • :directed - Boolean flag representing if the graph is directed (defaults to true).
  • :backend - Choose the native graph backend, either :soa or :hash_graph (defaults to :soa).
  • :integer_labels - If true, parses labels as integers directly in Zig, bypassing string hash-map lookups (defaults to false). Note that sparse ID spaces will result in placeholder nodes being created up to max_id, meaning node_count will return max_id + 1 rather than the count of unique active nodes.

read_tgf(path, opts \\ [])

@spec read_tgf(
  Path.t(),
  keyword()
) :: t()

Reads a graph from a Trivial Graph Format (TGF) file directly in native memory.

Options

  • :directed - Boolean flag representing if the graph is directed (defaults to true).
  • :backend - Choose the native graph backend, either :soa or :hash_graph (defaults to :soa).
  • :integer_labels - If true, parses labels as integers directly in Zig, bypassing string hash-map lookups (defaults to false). Note that sparse ID spaces will result in placeholder nodes being created up to max_id, meaning node_count will return max_id + 1 rather than the count of unique active nodes.

regular?(map, k)

Checks if the native resource graph is k-regular.

strongly_connected_components(map, opts \\ [])

Finds strongly connected components in the ResourceGraph natively. Returns a list of lists of node labels.

Options

  • :raw - If true, returns a list of component IDs directly corresponding to internal u32 node IDs instead of grouping and mapping to Elixir labels.

subgraph(res_graph, node_labels, opts \\ [])

@spec subgraph(t(), [Zog.SoA.label()] | MapSet.t(Zog.SoA.label()), keyword()) :: t()

Extracts an induced subgraph from a ResourceGraph containing only the specified node labels and the edges between them.

Returns a new ResourceGraph holding both the native Zig resource and the corresponding Elixir SoA metadata. Call ResourceGraph.destroy/1 on the returned graph when it is no longer needed to release native memory.

to_libgraph(map)

@spec to_libgraph(t()) :: Graph.t()

Converts a native graph resource back to a Graph (from libgraph).

to_yog(map)

@spec to_yog(t()) :: Yog.graph()

Converts a native graph resource back to a Yog.Graph.

topological_sort(map, opts \\ [])

@spec topological_sort(
  t(),
  keyword()
) :: {:ok, [Zog.SoA.label()]} | {:ok, [non_neg_integer()]} | {:error, :cycle}

Computes a topological ordering of the directed ResourceGraph.

Returns {:ok, [labels]} for a DAG, or {:error, :cycle} if the graph contains a directed cycle.

Options

  • :raw - If true, returns a list of internal u32 node IDs instead of mapping to Elixir labels.

transitive_closure(res_graph, opts \\ [])

@spec transitive_closure(
  t(),
  keyword()
) :: t()

Computes the transitive closure of a ResourceGraph.

Returns a new directed ResourceGraph with an edge (u, v) for every node v reachable from u in the original graph, including self-loops.

Raises ArgumentError if the input graph is undirected.

transitive_reduction(res_graph, opts \\ [])

@spec transitive_reduction(
  t(),
  keyword()
) :: t()

Computes the transitive reduction of a ResourceGraph.

Returns a new directed ResourceGraph containing the minimal set of edges that preserves the same reachability as the original DAG.

Raises ArgumentError if the graph is undirected or contains cycles.

tree?(map)

Checks if the native resource graph is a tree.

triangle_count(map)

@spec triangle_count(t()) :: non_neg_integer()

Triangle count.

walktrap(map, opts \\ [])

Walktrap community detection.

Options

  • :walk_length - Length of random walks (default: 4)
  • :target_communities - Target number of communities (default: nil)
  • :raw - If true, returns a Result with node indices instead of labels.

walktrap_hierarchical(map, opts \\ [])

Hierarchical Walktrap community detection.

weakly_connected_components(map, opts \\ [])

@spec weakly_connected_components(
  t(),
  keyword()
) :: [[Zog.SoA.label()]] | [non_neg_integer()]

Finds weakly connected components in the ResourceGraph natively. Returns a list of lists of node labels.

Options

  • :raw - If true, returns a list of component IDs directly corresponding to internal u32 node IDs instead of grouping and mapping to Elixir labels.

yen_k_shortest(map, start_label, goal_label, k, opts \\ [])

@spec yen_k_shortest(t(), Zog.SoA.label(), Zog.SoA.label(), pos_integer(), keyword()) ::
  {:ok, [{[Zog.SoA.label()], float()}]} | {:error, :no_path}

Computes the k shortest loopless paths and their weights between two nodes using Yen's algorithm directly on the native graph resource.