nimnet/algorithms/graph_hashing

Weisfeiler-Lehman graph hashing.

WL hashing iteratively refines node labels based on neighborhood structure. It is widely used for graph classification, approximate isomorphism testing, and graph neural networks.

  • weisfeilerLehmanHash(g) — whole-graph WL hash
  • weisfeilerLehmanSubgraphHashes(g) — per-node WL hashes

Procs

proc weisfeilerLehmanHash[N](dg: DiGraph[N]; iterations = 3; digestSize = 16): string
Return the Weisfeiler-Lehman hash of a directed graph. Uses both in-degree and out-degree for initial labels, and distinguishes successor/predecessor neighborhoods.
proc weisfeilerLehmanHash[N](g: Graph[N]; iterations = 3; digestSize = 16): string

Return the Weisfeiler-Lehman hash of an undirected graph.

The hash is computed by iteratively refining node labels based on multi-set neighbor labels, then hashing the sorted final label multiset.

Parameters:

  • iterations: number of WL iterations (default 3)
  • digestSize: length of the hex hash string (default 16)
proc weisfeilerLehmanSubgraphHashes[N](g: Graph[N]; iterations = 3): Table[N,
    seq[string]]
Return per-node WL hashes at each iteration. Result maps each node to a sequence of hash strings (one per iteration).