In Python, we can use collections.deque to implement FIFO queue operations. For example:
from collections import deque
queue = deque([1, 2, 3])
print("Initial queue:", queue) # Output: deque([1, 2, 3])
first_element = queue.popleft()
print("Popped element:", first_element) # Output: 1
print("Current queue:", queue) # Output: deque([2, 3])
The code implement the following functionality:
- Create a queue and initialize with elements
- Remove/return the first element (FIFO)
- Check the current queue state
I would like to know how to implement similar queue functionality in DolphinDB. I tried using vectors with the following approach:
queue = [1, 2, 3]
firstElement = queue[0] // Attempt to pop the first element
queue = erase(queue, 0) // Attempt to delete element at index 0
However this trigger an error:
Syntax Error: [line #3] Cannot recognize the token erase
The DolphinDB document( https://docs.dolphindb.com/en/Functions/e/erase!.html ) mentions erase, but I am encountering syntax errors.
What is the correct way to implement a FIFO queue in DolphinDB?
Is there a built-in queue structure?
If not, how can I simulate
popleft()andappend()operations?
Thanks in advance for your help!