QUE. - Queue

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures >

QUE. - Queue

 

The QUE.-Commands

Overview

The **QUE.-Commands** provide a powerful set of tools for creating, managing, and manipulating queues. A queue is a **First-In-First-Out (FIFO)** data structure, meaning the first element added to the queue is the first one to be removed. Queues are ideal for managing ordered data, such as task scheduling, buffering, or processing sequences.

 

A **handle** is a unique identifier that references a specific queue. It is generated when a queue is created using QUE.New and is used to interact with the queue in subsequent commands. Handles are essential for managing multiple queues simultaneously. Once a queue is deallocated using QUE.End or QUE.EndAll, its handle becomes invalid.

 


 

Key Concepts

What is a Queue?

A queue is a linear data structure that stores elements in a specific order. It follows the **First-In-First-Out (FIFO)** principle, meaning:

The first element added to the queue is the first one to be removed.

Elements are added to the **end (rear)** of the queue and removed from the **front (head)**.

Queues are commonly used for:

Task scheduling (e.g., processing tasks in the order they are received).

Buffering data (e.g., holding data temporarily before processing).

Managing sequences of operations or events.

 

What is a Handle?

A **handle** is a unique identifier that references a specific queue. It is generated when a queue is created using QUE.New and is used to interact with the queue in subsequent commands. Handles are essential for managing multiple queues simultaneously. Once a queue is deallocated using QUE.End or QUE.EndAll, its handle becomes invalid.

 


 

Example Scripts

 

Example 1: Basic Queue Operations

 

'***********************************

' QUE.-Commands Sample 1: Basic Operations

'***********************************

QUE.New|$$QUE

DBP.New queue created with this Handle: $$QUE

 

' Add elements to the queue

QUE.Push|$$QUE|42

QUE.Push|$$QUE|"Hello"

QUE.Push|$$QUE|3.14

 

' Check the number of elements in the queue

QUE.Count|$$QUE|$$COUNT

DBP.Number of elements in queue: $$COUNT

 

' Retrieve and remove the first element

QUE.Pop|$$QUE|$$VAL

DBP.Value popped from queue: $$VAL

 

' Retrieve the first element without removing it

QUE.Peek|$$QUE|$$VAL

DBP.First value in queue (after pop): $$VAL

 

' Clear the queue

QUE.Clear|$$QUE

DBP.Queue cleared.

 

' Deallocate the queue

QUE.End|$$QUE

DBP.Queue deallocated.

ENR.

 

Example 2: Working with Multiple Queues

 

'***********************************

' QUE.-Commands Sample 2: Multiple Queues

'***********************************

' Create an integer queue

QUE.New|$$QUE_INT|i

QUE.Push|$$QUE_INT|10

QUE.Push|$$QUE_INT|20

 

' Create a floating-point queue

QUE.New|$$QUE_FP|f

QUE.Push|$$QUE_FP|1.5

QUE.Push|$$QUE_FP|2.7

 

' Create a string queue

QUE.New|$$QUE_STR

QUE.Push|$$QUE_STR|"First"

QUE.Push|$$QUE_STR|"Second"

 

' Retrieve and display elements from each queue

QUE.Pop|$$QUE_INT|$$VAL

DBP.Popped from integer queue: $$VAL

 

QUE.Pop|$$QUE_FP|$$VAL

DBP.Popped from floating-point queue: $$VAL

 

QUE.Pop|$$QUE_STR|$$VAL

DBP.Popped from string queue: $$VAL

 

' Deallocate all queues

QUE.EndAll

DBP.All queues deallocated.

ENR.

 

Example 3: Validating and Checking Queue Type

 

'***********************************

' QUE.-Commands Sample 3: Validation and Type Checking

'***********************************

QUE.New|$$QUE|i

QUE.Push|$$QUE|42

 

' Validate the queue handle

QUE.Validate|$$QUE|$$RES

DBP.Queue validation result: $$RES

 

' Check the queue type

QUE.GetType|$$QUE|$$TYPE

DBP.Type of queue: $$TYPE (Expected: 1 - Integer)

 

' Deallocate the queue

QUE.End|$$QUE

DBP.Queue deallocated.

ENR.

 

Example 4: Using QUE.Delete

 

'***********************************

' QUE.-Commands Sample 4: Deleting Elements

'***********************************

QUE.New|$$QUE

QUE.Push|$$QUE|"First"

QUE.Push|$$QUE|"Second"

QUE.Push|$$QUE|"Third"

 

' Delete the first element

QUE.Delete|$$QUE

 

' Retrieve the new first element

QUE.Peek|$$QUE|$$VAL

DBP.First value after deletion: $$VAL

 

' Deallocate the queue

QUE.End|$$QUE

DBP.Queue deallocated.

ENR.

 

Example 5: Clearing and Reusing a Queue

 

'***********************************

' QUE.-Commands Sample 5: Clearing and Reusing

'***********************************

QUE.New|$$QUE

QUE.Push|$$QUE|"Old1"

QUE.Push|$$QUE|"Old2"

 

' Clear the queue

QUE.Clear|$$QUE

DBP.Queue cleared.

 

' Add new elements

QUE.Push|$$QUE|"New1"

QUE.Push|$$QUE|"New2"

 

' Retrieve and display the first element

QUE.Peek|$$QUE|$$VAL

DBP.First value after reuse: $$VAL

 

' Deallocate the queue

QUE.End|$$QUE

DBP.Queue deallocated.

ENR.

 

Example 6: Using QUE.EndAll

 

'***********************************

' QUE.-Commands Sample 6: Deallocating All Queues

'***********************************

QUE.New|$$QUE1

QUE.Push|$$QUE1|"Data1"

QUE.New|$$QUE2

QUE.Push|$$QUE2|"Data2"

 

' Deallocate all queues

QUE.EndAll

DBP.All queues deallocated.

ENR.

 

Summary

The **QUE.-Commands** provide a robust and flexible way to work with queues in your scripts. Whether you're managing task schedules, buffering data, or processing sequences, these commands enable you to efficiently manipulate queue data. Use the examples above as a starting point for integrating queues into your workflows.