"""Priority Queue Container Class"""

# Importing shuffle to use later.
from random import shuffle

class PriorityQueue:
    # Creates a container which takes on a (k, v)
    # pair for each object within the container.
    
    def __init__(self, queue=[]):
        # Initialises variable (required for class).
        self.__queue = queue
    
    def len(self):
        # Returns no of objects in container.
        total = 0
        for item in self.__queue:
            total += 1
        return(total)

    def is_empty(self):
        # Returns boolean TRUE if container is empty,
        # otherwise FALSE
        if self.__queue == []:
            return True
        else:
            return False

    def add(self, k, v):
        # Adds an object to PriorityQueue.
        add_item = (k, v)
        self.__queue.append(add_item)

    def min(self):
        # Returns the object with minimum key.
        PriorityQueue.shuffle_sort(self)
        return self.__queue[0]

    def shuffle_sort(self):
        # Helper function to shuffle sort the
        # PriorityQueue.
        shuffle(self.__queue)
        self.__queue.sort(key = lambda x: x[0])

    def remove_min(self):
        # Removes the object according to minimum key.
        PriorityQueue.shuffle_sort(self)
        purged = self.__queue[0]
        self.__queue.pop(0)
        return purged

