-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.PriorityQueue: Convert to an 'unmanaged'-style API #21433
base: master
Are you sure you want to change the base?
Conversation
Resolves: ziglang#21432. Removed the allocator field from the PriorityQueue struct and adapted functions to take an allocator where needed. Updated tests accordingly.
Removed the allocator field from the PriorityDequeue struct and adapted functions to take an allocator where needed. Updated tests accordingly.
lib/std/priority_dequeue.zig
Outdated
pub fn deinit(self: Self) void { | ||
self.allocator.free(self.items); | ||
pub fn deinit(self: Self, allocator: std.mem.Allocator) void { | ||
if (self.items.len > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't strictly necessary since free
checks for 0-length slices but it still seemed odd to me to intentionally free something that was not a result of a call to alloc
so I added this check.
lib/std/priority_queue.zig
Outdated
pub fn deinit(self: Self) void { | ||
self.allocator.free(self.allocatedSlice()); | ||
pub fn deinit(self: Self, allocator: std.mem.Allocator) void { | ||
if (self.items.len > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't strictly necessary since free
checks for 0-length slices but it still seemed odd to me to intentionally free something that was not a result of a call to alloc
so I added this check.
I added back the I also noticed that what PriorityQueue was doing with the PriorityQueue and PriorityDequeue still have a
The latter I think matches the rest of the standard library more, though as a user I have sometimes found it a little odd that I need to access fields directly for this information rather than calling some consistent function. What do y'all think the best move would be here? |
This is probably motivated by what ArrayList does and I think people generally agree (myself included) that it's preferred over the alternative because it means that your |
Okay, I put it in its own commit so it's easy to undo. I'll undo it. |
…city" This reverts commit 42981fe.
Co-authored-by: Andrew Kelley <[email protected]>
Resolves: #21432.
Removed the allocator field from the PriorityQueue struct and adapted functions to take an allocator where needed.
Updated tests accordingly.
If these changes look good, I'll make corresponding changes to PriorityDequeue and include them in a follow-up patch.