Developer first

API reference

The small public surface for creating a matcher, applying updates, inspecting state, and asserting the invariant.

Constructor

This page covers the Basic and Multilevel Matcher API. For thread-safe durable integration and its current qualification status, see Service, durability and qualification. Compact native Packed storage is not a separate matcher.

Matcher(n: int, mode: "basic" | "multilevel")
ArgumentMeaning
nNumber of vertices. Vertices are integers in [0, n).
modeExactly basic or multilevel.

Updates

MethodBehavior
insert(u, v)Adds an existing or new graph edge and repairs the matching.
delete(u, v)Removes an existing graph edge and repairs any affected matching state.

Update semantics

  • insert(u, v) ignores a duplicate edge after validating its endpoints.
  • delete(u, v) records a missing-edge deletion without changing the graph.
  • Self-loops are outside the graph model and do not become matching edges.
  • A failed update is atomic: callers do not receive a partially applied state.

Inspection

matcher.matching()  # matching edge snapshot
matcher.size()      # number of matching edges
matcher.maximal()   # invariant check
matcher.stats()     # update and rebuild ledger

Inspection methods are read-only from the caller’s perspective. Treat returned collections as snapshots and continue to mutate the graph through insert and delete.

MethodReturnsUseCost
partner(v)int | NoneReturn the matched neighbor or None.O(1)
partners()dict[int, int]Return a copy of the full partner map.O(|M*|)
matching()set[Edge]Return a copy of the current matching.O(|M*|)
size()intReturn the number of matching edges.O(1)
maximal()boolCheck the matching against the current graph.O(n + m)
stats()dict[str, int]Return counters and active schedule values.O(1)

stats() schema

KeyMeaning
n, mVertex and live-edge counts at the time of the snapshot.
matching_sizeNumber of edges in the maintained maximal matching.
updates_since_rebuildUpdates applied since the active phase rebuild.
phase_length, subphase_lengthConfigured rebuild and seed-maintenance boundaries.
subphase_countNumber of subphase maintenance events completed.
zActive saturation threshold for the current mode.
total_updates, total_insertions, total_deletionsCumulative accepted update counters.
phase_rebuilds, subphase_rebuildsCumulative phase and subphase maintenance counts.
rematch_*_scans, stale_cleanupsEmpirical work counters for rematching and removed matching edges.

Validation and failure

Invalid vertices, malformed edges, and unsupported modes are rejected explicitly. Duplicate insertions and missing deletions follow the documented no-op semantics. A failed update must not expose a partially applied graph or matching state.

ConditionResult
Invalid n, vertex, mode, graph, or colorerValueError before state changes.
Duplicate insertion, missing deletion, or self-loop updateValidated no-op; the graph and matching remain unchanged.
Internal repair or invariant failureRuntimeError after atomic rollback; inspect the diagnostic and preserve the input trace.

For reproducible experiments, record the mode, vertex count, update sequence, and stats() ledger alongside your result.

Custom implementations and concurrency

The optional graph and basic-mode colorer parameters are extension points for compatible implementations. A custom graph must preserve the graph protocol and edge-set semantics; a multilevel matcher always uses its canonical paper-oriented colorer.

Thread safety: a matcher is stateful and is not designed for concurrent mutation. Serialize updates per instance. Use independent matcher instances for parallel experiments.

NextRun examples