Skip to content

std: Make std.PriorityQueue and std.PriorityDequeue unmanaged containers (change has landed, PR can be closed)#25559

Open
saurabh-mish wants to merge 22 commits intoziglang:masterfrom
saurabh-mish:unmanaged-priority-queue-and-dequeue
Open

std: Make std.PriorityQueue and std.PriorityDequeue unmanaged containers (change has landed, PR can be closed)#25559
saurabh-mish wants to merge 22 commits intoziglang:masterfrom
saurabh-mish:unmanaged-priority-queue-and-dequeue

Conversation

@saurabh-mish
Copy link
Contributor

@saurabh-mish saurabh-mish commented Oct 13, 2025

#23431 had been dormant for a while.

This PR revives #21433 and resolves #21432.

@rohlem
Copy link
Contributor

rohlem commented Oct 13, 2025

Unrelated to these changes, but it seems theres'a typo in the doc comment:
PriorityDeque says Order.gt if the third argument should be min-popped second,
while Queue says Order.gt if the third argument should be min-popped first.
From my understanding PriorityQueue is consistent here, the error for Deque was made in 22e1d92, but not in corresponding 82e8930.

(The wording is a bit clunky imo, I'd personally just replace the last part with "otherwise", or drop it since it's logically implied - but up to you or maintainers to decide.)

@saurabh-mish
Copy link
Contributor Author

saurabh-mish commented Oct 13, 2025

Summary of changes

Priority Dequeue

std.PriorityDequeue has method signatures similar to std.Deque

  • Moved methods removeMinOrNull into removeMin and removeMaxOrNull into removeMax; updated tests.

  • Renamed methods add, removeMin and removeMax to push, popMin and popMax repectively.

  • Added new method isEmpty which returns true if the priority dequeue is empty and false if not. It is being used in addUnchecked, peekMin, removeMin, and removeMax.

Moved Priority Dequeue into Priority Deque

Priority Queue

std.PriorityQueue has method signatures similar to std.PriorityDequeue

  • Moved method removeOrNull into remove and updated corresponding tests.

  • Renamed methods add to push and remove to pop.

  • Added new method isEmpty method which returns true if the priority queue is empty and false if not. It is being used in peek and pop methods.

  • Renamed the cap field to capacity (as present in ArrayList) and renamed the capacity method to getCapacity

TODO (this part will be edited based on progress, feedback, and observation)

  • Add / improve doc comments
    • PriorityQueue
    • PriorityDeque
  • Consistent fields: PriorityQueue has items, cap, and context, whereas PriorityDeque has items, len, context
    • Was struggling with this to be honest. If this is indeed an issue, I think it is beyond the scope of this PR.
  • .empty value
    • PriorityQueue
    • PriorityDeque

@linux-user36
Copy link

Since there's already deque.zig, should this maybe be renamed to PriorityDeque for consistency?

@saurabh-mish
Copy link
Contributor Author

Since there's already deque.zig, should this maybe be renamed to PriorityDeque for consistency?

I think so too, pushing PriorityDeque related changes shortly

…st) and `capacity` method to `getCapacity`
@saurabh-mish
Copy link
Contributor Author

This PR is ready for review (updated the summary of changes).

@saurabh-mish saurabh-mish marked this pull request as ready for review October 13, 2025 19:43
@saurabh-mish saurabh-mish changed the title std: Make std.PriorityQueue and std.PriorityDequeue unmanaged containers std: Make std.PriorityQueue and std.PriorityDequeue unmanaged containers (change has landed, PR can be closed) Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a PriorityQueueUnmanaged type to the standard library

5 participants