struct::prioqueue(3tcl)
π struct::prioqueue β the manual, but make it cute β¨
ok so bestie, welcome to struct::prioqueue, a page straight out of Tcl Data Structures. grab a boba, we're building priority queues πΈ
π NAME π
struct::prioqueue β create and manipulate prioqueue objects. that's it, that's the job π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require struct::prioqueue ?1.5?
::struct::prioqueue ?-ascii|-dictionary|-integer|-real? ?prioqueueName?
prioqueueName option ?arg arg ...?
prioqueueName clear
prioqueueName remove item
prioqueueName destroy
prioqueueName get ?count?
prioqueueName peek ?count?
prioqueueName peekpriority ?count?
prioqueueName put item prio ?item prio ...?
prioqueueName size
π DESCRIPTION π
okay so this package implements a simple priority queue using nested tcl lists. no cap, that's the whole storage strategy π
the command ::struct::prioqueue creates a brand new priority queue with the default priority key type -integer. what that means for you: keys you hand over to the put subcommand must have that type. it's giving strict but fair β¨
this is also what sets your priority ordering, so pay attention bestie:
- for key types
-asciiand-dictionarythe data is sorted in ascending order (exactly likelsort -increasing) π± - for
-integerand-realthe data is sorted in descending order (exactly likelsort -decreasing) π₯
prioqueue names are unrestricted, but heads up: they may be recognized as options if no priority type is given. lowkey a little trap, iykyk π
π the commands, one by one
::struct::prioqueue?-ascii|-dictionary|-integer|-real??prioqueueName?β this creates a new prioqueue object with an associated global Tcl command whose name is prioqueueName. that command is your main character, it's how you invoke all the various operations on the prioqueue. its general form is:
prioqueueName option ?arg arg ...?
prioqueueName option ?arg arg ...?β option and the args decide the exact behavior of the command. for prioqueue objects, the possible commands are the ones listed below πprioqueueName clearβ remove all items from the prioqueue. total clean slate, so satisfying π§prioqueueName remove itemβ remove the selected item from this priority queue. bye bestie πprioqueueName destroyβ destroy the prioqueue, including its storage space and its associated command. it's gone gone πprioqueueName get ?count?β return the front count items of the prioqueue (but not their priorities) and remove them from the prioqueue. if count isn't specified it defaults to1. if count is1, the result is a simple string; otherwise it's a list. if you do specify it, count must be greater than or equal to1. and if there are no items or too few items in the prioqueue, this command will throw an error π so check your size first fr fr.prioqueueName peek ?count?β return the front count items of the prioqueue (but not their priorities), without removing them from the prioqueue. look, don't touch π. if count isn't specified it defaults to1. if count is1, the result is a simple string; otherwise it's a list. if specified, count must be greater than or equal to1. and yeah, if there are no items or too few items in the queue, this command will throw an error.prioqueueName peekpriority ?count?β return the front count items' priority keys, without removing them from the prioqueue. same deal: count defaults to1; count of1gives you a simple string, otherwise a list; if specified it must be greater than or equal to1; and if there are no items or too few items in the queue, this command will throw an error πΈprioqueueName put item prio ?item prio ...?β put the item or items you specify into the prioqueue. prio must be a valid priority key for this type of prioqueue, otherwise an error is thrown and no item is added. items get inserted at their priority ranking, and items with equal priority are added in the order they were added (fifo energy, we love to see it) π«ΆprioqueueName sizeβ return the number of items in the prioqueue. the receipts π
π¦ BUGS, IDEAS, FEEDBACK π¦
ngl bestie, this document and the package it describes will undoubtedly contain bugs and other problems. it's giving humble.
please report such in the category struct :: prioqueue of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. please also report any ideas for enhancements you may have for either the package and/or the documentation π
when proposing code changes, please provide unified diffs, i.e. the output of diff -u. keep it clean β¨
note further that attachments are strongly preferred over inlined patches. attachments can be made 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. no cap, that's the whole workflow π
π₯ KEYWORDS π₯
ordered list, prioqueue, priority queue
β CATEGORY β
Data structures
π COPYRIGHT π
Copyright (c) 2003 Michael Schlenker <mic42@users.sourceforge.net>
okay that's the whole page, and yes, this little icon of a manual comes from tcllib, version 1.5 β the struct::prioqueue(3tcl) era, iconic behavior only π thanks for reading bestie, now go sort something π
β¨
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2003 Michael Schlenker <mic42@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms