# mlpy.auxiliary.datastructs.PriorityQueue¶

class `mlpy.auxiliary.datastructs.``PriorityQueue`(func=<function <lambda>>)[source]

The priority queue.

In a priority queue each element has a priority associated with it. An element with high priority (i.e., smallest value) is served before an element with low priority (i.e., largest value). The priority queue is implemented with a heap.

Parameters: func : callable A callback function handling the priority. By default the priority is the value of the element.

Examples

```>>> q = PriorityQueue()
>>> q.push(5)
>>> q.extend([1, 3, 7])
>>> print q
[(1,1), (5,5), (3,3), (7,7)]
```

Retrieving the element with highest priority:

```>>> q.pop()
1
```

Removing an element:

```>>> q.remove((3, 3))
>>> print q
[(5,5), (7,7)]
```

Get the element in the queue identical to the given item:

```>>> q.get(7)
7
```

Check if the queue is empty:

```>>> q.empty()
False
```

Loop over the elements in the queue:

```>>> for x in q:
>>>     print x
(5, 5)
(7, 7)
```

Check if an element is in the queue:

```>>> if 7 in q:
>>>     print "yes"
yes
```

Methods

 `empty`() Check if the queue is empty. `extend`(items) Extend the queue by a number of elements. `get`(item) Return the element in the queue identical to item. `pop`() Get the element with the highest priority. `push`(item) Push an element on the priority queue. `remove`(item) Remove an element from the queue.