examples/

directory
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT

README

GoGraph examples

This directory contains 25 runnable, self-documenting demonstrations of GoGraph — from a five-line shortest-path query to a persistent, kill -9-safe REST service. Each example is a standalone package main with its own README.md, and each is pinned by a regression test so the output you see below is guaranteed by CI, not just illustrative.

Run any example with:

go run ./examples/<NN_name>

For the conventions every example follows — testable extraction, a regression test, and the per-example README.md template — see ../docs/examples-standard.md.

Basics

Example What it demonstrates Run
01_basic Build a weighted directed graph, freeze it into an immutable CSR snapshot, and run single-source search.Dijkstra, reading back both distances and reconstructed routes. go run ./examples/01_basic
02_property_graph Build a labelled property graph with an optional schema, run label- and property-indexed MATCH-style queries, and read typed properties back out. go run ./examples/02_property_graph
03_advanced_algorithms Run four algorithms over one CSR snapshot — BFS, Dijkstra, exact Brandes betweenness centrality (with printed ranks), and PageRank. go run ./examples/03_advanced_algorithms

Persistence and out-of-core

Example What it demonstrates Run
04_persistence The full durability path: WAL-committed transactions, a v2 snapshot (CSR + labels + properties), then rebuild from disk with recovery.Open. go run ./examples/04_persistence
05_out_of_core Tier 2 external memory: persist a CSR snapshot as a csrfile, re-open it by mmap, and run semi-external PageRank over the mapped adjacency. go run ./examples/05_out_of_core
17_transactional_log WAL-backed store with a background checkpointer that folds the log into a self-sufficient snapshot, plus recovery after a simulated crash. go run ./examples/17_transactional_log
18_oocore_pipeline The full out-of-core pipeline: CSV → CSR → csrfilemmap, then semi-external BFS and PageRank over the mapped region. go run ./examples/18_oocore_pipeline
21_typed_recovery Generic recovery.Open[N, W] over an (int64, float64) graph: round-trip edges (bit-exact float weights), labels, and typed properties through a v2 snapshot. go run ./examples/21_typed_recovery

Cypher and Bolt

Example What it demonstrates Run
22_cypher The Cypher engine over a small social graph: a label scan with projection and ORDER BY, a WHERE filter, a relationship pattern, and a CREATE in a write transaction — every value printed in human-readable form. go run ./examples/22_cypher
23_bolt_server Bolt v5 end to end: start the embedded server, connect the official neo4j-go-driver/v5 as a real client, run a Cypher query over a session, and shut down cleanly with no goroutine leak. go run ./examples/23_bolt_server
24_social_network_cli A one-shot CLI over a persistent LPG social network, walking every layer: LPG, WAL + recovery, manual checkpoints, and Cypher reads streamed as JSON Lines. go run ./examples/24_social_network_cli
25_software_house_api A persistent, kill -9-safe REST API (stdlib only) over a multi-layer LPG spanning Code/Work/People, answering change-impact, ownership, and bus-factor questions in Cypher. go run ./examples/25_software_house_api

Interchange

Example What it demonstrates Run
06_csv_import The serialisation round-trip: read an edge-list CSV with csv.ReadInto, then write the graph back out as CSV and as newline-delimited JSON (JSON Lines). go run ./examples/06_csv_import
07_graphml_roundtrip Graph interchange I/O: parse a GraphML document with graphml.ReadInto, then serialise it back out to GraphML and Graphviz DOT, edges and weights intact. go run ./examples/07_graphml_roundtrip

Algorithms

Example What it demonstrates Run
08_pagerank PageRank over a directed authority web (peripheral pages → an authority → a hub), reading back the per-node rank vector ordered most- to least-important with distinct ranks. go run ./examples/08_pagerank
09_leiden Modularity-optimising community detection with community.Leiden over two K4 cliques joined by a single bridge edge. go run ./examples/09_leiden
10_dimacs9_routing Build a deterministic synthetic road network with the DIMACS 9 harness, then run a concrete search.Dijkstra query that reconstructs the shortest route from node 0 to node 11. go run ./examples/10_dimacs9_routing
14_routing_alternatives Three shortest-path flavours over one routing graph: Dijkstra, Yen's k-shortest paths, and search.AStar driven by a coordinate-based Euclidean heuristic that expands fewer nodes for the same optimal cost. go run ./examples/14_routing_alternatives
15_task_assignment Two bipartite assignment algorithms side by side: search.Hungarian (cheapest one-to-one assignment) and search.HopcroftKarp (largest matching once edges are pruned). go run ./examples/15_task_assignment
16_centrality_analytics Two analytics over one CSR snapshot: exact Brandes betweenness centrality and label-propagation community detection, with deterministic tie-breaking. go run ./examples/16_centrality_analytics

Real-world recipes

Example What it demonstrates Run
11_social_network An end-to-end social-network workload over an LPG: PageRank influence ranking, Leiden community detection, and a manual friend-of-friend recommendation walk. go run ./examples/11_social_network
12_build_dependency Model a build-dependency graph, derive a valid build order with search.TopologicalSort (Kahn), and detect a circular dependency with search.TarjanSCC. go run ./examples/12_build_dependency
13_network_reliability Two resilience analyses over one network: single points of failure (articulation points and bridges) and the max throughput plus its limiting min-cut bottleneck, with the flow network derived from the same edge list. go run ./examples/13_network_reliability
19_pattern_query The fluent graph/query API: MATCH-style pattern queries combining label and property predicates with a one-hop expansion, reading matched properties back out. go run ./examples/19_pattern_query
20_concurrent_reads The lock-free read contract of a frozen CSR: Dijkstra, BFS, and PageRank run concurrently over one shared immutable snapshot with zero synchronisation on the snapshot. go run ./examples/20_concurrent_reads

Directories

Path Synopsis
Example 01_basic — build a small weighted directed graph, snapshot it to a CSR view, and run a single-source shortest-paths query.
Example 01_basic — build a small weighted directed graph, snapshot it to a CSR view, and run a single-source shortest-paths query.
Example 02_property_graph — build a small labelled property graph, declare a schema, attach labels and typed properties, then run a MATCH-style indexed query and read the typed properties back.
Example 02_property_graph — build a small labelled property graph, declare a schema, attach labels and typed properties, then run a MATCH-style indexed query and read the typed properties back.
Example 03_advanced_algorithms — exercises BFS, Dijkstra, Brandes betweenness centrality, and PageRank on one small undirected graph.
Example 03_advanced_algorithms — exercises BFS, Dijkstra, Brandes betweenness centrality, and PageRank on one small undirected graph.
Example 04_persistence — opens a WAL, performs a few transactions that include both node and edge labels, attaches typed properties directly on the in-memory graph, then takes a v2 snapshot (CSR + labels.bin + properties.bin) and demonstrates that labels and typed properties survive a restart.
Example 04_persistence — opens a WAL, performs a few transactions that include both node and edge labels, attaches typed properties directly on the in-memory graph, then takes a v2 snapshot (CSR + labels.bin + properties.bin) and demonstrates that labels and typed properties survive a restart.
Example 05_out_of_core — writes a Tier 2 csrfile, opens it via mmap, applies a SEQUENTIAL access hint, and runs PageRank directly over the mapped region, then verifies the result against the graph's symmetry.
Example 05_out_of_core — writes a Tier 2 csrfile, opens it via mmap, applies a SEQUENTIAL access hint, and runs PageRank directly over the mapped region, then verifies the result against the graph's symmetry.
Example 06_csv_import — reads an edge-list CSV, builds the adjacency list, then writes it out as both CSV and JSON Lines.
Example 06_csv_import — reads an edge-list CSV, builds the adjacency list, then writes it out as both CSV and JSON Lines.
Example 07_graphml_roundtrip — reads a GraphML document, prints the number of ingested edges, then writes the graph back out to both GraphML and DOT.
Example 07_graphml_roundtrip — reads a GraphML document, prints the number of ingested edges, then writes the graph back out to both GraphML and DOT.
Example 08_pagerank — runs PageRank on a small directed "authority" graph and prints each page's rank, sorted from most to least important.
Example 08_pagerank — runs PageRank on a small directed "authority" graph and prints each page's rank, sorted from most to least important.
Example 09_leiden — runs Leiden community detection on two K4 cliques joined by a single bridge edge and prints the discovered communities.
Example 09_leiden — runs Leiden community detection on two K4 cliques joined by a single bridge edge and prints the discovered communities.
Example 10_dimacs9_routing — build a small synthetic road-network graph with the DIMACS 9 harness, run a concrete single-source shortest-paths query over it, and print an environment-dependent latency summary from the harness for flavour.
Example 10_dimacs9_routing — build a small synthetic road-network graph with the DIMACS 9 harness, run a concrete single-source shortest-paths query over it, and print an environment-dependent latency summary from the harness for flavour.
Example 11_social_network — a small social-network application showing how to:
Example 11_social_network — a small social-network application showing how to:
Example 12_build_dependency — model a software build dependency graph, derive the build order via topological sort, and detect circular dependencies with Tarjan SCC.
Example 12_build_dependency — model a software build dependency graph, derive the build order via topological sort, and detect circular dependencies with Tarjan SCC.
Example 13_network_reliability — analyse the resilience of a single communication backbone two ways over ONE coherent network:
Example 13_network_reliability — analyse the resilience of a single communication backbone two ways over ONE coherent network:
Example 14_routing_alternatives — compare three flavours of shortest-path computation on the same routing graph: classical Dijkstra, Yen's k-shortest for alternatives, and A* with a coordinate-based Euclidean heuristic.
Example 14_routing_alternatives — compare three flavours of shortest-path computation on the same routing graph: classical Dijkstra, Yen's k-shortest for alternatives, and A* with a coordinate-based Euclidean heuristic.
Example 15_task_assignment — staff four workers onto four tasks two ways and compare the results: the Hungarian algorithm computes the globally cheapest one-to-one assignment, while Hopcroft-Karp computes the largest matching that respects a "willing to take" business rule.
Example 15_task_assignment — staff four workers onto four tasks two ways and compare the results: the Hungarian algorithm computes the globally cheapest one-to-one assignment, while Hopcroft-Karp computes the largest matching that respects a "willing to take" business rule.
Example 16_centrality_analytics — analyse a small undirected network with two centrality metrics: Brandes betweenness (structural importance via shortest paths) and label propagation (cluster membership).
Example 16_centrality_analytics — analyse a small undirected network with two centrality metrics: Brandes betweenness (structural importance via shortest paths) and label propagation (cluster membership).
Example 17_transactional_log — end-to-end durability walk-through with an ACID-safe background checkpointer.
Example 17_transactional_log — end-to-end durability walk-through with an ACID-safe background checkpointer.
Example 18_oocore_pipeline — out-of-core ingestion pipeline.
Example 18_oocore_pipeline — out-of-core ingestion pipeline.
Example 19_pattern_query — build a labelled property graph with a declared schema, populate it, then run several MATCH-style queries combining label and property predicates plus a one-hop expansion.
Example 19_pattern_query — build a labelled property graph with a declared schema, populate it, then run several MATCH-style queries combining label and property predicates plus a one-hop expansion.
Example 20_concurrent_reads — run three different read-only graph algorithms concurrently over one shared, immutable CSR snapshot.
Example 20_concurrent_reads — run three different read-only graph algorithms concurrently over one shared, immutable CSR snapshot.
Example 21_typed_recovery — demonstrates the canonical typed recovery API `recovery.Open[N, W]` against a non-string graph.
Example 21_typed_recovery — demonstrates the canonical typed recovery API `recovery.Open[N, W]` against a non-string graph.
Example 22_cypher — the GoGraph Cypher engine, the module's flagship (100% openCypher TCK compliant at the execution level).
Example 22_cypher — the GoGraph Cypher engine, the module's flagship (100% openCypher TCK compliant at the execution level).
Example 23_bolt_server starts a GoGraph Bolt v5 server backed by an in-memory labelled property graph, then drives a full client round-trip against it with the official neo4j-go-driver/v5.
Example 23_bolt_server starts a GoGraph Bolt v5 server backed by an in-memory labelled property graph, then drives a full client round-trip against it with the official neo4j-go-driver/v5.
Package main implements `24_social_network_cli`, an example one-shot CLI that demonstrates how to build, persist and query a labelled property graph for a social-network domain using GoGraph.
Package main implements `24_social_network_cli`, an example one-shot CLI that demonstrates how to build, persist and query a labelled property graph for a social-network domain using GoGraph.
Command 25_software_house_api is a persistent REST WebAPI that demonstrates how to build, query and mutate a multi-layer Labeled Property Graph (LPG) with GoGraph in a production-shaped service.
Command 25_software_house_api is a persistent REST WebAPI that demonstrates how to build, query and mutate a multi-layer Labeled Property Graph (LPG) with GoGraph in a production-shaped service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL