Documentation is at http://tcllib.sourceforge.net/doc/prioqueue.html
This part of the [struct] (data structures) submodule of [tcllib] provides a prioritized queue.
Simple usage example:
package require struct 1.3 # create a prioqueue with integer priorities set pq [::struct::prioqueue -integer] # get some random things an put them in the queue for {set i 0} {$i < 100} {incr i} { $pq put item$i [expr {int(rand()*500)}] } # Iterate over the queue and output the items in priority order # To process the whole queue in one step better use: # foreach item [$pq get [$pq size]] { ... } while {[$pq size]} { puts stdout [$pq get] } # destroy the queue after use $pq destroy
Ken: Is there a way to change the priority to only retrieve the smallest number in the queue instead of the largest number
schlenk: Not by default. If you really need it, its a small code change.
Ken: Ok its a small code change, but which proc should i edit it? any hints?
RS Looks like this should be sufficient:
set pq [::struct::prioqueue] lset struct::prioqueue::sortdir 0 1
This way you don't edit the Tcllib source yourself, but override the default for -integer. However, this applies globally for all prioqueues from that time on.
Ken: Cheers
Stacks and queues also has a prioqueue.
Category Package; see struct - Tcllib | Category Data Structure