Accept reordered neighbors in C graph clones

Merged
JI
1d ago
+193-17

Correct C graph clones could fail exact comparison when their neighbor arrays used a different order from the expected adjacency list. The C serializer now sorts temporary copies of neighbor IDs, preserving the candidate's graph and the original-node rejection check.

The regression tests cover original, reversed, partially reversed and rotated neighbor orders, including a node with three neighbors. They also compile and run a solution that returns the input graph and require rejection of every nonempty case.

Validation on Windows 11, over 4faffce:

  • node --test --test-name-pattern="C Clone Graph" tests/browser/compiler-explorer.test.js: 5 passed, 0 failed and 0 skipped on Windows using local cc, as confirmed by the contributor's output. This covers original, reversed, partially reversed and rotated neighbor orders, plus rejection of the original graph.
  • An earlier before/after comparison using a temporary local MSVC adapter showed that the three reordered-neighbor tests fail with the original serializer and all five graph tests pass with the fix. The adapter is not part of this PR.
  • git diff --check passes.
  • Manual validation reported by the contributor: C compilation and execution succeeded in the CodeTrial UI.

Additional local checks run by the contributor:

  • npx prettier --check web/compiler-explorer.js tests/browser/compiler-explorer.test.js
  • npx eslint web/compiler-explorer.js tests/browser/compiler-explorer.test.js
  • ./scripts/test.sh

./scripts/test.sh is not green on this Windows machine. Failing gate touch non of these files


Summary by cubic

Fixes the C Clone Graph judge rejecting valid deep copies when neighbor order differs, and now also rejects NULL neighbors in C and C++ graph clones so malformed answers get a diagnostic instead of crashing the harness.

The C serializer now sorts neighbor IDs before comparison, and both C and C++ graph serializers detect and reject NULL neighbors during traversal.

Tests:

  • Cover original, reversed, partially reversed, and rotated neighbor orders, including a degree-three node.
  • Verify every nonempty case is rejected when the input graph is returned unchanged, and that NULL neighbors are reported for root and non-root nodes.

Updated 20261022

Correct C graph clones could fail exact comparison when their neighbor arrays used a different order from the expected adjacency list. The C serializer now sorts temporary copies of neighbor IDs, preserving the candidate's graph and the original-node rejection check.

Both C and C++ graph serializers now reject NULL neighbor slots during traversal, before dereferencing them or generating adjacency rows. An incomplete clone receives a per-case diagnostic while subsequent cases continue to run.

The native regression tests cover original, reversed, partially reversed and rotated C neighbor orders, reversed C++ neighbors, and a node with three neighbors. They also reject returned original C nodes and exercise NULL slots on both root and reachable non-root nodes in C and C++.

Validation:

  • node --test --test-timeout=30000 --test-name-pattern="Clone Graph" tests/browser/compiler-explorer.test.js: 10 passed, 0 failed and 0 skipped on Windows using local cc and g++.
  • ./scripts/test.sh browser: 1,022 passed, 0 failed and 320 skipped because Chromium or Java was unavailable; the lane exited successfully.
  • Before/after native checks reproduced crashes for NULL slots on root and reachable non-root nodes in both C and C++; the guarded versions pass. An earlier MSVC comparison also confirmed that three reordered-neighbor tests fail before C neighbor normalization.
  • Prettier and ESLint pass for both changed files.
  • git diff --check passes.
  • Manual validation reported by the contributor: C++ compilation and execution succeeded in the CodeTrial UI.

Closes #360