struct::queue(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– 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 version 1.4.1 of this package there's a critcl based C implementation available. The catch? That implementation needs Tcl 8.4 to 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 to 1. If count is 1, the result is a simple string; otherwise it's a list. If you do pass it, count has to be greater than or equal to 1. 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 to 1. If count is 1, you get a simple string; otherwise a list. If you specify it, count must be greater than or equal to 1. Not enough items in the queue to fulfill the request? error. same energy as get, 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 method get. 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