Dynamic Array & Queue Operations

Problem Description
Implement a class PacketBuffer that behaves like a FIFO buffer using a dynamic array.
Inside the class, use:
logic [7:0] data[];❗ Do NOT use queues ([$]). The goal is to practice dynamic array resizing.
📌 Functions to Implement
Function | Input | Return | Description |
|---|---|---|---|
|
| void | Add value at the end |
| — |
| Remove & return first element. Warn the user and return 0 if empty. |
| — | int | Return the number of elements |
|
| int | Return index of first match, -1 if not found |
⚙️ Behavior Rules
Use FIFO order:
First pushed → first popped
push()
Increase the array size by 1 using
new[]Insert value at the last index
pop()
Return
data[0]Shift remaining elements left
Reduce array size by 1
Empty pop case
$display("WARNING: pop on empty buffer"); return 8'h00;find_val()
Traverse from index
0Return first matching index
Return
-1if not found
🧠 Example
push(AA) → {AA}
push(BB) → {AA, BB}
push(CC) → {AA, BB, CC}
pop() → AA → {BB, CC}
pop() → BB → {CC}⚠️ Constraints
Use only dynamic arrays
Do NOT use queues or shortcuts
SystemVerilog
Code Editor Access
Log in to write, run and submit your solution to this interview question. It's free.
