Dynamic Array & Queue Operations

Qualcomm

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

push

logic [7:0] val

void

Add value at the end

pop

—

logic [7:0]

Remove & return first element. Warn the user and return 0 if empty.

get_size

—

int

Return the number of elements

find_val

logic [7:0] val

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 0

    • Return first matching index

    • Return -1 if 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.

Output

Output goes here...