Reservation-station Tag Match
Problem statement
Model tag matching in a reservation station. Each row of entries is [valid,entryTag], where valid1 means occupied and valid0 means unused. Given tag, return the smallest zero-based index whose row is valid and whose entryTag equals tag. Return -1 when there is no match.
For this exercise, a row has one tag only. Duplicate tags may occur, and the lowest matching index wins. This is a bounded tag-lookup model; it does not model instruction issue, operand wakeup or an entire out-of-order processor.
Function
matchingEntry(entries: int[][], tag: int) → intExamples
Example 1
entries = [[1,7],[0,7],[1,9]]tag = 7return = 0Entry0 is valid and has tag7. Entry1 is invalid, and entry2 has a different tag.
Example 2
entries = [[0,4],[1,5]]tag = 4return = -1The only row with tag4 is invalid, so no entry matches.
Example 3
entries = [[1,3],[1,3]]tag = 3return = 0Both rows match. The authored priority rule chooses the smallest index,0.
Constraints
0 <= entries.length <= 1000.Every entry has exactly 2 integers.Every entry value is from 0 to 1000000.Each entry is [valid, entryTag], where valid is 0 or 1.0 <= tag <= 1000000.