Skip to main content

wl_hash

Function wl_hash 

Source
pub fn wl_hash(
    graph: &Graph,
    labels: Option<&[u32]>,
    max_iterations: u32,
) -> IgraphResult<WlHashResult>
Expand description

Compute the Weisfeiler-Lehman hash of a graph.

Uses 1-WL (color refinement): each vertex starts with an initial color derived from its label (or degree if no labels provided), then iteratively updates its color by hashing the sorted multiset of neighbor colors together with its own color.

§Parameters

  • graph — The input graph.
  • labels — Optional initial vertex labels. If None, vertex degrees are used as initial colors.
  • max_iterations — Maximum number of WL iterations. The algorithm stops early if the coloring stabilizes (no new colors created).

§Returns

A WlHashResult containing per-vertex hashes, the graph-level hash, and the number of iterations performed.

§Examples

use rust_igraph::{Graph, wl_hash};

// Two triangles — same WL hash
let g1 = Graph::from_edges(&[(0,1),(1,2),(2,0)], false, Some(3)).unwrap();
let g2 = Graph::from_edges(&[(0,1),(1,2),(2,0)], false, Some(3)).unwrap();
let h1 = wl_hash(&g1, None, 5).unwrap();
let h2 = wl_hash(&g2, None, 5).unwrap();
assert_eq!(h1.graph_hash, h2.graph_hash);

// Triangle vs path — different WL hash
let g3 = Graph::from_edges(&[(0,1),(1,2)], false, Some(3)).unwrap();
let h3 = wl_hash(&g3, None, 5).unwrap();
assert_ne!(h1.graph_hash, h3.graph_hash);