Program Listing for File TreePriorityQueue.h

↰ Return to documentation for file (ADS/priority/TreePriorityQueue.h)

/*--------------------------------------------------------------------------*/
/*------------------------ File TreePriorityQueue.h ------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef __ADS_TreePriorityQueue
 #define __ADS_TreePriorityQueue
                      /* self-identification: #endif constant */

/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/

#include "ADS/Contract.h"
#include "ADS/Iterators.h"
#include "ADS/priority/PriorityQueue.h"
#include "ADS/tree/SearchTree.h"

#include <concepts>
#include <cstddef>
#include <utility>
#include <vector>

/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/

namespace ADS {

/*--------------------------------------------------------------------------*/
/*------------------------ CLASS TreePriorityQueue -------------------------*/
/*--------------------------------------------------------------------------*/

template< class T , std::totally_ordered P = int >
class TreePriorityQueue {

 using Key = std::pair< P , long >;

/*--------------------------------------------------------------------------*/
 public:

 using Item = T;
 using Priority = P;
 using Handle = long;

 [[nodiscard]] bool empty( void ) const;

 [[nodiscard]] int size( void ) const;

 [[nodiscard]] const T & min( void ) const;

 T deleteMin( void );

 Handle insert( const T & x , const P & p );

 void decrease( Handle y , const P & p );

/*------------------------- THE STANDARD INTERFACE -------------------------*/

 // a constant view of the pairs ( ( priority , number of insertion ) ,
 // item ) in increasing order of priority, bidirectional, those of the tree

 using value_type = typename RedBlackTree< Key , T >::value_type;
 using const_iterator = typename RedBlackTree< Key , T >::const_iterator;
 using iterator = const_iterator;

 [[nodiscard]] const_iterator begin( void ) const { return( f_t.begin() ); }
 [[nodiscard]] const_iterator end( void ) const { return( f_t.end() ); }
 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }

/*--------------------------------------------------------------------------*/
 private:

 [[nodiscard]] bool consistent( void ) const;

 RedBlackTree< Key , T > f_t;
 std::vector< P > f_p;

 };  // end( class TreePriorityQueue )

/*--------------------------------------------------------------------------*/

}  // end( namespace ADS )

/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/

#include "ADS/priority/impl/TreePriorityQueue.tpp"

/*--------------------------------------------------------------------------*/

#endif  /* TreePriorityQueue.h included */

/*--------------------------------------------------------------------------*/
/*---------------------- End File TreePriorityQueue.h ----------------------*/
/*--------------------------------------------------------------------------*/