File pqueue.icn |
########################################################################### File: pqueue.icn Subject: Class MaxPQueue, implementing a max-priority queue. Also see Steve Wampler's more general priority queue. Authors: Kostas Oikonomou Based on pqueue.icn in the IPL, by William S. Evans and Gregg M. Townsend. Date: September 15, 2004 ########################################################################### This file is in the public domain. ########################################################################### Methods: construct(S) returns a max-priority queue containing the elements in the structure (list, table, or set) S of "elem" records, each containing a "data" and a numeric "priority" field. get() removes and returns the highest priority element from the priority queue. put(e) adds element e (a "elem" record) to the queue. gen() generates (non-destructively) the elements of the queue in order, highest priority first. len() returns the number of elements in the queue. maxlen() returns the maximum length reached by the queue during its lifetime. elem(d, p) constructs a record with data d and priority p. ########################################################################### The priority queue is implemented as a max-heap. The heap is implemented by a list in the usual fashion. ###########################################################################
This file is part of the (main) package.
Source code.