How it works
Append an element to the tail of a FIFO queue in constant time.
Implementation
function queueEnqueueOp(state, value) { const values = state.values; const tail = values.length; probeSlot(tail); values[tail] = value; enqueueValue(tail, value); finish(tail - state.head + 1); }
def queueEnqueueOp(state, value): values = state.values tail = values.length probeSlot(tail) values[tail] = value enqueueValue(tail, value) finish(((tail - state.head) + 1))
#include <vector> #include <algorithm> void queueEnqueueOp(int state, int value) { auto values = state.values; auto tail = values.length; probeSlot(tail); values[tail] = value; enqueueValue(tail, value); finish(((tail - state.head) + 1)); }
public void queueEnqueueOp(int state, int value) { var values = state.values; var tail = values.length; probeSlot(tail); values[tail] = value; enqueueValue(tail, value); finish(((tail - state.head) + 1)); }
#include <stdio.h> void queueEnqueueOp(int state, int value) { var values = state.values; var tail = values.length; probeSlot(tail); values[tail] = value; enqueueValue(tail, value); finish(((tail - state.head) + 1)); }