struct::queue(n)
π struct::queue(n) β Tcl Data Structures π
okay bestie, sit down, we're doing queues today and honestly? iconic behavior.
β¨ NAME β¨
struct::queue β Create and manipulate queue objects π
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require struct::queue ?1.4.6?
queueName option ?arg arg ...?
queueName clear
queueName destroy
queueName get ?count?
queueName peek ?count?
queueName put item ?item ...?
queueName unget item
queueName size
π¦ DESCRIPTION π¦
So the ::struct namespace is basically the home base for a whole pile of commands that process finite queues. It exports exactly one single command, ::struct::queue, and every single bit of functionality you could ever want lives as a subcommand of that one command. one command, all the power, main character energy fr fr π
Note: as of version1.4.1of this package there's a critcl based C implementation available. The catch? That implementation needs Tcl8.4to run. iykyk.
The ::struct::queue command makes you a brand new queue object, and it comes with a global Tcl command attached to it whose name is queueName. You use that command to run all the various operations on the queue. Its general shape is:
queueName option ?arg arg ...?
The option plus the args decide exactly what the command does. These are the commands you can use on queue objects:
queueName clearβ yeet every single item out of the queue. gone. empty. clean slate bestie π§ΉqueueName destroyβ destroy the whole queue, and that means its storage space and its associated command too. like, the entire thing. πqueueName get ?count?β returns the front count items of the queue and removes them from the queue (so they're gone from the queue, gone gone). If you don't pass count, it defaults to1. If count is1, the result is a simple string; otherwise it's a list. If you do pass it, count has to be greater than or equal to1. And if the queue doesn't have enough items to fulfill your request? it throws an error, no cap πqueueName peek ?count?β returns the front count items of the queue but without removing them. so it's giving "look but don't touch" β¨ If count isn't specified it defaults to1. If count is1, you get a simple string; otherwise a list. If you specify it, count must be greater than or equal to1. Not enough items in the queue to fulfill the request? error. same energy asget, just with the items staying put.queueName put item ?item ...?β puts the item (or items, plural, we love a group chat) into the queue. If you hand it more than one item, they get added in the order you listed them. first come, first served πqueueName unget itemβ puts item into the queue at the front, i.e. before any other items already chillin' in there. this makes it the literal complement to the methodget. put it back where you found it queen π«ΆqueueName sizeβ returns the number of items in the queue. that's it. that's the whole vibe check. π’
π BUGS, IDEAS, FEEDBACK π
ngl, this document and the package it describes will undoubtedly contain bugs and other problems. it's giving "we know". Please report such in the category struct :: queue of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist.
Also please report any ideas for enhancements you may have for either the package and/or the documentation. we love a glow-up suggestion π
When proposing code changes, please provide unified diffs, i.e. the output of diff -u. periodt.
Note further: attachments are strongly preferred over inlined patches. You make an attachment by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. lowkey a little scavenger hunt but you got this π
β KEYWORDS β
graph, list, matrix, pool, prioqueue, record, set, skiplist, stack, tree
π CATEGORY π
Data structures
and that's the whole page bestie π this doc shipped as part of tcllib, version 1.4.6, and it's filed under struct::queue(n). go build a queue, you're gonna slay π
β¨π¦
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms