i'm having a little trouble understanding how the CircularFifoQueue Class works. So for my requirements, i need a FIFO Queue of fixed Size (about 6000 Elements). At frist i was using the ArrayDequeue, but it was performing rather badly. Then i read about CircularFifoQueue and tried it out. I can see a boost in Performance, but it still isn't fast.
My Question is now: what happens if the Queue is full and i add an element? Is the whole underlying array copied? Is there some offset, that will be set, e.g.
head = (head + 1) % size;
If the latter is the case, then i guess my algorithm is performing poorly.
Thanks!
The docs says the following about insertion in a CircularFifoQueue
:
If the queue is full, the least recently added element is discarded so that a new element can be inserted.
When it comes to performance, it is to be noted that aside from the add
, remove
, peek
, poll
and offer
methods which performs in constant time, all methods of this data structure perform in linear time, or worse.