dequeue Reference
Module defined in `lua/common/dequeue.lua`. Double-ended queue (deque) implementation supporting push/pop from both ends, rotation, removal, and iteration. Based on Pierre Chapuis's library.
Module defined in lua/common/dequeue.lua. Double-ended queue (deque) implementation supporting push/pop from both ends, rotation, removal, and iteration. Based on Pierre Chapuis's library.
Exports
Functions
dequeue.new(data)
Creates a new deque, optionally from existing serialized data.
- Parameters:
data- table|nil - Optional table with existing data andhead/tailindices for deserialization
- Returns: table - A deque object
Instance Methods
deque:push_right(x)
Pushes an element to the right (tail) end. Asserts x is not nil.
- Parameters:
x- any (non-nil) - Element to push
deque:push_left(x)
Pushes an element to the left (head) end. Asserts x is not nil.
- Parameters:
x- any (non-nil) - Element to push
deque:pop_right()
Removes and returns the rightmost element.
- Returns: any|nil - The element, or nil if empty
deque:pop_left()
Removes and returns the leftmost element.
- Returns: any|nil - The element, or nil if empty
deque:peek_right()
Returns the rightmost element without removing it.
- Returns: any|nil
deque:peek_left()
Returns the leftmost element without removing it.
- Returns: any|nil
deque:rotate_right(n)
Rotates the deque right by n positions (moves tail elements to head).
- Parameters:
n- number|nil - Positions to rotate (default: 1)
deque:rotate_left(n)
Rotates the deque left by n positions (moves head elements to tail).
- Parameters:
n- number|nil - Positions to rotate (default: 1)
deque:remove_right(x)
Removes the first occurrence of x searching from the right.
- Parameters:
x- any - Value to find and remove - Returns: boolean - True if found and removed
deque:remove_left(x)
Removes the first occurrence of x searching from the left.
- Parameters:
x- any - Value to find and remove - Returns: boolean - True if found and removed
deque:length()
- Returns: number - Number of elements
deque:is_empty()
- Returns: boolean - True if no elements
deque:contents()
- Returns: table - Array of all elements from left to right
deque:iter_right()
- Returns: function - Iterator yielding elements from right to left
deque:iter_left()
- Returns: function - Iterator yielding elements from left to right
deque:reset()
Empties the deque.
Internal Notes
- Internal representation uses
headandtailindices - elements stored at integer keys in the table itself _serialize = trueflag enables serialization support- Supports deserialization: pass existing data table to
new()to restore state
delayLine Reference
Module defined in `lua/common/delayLine.lua`. Implements a time-based delay buffer for queuing data packets that arrive at one end and exit after a fixed time delay. Originally designed for simulating
devUtils Reference
Module defined in `lua/common/devUtils.lua`. Development utilities for sandboxed Lua execution, module local variable introspection, global state snapshots, and table recursion detection.