Version 4 of queue

Updated 2004-12-10 18:24:54 by SEH

Documentation can be found at http://tcllib.sourceforge.net/doc/queue.html .

This module of the tcllib data structures collection provides the data structure portion of a queue.

See Stacks and Queues for a description about what a queue is.


SEH 10 Dec 04 -- I have found out to my regret that it is not really possible to use [queue] in loop structures, because the "peek" and "get" commands acts differently when the queue size is 1 than when it is any number > 1.

It would be nice to be able to do something like:

 foreach item [$queue peek [$queue size]] {<do stuff>}

but if [$queue size] is 1, then the value is returned as a string value, whereas if it's 2, the values are returned as a list. So you can't use the above construction unless you know all queue values will look the same as strings or lists. For example:

 %set q [struct::queue]
 %$q put "a b"
 %foreach item [$q peek [$q size]] {puts $item}
 a
 b
 %$q put "c d"
 %foreach item [$q peek [$q size]] {puts $item}
 a b
 c d

This behavior is documented and hence not actually a bug, but as a practical matter it makes the [queue] structure useless to me.


[ Arts and Crafts of Tcl-Tk Programming | Category Command, package tcllib, module struct | Category Data Structure | ]