Roy Want / Mbed OS beaconCompileReadyFork
Embed: (wiki syntax)

« Back to documentation index

PriorityQueue< T, Capacity > Class Template Reference

PriorityQueue< T, Capacity > Class Template Reference

Priority queue of Ts. More...

#include <PriorityQueue.h>

Data Structures

class  Iterator
 Iterator for elements of the queue. More...
struct  Node
 Type of the nodes in this queue. More...

Public Member Functions

 PriorityQueue ()
 Construct an empty priority queue.
 PriorityQueue (const PriorityQueue &other)
 Copy construct a priority queue.
 ~PriorityQueue ()
 destroy a priority queue.
PriorityQueueoperator= (const PriorityQueue &other)
 Copy assignemnent from another priority queue.
iterator push (const T &element)
 Push a new element to the queue.
bool pop ()
 pop the head of the queue.
void update (iterator it)
 If the content of an element is updated is updated after the insertion then, the list can be in an unordered state.
iterator begin ()
 return an iterator to the begining of the queue.
iterator end ()
 return an iterator to the end of the queue.
bool erase (iterator it)
 erase an iterator from the list
bool erase (Node *n)
 erase a node from the list
bool empty () const
 Indicate if the queue is empty or not.
bool full () const
 Indicate if the true is full or not.
std::size_t size () const
 Indicate the number of elements in the queue.
std::size_t capacity () const
 Expose the capacity of the queue in terms of number of elements the queue can hold.
void clear ()
 Clear the queue from all its elements.

Detailed Description

template<typename T, std::size_t Capacity>
class eq::PriorityQueue< T, Capacity >

Priority queue of Ts.

Ts are ordered from the smaller to the bigger ( < ). Elements in the queue are mutable (this is a design choice). After a mutation the function update should be called to ensure that the queue is still properly sorted.

Template Parameters:
Ttype of elements in this queue
Parameters:
capacityNumber of elements that this queue can contain

Definition at line 35 of file PriorityQueue.h.


Constructor & Destructor Documentation

Construct an empty priority queue.

Definition at line 119 of file PriorityQueue.h.

PriorityQueue ( const PriorityQueue< T, Capacity > &  other )

Copy construct a priority queue.

The queue will have the same content has other.

Definition at line 125 of file PriorityQueue.h.

~PriorityQueue (  )

destroy a priority queue.

Definition at line 132 of file PriorityQueue.h.


Member Function Documentation

iterator begin (  )

return an iterator to the begining of the queue.

Definition at line 267 of file PriorityQueue.h.

std::size_t capacity (  ) const

Expose the capacity of the queue in terms of number of elements the queue can hold.

Returns:
the capacity of the queue.
Invariant:
this function should always return Capacity.

Definition at line 340 of file PriorityQueue.h.

void clear (  )

Clear the queue from all its elements.

Definition at line 347 of file PriorityQueue.h.

bool empty (  ) const

Indicate if the queue is empty or not.

Returns:
true if the queue is empty and false otherwise.
Invariant:
the queue remains untouched.

Definition at line 312 of file PriorityQueue.h.

iterator end (  )

return an iterator to the end of the queue.

Note:
can't be dereferenced

Definition at line 273 of file PriorityQueue.h.

bool erase ( Node n )

erase a node from the list

Definition at line 283 of file PriorityQueue.h.

bool erase ( iterator  it )

erase an iterator from the list

Definition at line 278 of file PriorityQueue.h.

bool full (  ) const

Indicate if the true is full or not.

Returns:
true if the queue is full and false otherwise.
Invariant:
the queue remains untouched.

Definition at line 321 of file PriorityQueue.h.

PriorityQueue& operator= ( const PriorityQueue< T, Capacity > &  other )

Copy assignemnent from another priority queue.

The content of the queue will be destroyed then the content from other will be copied.

Definition at line 139 of file PriorityQueue.h.

bool pop (  )

pop the head of the queue.

Definition at line 188 of file PriorityQueue.h.

iterator push ( const T &  element )

Push a new element to the queue.

It will be added before the first element p in the queue where element < p == true.

Returns:
An iterator to the inserted element.

Definition at line 151 of file PriorityQueue.h.

std::size_t size (  ) const

Indicate the number of elements in the queue.

Returns:
the number of elements currently held by the queue.
Invariant:
the queue remains untouched.

Definition at line 330 of file PriorityQueue.h.

void update ( iterator  it )

If the content of an element is updated is updated after the insertion then, the list can be in an unordered state.

This function help; it update the position of an iterator in the list.

Definition at line 205 of file PriorityQueue.h.