FIFO Queue

It's not similar, it's identical. A FIFO queue isn't a data structure, it's a description of behavior. There are various ways to implement that behavior. Array can be used as a FIFO queue, but you add the further constraints that you want O(1) time complexity for push/pop, which disqualifies Array.

Two data structures that match your description are a resizing ring buffer like this one, or a linked list (whose performance is usually hot garbage, don't use these 99% of the time).

If you want to enforce the FIFO nature of it, then I suggest you make a Queue protocol, whose only methods are push() and pop(), then you can extend SwiftNIO's CircularBuffer to conform.

Though yeah, I really wish such basic batteries were included in the standard library.

3 Likes