Repository navigation
Refuse a copied random list that loops back - #430
Conversation
098e27f to
aa17a99
Compare
|
Already rebased onto main. |
jserv
left a comment
There was a problem hiding this comment.
Remove AI attribution from Git commit messages, as it does not help collaboration.
Every random-list serializer stopped at the first revisited node, so a deep copy whose last node links back to the first printed as the acyclic list it loops over, and the exact checker accepted it in C++, Java, JavaScript and Python. C walked the ring until its 10000-node buffer filled and failed without saying why. Report the revisit with the message the plain list serializers already use; the seen set stays so serialization still terminates.
aa17a99 to
4ed1a15
Compare
|
I removed the AI attribution from the commit message. |
You don't have to leave messages like the above as Git always tracks changes. |
43379d0 to
04d26aa
Compare
|
@papaya0112 Both points from the last review hold at 04d26aa: the cycle check runs after the |
04d26aa to
1f5ff3f
Compare
The C random-list serializer printed a shallow copy's refusal as the answer itself and put a stray random pointer's refusal inside the array, so neither case carried an error and C showed a wrong answer with no reason, while C++ and Java throw both. Check every random pointer before the opening bracket and report both refusals through the error field, as the cycle check now does. The cycle check runs after the deep-copy walk, so a shallow copy that also loops is refused as a shallow copy, the same answer the other four give.
The cyclic-copy and stray-copy tests repeated the compile-and-run steps of the flatten tests, with their own compiler flags and timeout. Give that helper the judge id as a parameter so every harness test builds and bounds its run in one place. The stray-copy comment also claimed JavaScript and Python throw a stray random pointer, which they do not until sysprog21#372 lands.
1f5ff3f to
7874eb5
Compare
|
The sentence "JavaScript and Python follow once #372 lands, which closes #364" contains a closing keyword, so GitHub lists #364 among this PR's closing references, and merging this first would close #364 before the JavaScript and Python fix in #372 exists. Please reword it so only |
ColtenOuO
left a comment
There was a problem hiding this comment.
Changes of the code are looking good to me.
A skipped gates lane passed as green, an approval survived the push after it, and resolving an outdated thread raised a grade nobody had earned, as sysprog21#430 showed. The sweep now grades those, names everyone a PR waits on, and lists stacked prerequisites and PR pairs that change the same base lines. The review of a low or blocked PR rechecks its outdated threads, and its findings go out as one review, so the author gets one notification instead of one per finding.
|
Thank @papaya0112 for contributing! |
A deep copy whose last node links back to the first copy passed Outline Snapshot Duplicator (copy-list-with-random-pointer) in C++, Java, JavaScript and Python, and failed in C with no reason given.
Root cause:
checkAnswercompares only the serialized value, so the serializer is the only code that sees the returned structure. The random-list serializers (randomListToJson,randomListJson,randomListToArray,_random_list_to_array) kept aseenset for termination but treated a revisit as the end of the list, so a ring was cut at its first repeated node and printed exactly as a correct copy. #405 fixed this for theListNodeserializers; the random list uses the separateNodetype and its own serializers, which kept the old loop from the initial import. A judge case cannot catch it, because an expected value in JSON cannot describe a cycle.C differed because
json_random_listhad noseenset, only a 10000-node buffer cap: on the ring it printed 10000 entries per non-empty case with random indices pointing at late repeats, and noerrorfield, so the candidate saw a wrong answer without a reason.This change reports a revisit as an error in all five serializers with the message #405 already uses, "Returned list must not reach a node twice.", and keeps the
seenset so serialization still terminates. C gets the same Floyd check asjson_list, run after the deep-copy walk, which is capped at 10000 nodes, so a ring of copies is walked to that cap before the check refuses it. Correct copies and the empty case are unaffected.The regression test compiles and runs the cyclic copy against the judge in C, C++ and Java and expects that message on every non-empty case; it fails on main and passes with this change. JavaScript and Python get the same source check #405 added for the plain list serializers.
The C serializer also printed its two existing refusals where the answer goes: a shallow copy's "Returned list must be a deep copy." became the
actualvalue, and a stray random pointer's "Returned random pointer must stay inside the copied list." landed inside the array, so both failed with no reason. It now checks every random pointer before the opening[and reports both throughnull,"error":, as the cycle check does, which lines C up with C++ and Java; the JavaScript and Python half of #364 stays with #372.json_graphhas the same pattern and is left for a separate change.Closes #417
Summary by cubic
Fixes the random-list serializers so a deep copy whose last node links back to the first is rejected instead of being accepted as a correct acyclic list.
Returned list must not reach a node twice.on a revisit, matching the existing plain-list behavior.Written for commit 7874eb5. Summary will update on new commits.