Q297FreeSystemVerilog
Measure external fragmentation
Interview prompt
Question
Report total free capacity, the largest contiguous free block, and a defined external-fragmentation ratio.
Starting point
Question code
function void fragmentation_metrics(
output longint unsigned total_free,
output int unsigned largest_block,
output real external_ratio
);Reviewed example
Trace one case
Input
free=[[0,9],[20,24]]Expected output
total_free=15; largest_block=10; external_ratio=1-10/15=0.3333Inclusive sizes are 10 and 5, and the largest-to-total fraction is subtracted from one.
What to cover
Requirements
- Measure inclusive range sizes correctly.
- Return zeros for an empty free list.
- Define external_ratio as 1 minus largest_block divided by total_free.
- Avoid division by zero.

