<s> __author__ = """<STR_LIT>""" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from os import getcwd <EOL> from os import sys <EOL> sys . path . append ( getcwd ( ) ) <EOL> from MOAL . helpers . display import print_simple <EOL> from MOAL . helpers . display import Section <EOL> from MOAL . data_structures . abstract . queues import Queue <EOL> DEBUG = True if __name__ == '<STR_LIT:__main__>' else False <EOL> class PriorityQueue ( Queue ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( PriorityQueue , self ) . __init__ ( * args , ** kwargs ) <EOL> self . max_priority = <NUM_LIT:0> <EOL> def __str__ ( self ) : <EOL> print_simple ( '<STR_LIT>' , self . items ) <EOL> return '<STR_LIT>' <EOL> def enqueue ( self , item , priority = <NUM_LIT:0> ) : <EOL> item = { '<STR_LIT>' : priority , '<STR_LIT:data>' : item } <EOL> if priority > self . max_priority : <EOL> self . max_priority = priority <EOL> return super ( PriorityQueue , self ) . enqueue ( item ) <EOL> def pull_highest_priority_element ( self ) : <EOL> return self . get_priority ( self . max_priority ) <EOL> def get_priority ( self , level ) : <EOL> """<STR_LIT>""" <EOL> for k , el in enumerate ( self . items ) : <EOL> if el [ '<STR_LIT>' ] == level : <EOL> return self . items . pop ( k ) <EOL> return None <EOL> if DEBUG : <EOL> with Section ( '<STR_LIT>' ) : <EOL> pq = PriorityQueue ( ) <EOL> pq . enqueue ( '<STR_LIT>' , priority = <NUM_LIT:0> ) <EOL> pq . enqueue ( '<STR_LIT>' , priority = <NUM_LIT:4> ) <EOL> pq . enqueue ( '<STR_LIT>' , priority = <NUM_LIT:5> ) <EOL> pq . enqueue ( '<STR_LIT>' , priority = <NUM_LIT:3> ) <EOL> pq . enqueue ( '<STR_LIT>' , priority = <NUM_LIT:1> ) <EOL> pq . enqueue ( '<STR_LIT>' , priority = <NUM_LIT:2> ) <EOL> print ( pq ) <EOL> firstlen = len ( pq ) <EOL> item = pq . get_priority ( <NUM_LIT:4> ) <EOL> assert item [ '<STR_LIT:data>' ] == '<STR_LIT>' <EOL> item = pq . get_priority ( <NUM_LIT:0> ) <EOL> assert item [ '<STR_LIT:data>' ] == '<STR_LIT>' <EOL> item = pq . get_priority ( <NUM_LIT:10> ) <EOL> assert item is None <EOL> print ( pq ) <EOL> assert len ( pq ) < firstlen </s>
