-
-
Notifications
You must be signed in to change notification settings - Fork 3k
std: add a Deque data structure #24968
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
base: master
Are you sure you want to change the base?
Conversation
const result, const overflow = @addWithOverflow(a, b); | ||
if (overflow != 0) return error.OutOfMemory; | ||
return result; |
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 can be simplified to
return std.math.add(usize, a, b) catch error.OutOfMemory;
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.
Not sure I agree that adding more abstraction would be simpler here
Added a more comprehensive test that can also be used for fuzzing. Also added |
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.
give it a spin:
|
Came back with fresh eyes and managed to de-obfuscate my |
Will do! |
And delete DeprecatedLinearFifo from the source tree.
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.