Overview
Add a new command to the module: PQUEUE.PUSH. It should accept three arguments: key, priority, and value. If the per-key queue (heap) does not exist yet, create it. Insert the value into the heap with the given priority and return the current size of that queue after the insertion.
Command signature
PQUEUE.PUSH
Behavior
Per-key queues are independent. Each key maps to its own priority queue.
Priority is numeric. Higher numbers denote higher priority. The heap should present the highest priority item first.
If multiple items share the same priority, preserve insertion order (stable behavior). Implement this by associating a monotonically increasing tiebreaker with each pushed item.
The function should return the size of the queue for the given key after the push (an integer).
Data structures
A map/dictionary: queues: map<string, Heap>
Each PQItem stores: priority (numeric), value (string), and an insertion_index (monotonic counter).
Implementation notes
Integrate with the project’s existing command-dispatch mechanism. Add a handler for PQUEUE.PUSH that updates the queues map accordingly.
If the key is new, initialize an empty heap for it.
Push the new item and then return the current size of that heap.
Use a max-heap semantics. If your underlying heap is a min-heap, invert the comparison or store negative priorities.
Edge cases
Priority values are parsed as numbers; report/propagate type errors if invalid.
Value may contain spaces; ensure parsing preserves the entire string payload.
If the key exists but is not a heap, report a suitable error or reinitialize as a new heap depending on project conventions.
Testing guidance
Add unit tests to cover:
Creating a new key and pushing once returns size 1.
Pushing with different priorities updates size correctly.
Equal priorities preserve insertion order.
Pushing to an existing key does not affect other keys’ queues.
Validate return type is an integer and equals the heap size after push.
Deliverables
A patch implementing PQUEUE.PUSH as described.
Unit tests for the new command.
A quick in-repo README note documenting the tie-breaker rule (stable order for equal priorities).