Skip to content

Conversation

ifreund
Copy link
Member

@ifreund ifreund commented Aug 23, 2025

This is my penance for baiting andrew into deleting the existing generic queue data structures with my talk of "too many ring buffers".

The new Reader and Writer interfaces are excellent ring buffers for many use cases, but a generic queue container type is now missing.

This new double-ended queue, known more succinctly as a deque, is implemented from scratch based on the API design lessons learned from ArrayList over the years.

The API is not yet as featureful as ArrayList, but the core functionality is in place and I will be using this in my personal projects shortly. I think it makes sense to add further functions as needed based on real-world use-cases.

@ifreund ifreund requested a review from andrewrk August 23, 2025 13:48
Comment on lines +220 to +265
const result, const overflow = @addWithOverflow(a, b);
if (overflow != 0) return error.OutOfMemory;
return result;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to

    return std.math.add(usize, a, b) catch error.OutOfMemory;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I agree that adding more abstraction would be simpler here

@ifreund
Copy link
Member Author

ifreund commented Aug 24, 2025

Added a more comprehensive test that can also be used for fuzzing.

Also added .iterator(), .at(), .front() and .back() for a more complete starting point of this API.

This is my penance for baiting andrew into deleting the existing generic
queue data structures with my talk of "too many ring buffers".

The new Reader and Writer interfaces are excellent ring buffers for many
use cases, but a generic queue container type is now missing.

This new double-ended queue, known more succinctly as a deque, is
implemented from scratch based on the API design lessons learned from
ArrayList over the years.

The API is not yet as featureful as ArrayList, but the core
functionality is in place and I will be using this in my personal
projects shortly. I think it makes sense to add further functions as
needed based on real-world use-cases.
@andrewrk
Copy link
Member

give it a spin:

andy@bark ~/s/zig (master)> g DeprecatedLinearFifo src/
src/Compilation.zig:const DeprecatedLinearFifo = @import("deprecated.zig").LinearFifo;
src/Compilation.zig:]DeprecatedLinearFifo(Job),
src/Compilation.zig:c_object_work_queue: DeprecatedLinearFifo(*CObject),
src/Compilation.zig:win32_resource_work_queue: if (dev.env.supports(.win32_resource)) DeprecatedLinearFifo(*Win32Resource) else struct {

@ifreund
Copy link
Member Author

ifreund commented Aug 25, 2025

Came back with fresh eyes and managed to de-obfuscate my bufferIndex() implementation without adding any expensive division or overflow :)

@ifreund
Copy link
Member Author

ifreund commented Aug 25, 2025

give it a spin:

Will do!

And delete DeprecatedLinearFifo from the source tree.
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.

6 participants