Take a copy of a dynamic array that stays the same when the original changes or is resized.
Hardware context: High-throughput monitor-to-scoreboard transaction storage. Freeze a value-array snapshot of a hardware transaction before the monitor reuses its buffer.
A monitor saved each sample by keeping a reference to its live capture buffer. When the buffer was reused for the next transaction, every saved sample changed with it, and the scoreboard compared new data with new data.
Write freeze_values(source, frozen). source is passed by reference, so you see the live buffer. Make frozen an independent copy: the same length and the same values, which must not change when the monitor later writes to source or resizes it. Do not change source.
For source = [11, -4, 99], frozen becomes [11, -4, 99]. If the monitor then writes 700 into source[1] and grows source to 5 words, frozen still holds -4 at position 1 and still has 3 words.
Signals in the timeline
| Signal | Width | Role |
|---|---|---|
source_words | 256 | input of each check |
count | 32 | input of each check |
mutation_index | 32 | input of each check |
replacement | 32 | input of each check |
next_count | 32 | input of each check |
selected | 32 | input of each check |
Full specification
function automatic void freeze_values(ref int source[], output int frozen[]);
source has 0 to 8 signed words. After your call the fixture may write one word of source and resizes source to 0 to 8 words, keeping its first words.
Each case reports the size of frozen and of source after those changes, and one selected word of each (0 when the position does not exist).
Examples
Example 1
The buffer is reused- Input
source = [11, -4, 99]; then source[1] = 700 and source grows to 5; selected word 1
- Output
snapshot_size = 3, source_size = 5, snapshot_word = -4, source_word = 700
The snapshot still holds -4 and 3 words; the live buffer holds 700 and 5 words.
Example 2
The buffer shrinks- Input
same capture; then source shrinks to 1 word; selected word 2
- Output
snapshot_size = 3, source_size = 1, snapshot_word = 99, source_word = 0
The snapshot keeps 99 at position 2. The live buffer has no position 2, so its word reads 0.
Example 3
An empty snapshot- Input
source = []; then source grows to 3; selected word 0
- Output
snapshot_size = 0, source_size = 3, snapshot_word = 0, source_word = 0
The snapshot stays empty while the live buffer grows.
Constraints and contract
- Words are signed and must be copied bit for bit, including the most negative value.
- source must be left exactly as it was.
- Keep the signature.
Hints
Hint 1
What does assigning one dynamic array to another copy: the elements, or a way to reach the same elements?
Hint 2
An empty source is legal; your copy is then empty too.
Hint 3
One assignment is enough. Ask yourself why the ref on source does not make frozen share it.
What this judge verifies: Your function is run on 0 to 8 signed words, followed by every write position and resize of the live buffer. Passing shows the snapshot stays independent on these inputs.
651 checks on Verilator · local server. Run the examples first, then check the full regression. The suite is local and inspectable. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 5 steps and the final capstone