Documentation
¶
Overview ¶
Example 07_graphml_roundtrip — a GraphML interchange round-trip over a realistic, seeded link graph.
It generates a directed link graph in memory (a miniature "web" of documents that cite one another), serialises it to GraphML, parses that GraphML back with graphml.ReadInto so the reader is genuinely exercised, and then re-serialises the parsed graph to both GraphML and Graphviz DOT. It reports the deterministic shape of the data and the round-trip invariant (node/edge counts and a weight checksum survive the trip) as bare fact lines, and the volatile interchange telemetry — bytes in/out per format, parse and serialise throughput, and Go heap — as "# "-prefixed lines.
Model ¶
(page)-[link {weight}]->(page) // a directed, weighted link graph
Pages are 12-character lowercase hex ids drawn from the seeded RNG. The graph is grown by preferential attachment: page i links to a small number of distinct earlier pages, with an earlier page chosen with probability proportional to the in-degree it has already accumulated. That yields a heavy-tailed in-degree distribution — a handful of "authority" pages collect most links — which is the realistic shape of a citation or hyperlink web and a more interesting interchange payload than a uniform-random graph. Every link carries a positive integer weight in [1, maxWeight], stored as the GraphML <data key="w"> long that graphml.ReadInto reads back and dot.Write renders as a label="..." edge attribute.
The graph is a simple directed graph (no self-loops, no parallel edges), so the GraphML reader — which collapses parallel edges and is directed when edgedefault is not "undirected" — re-materialises it edge-for-edge. That makes the round-trip exact: re-reading the written GraphML yields the same node count, the same edge count, and the same weight sum.
Scale ¶
Run with no flags, the example builds a small, deterministic default (a few hundred pages) that the regression test pins and that finishes in well under the short-test budget. Every dimension is a flag, so the same binary scales up to where parse/serialise throughput and the interchange byte footprint become observable:
go run ./examples/07_graphml_roundtrip -nodes 1000000 -edges 12 -seed 7
The deterministic facts are reproducible for a fixed -seed; only the telemetry (lines prefixed with "# ") varies between runs and machines. At the default scale the example does not dump the GraphML or DOT documents to stdout — it serialises to in-memory buffers and reports their byte sizes — but the -sample flag prints the first few lines of each serialised format for a quick visual check.