Hardware interview practice
Find an associative-array value without a sentinel
A reference model stores int values at byte keys, and every byte value including 8'hFF is legal. Return a success flag separately from the first key whose value matches a target.
Starting point
Question code
int mem[byte];
function bit find_value(input int target, output byte key);Reviewed example
Work through one case
Input
mem = '{8'hFF: 3}, target = 3Expected output
success = 1, key = 8'hFFThe all-ones key remains representable because success is carried independently rather than encoded as an impossible byte value.
What to cover
Requirements
- Return failure cleanly for an empty associative array.
- Visit each existing key at most once using first() and next().
- Return the first matching key in associative index order.
- Use the function result as the success indicator instead of reserving a key as a sentinel.
