All problems
Hazard Pointer Retire Count
Problem
Count how many retired nodes a hazard-pointer scheme can free.
hazards is a list of per-thread hazard pages (None entries are ignored) and retires is a list of [node_id, page] pairs. A retired node is deferred while any thread holds its page as a hazard, and is freed otherwise.
Return [freed_count, deferred_count].
Hint
Any thread holding the page as a hazard defers reclamation of that node.
Test cases
case 1
in: [[[1,null],[2,null]],[[10,1],[11,1],[12,2],[13,3]]]
expected: [1,3]
case 2
in: [[[null]],[[1,5]]]
expected: [1,0]
case 3
in: [[[7]],[[1,7],[2,7]]]
expected: [0,2]
case 4
in: [[[],[]],[]]
expected: [0,0]
Starter codePython
def hazard_retire_count(hazards, retires):
# Your code here
pass4 test cases · run your code against them in the editor