Loading...
Searching...
No Matches
PriorityQueue.h
Go to the documentation of this file.
// -*- c++ -*-
//------------------------------------------------------------------------------
// PriorityQueue.h
//------------------------------------------------------------------------------
// Copyright (c) 1999 by Vladislav Grinchenko
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//------------------------------------------------------------------------------
#ifndef PRIORITY_QUEUE_H
#define PRIORITY_QUEUE_H
#include <unistd.h>
#include <limits.h>
#include "assa/Assure.h"
#include "assa/PriorityQueue_Impl.h"
#include "assa/PriorityQueue_Heap.h"
namespace ASSA {
template<class T, class Compare> class PriorityQueue_Impl;
template<class T, class Compare >
class PriorityQueue
{
public:
PriorityQueue (size_t max_ = 20);
PriorityQueue (size_t max_, const Compare&);
virtual ~PriorityQueue ();
virtual void insert (const T&);
virtual T pop ();
virtual const T& top () const;
virtual bool remove (T&);
virtual size_t size ();
virtual T& operator[] (int);
virtual void setHeapImpl (size_t, const Compare&);
protected:
const PriorityQueue_Impl<T, Compare>* getPriorityQueueImpl () const;
Compare m_comp;
PriorityQueue (const PriorityQueue&);
PriorityQueue& operator= (const PriorityQueue&);
private:
PriorityQueue_Impl< T, Compare >* m_impl;
};
//----------------------------------------------------------------------------
// Member functions
//----------------------------------------------------------------------------
template <class T, class Compare>
inline
PriorityQueue<T, Compare>::
PriorityQueue (size_t maxsz_)
: m_impl (0)
{
// This is a perfect place for using Factory to decide which
// implementation to use
// const char self[]="PriorityQueue::PriorityQueue(maxsz)"; trace();
setHeapImpl (maxsz_, m_comp);
}
template <class T, class Compare>
inline
PriorityQueue<T, Compare>::
PriorityQueue (size_t maxsz_, const Compare& x_)
: m_comp (x_), m_impl (0)
{
// This is perfect place for using Factory to decide which
// implementation to use
setHeapImpl (maxsz_, m_comp);
}
template <class T, class Compare>
inline void
PriorityQueue<T, Compare>::
setHeapImpl (size_t maxsz_, const Compare& x_)
{
// Maybe here you would want to copy contents of the old
// implementation to the new one?
//
if (m_impl != 0)
delete m_impl;
m_impl = new PriorityQueue_Heap<T, Compare> (maxsz_, x_);
}
template <class T, class Compare>
inline
PriorityQueue<T, Compare>::
~PriorityQueue ()
{
delete m_impl;
}
template <class T, class Compare> void
inline
PriorityQueue<T, Compare>::
insert (const T& el_)
{
m_impl->insert (el_);
}
template <class T, class Compare> T
inline
PriorityQueue<T, Compare>::
pop ()
{
return m_impl->pop ();
}
template <class T, class Compare>
inline const T&
PriorityQueue<T, Compare>::
top () const
{
return m_impl->top ();
}
template <class T, class Compare>
inline bool
PriorityQueue<T, Compare>::
remove (T& t_)
{
return m_impl->remove (t_);
}
template <class T, class Compare>
inline size_t
PriorityQueue<T, Compare>::
size ()
{
return m_impl->size ();
}
template <class T, class Compare>
inline const PriorityQueue_Impl<T, Compare>*
PriorityQueue<T, Compare>::
getPriorityQueueImpl () const
{
return (const PriorityQueue_Impl<T, Compare>*) m_impl;
}
template <class T, class Compare>
inline T&
PriorityQueue<T, Compare>::
operator[] (int idx)
{
return (*m_impl)[idx];
}
} // end namespace ASSA
#endif /* PRIORITY_QUEUE_H */
Assure.h
A collection of assert function wrappers.
PriorityQueue_Heap.h
Heap-based implementation of PriorityQueue algorithm based on Robert Sedgewick's "Algorithms in C++",...
PriorityQueue_Impl.h
Interface class that defines Implementor of the Bridge pattern.
ASSA::PriorityQueue_Heap
Definition PriorityQueue_Heap.h:30
ASSA::PriorityQueue_Impl
Class PriorityQueue_Impl.
Definition PriorityQueue_Impl.h:54
ASSA::PriorityQueue::operator=
PriorityQueue & operator=(const PriorityQueue &)
ASSA::PriorityQueue::operator[]
virtual T & operator[](int)
Definition PriorityQueue.h:164
ASSA::PriorityQueue::PriorityQueue
PriorityQueue(size_t max_=20)
Definition PriorityQueue.h:69
ASSA::PriorityQueue::pop
virtual T pop()
Definition PriorityQueue.h:124
ASSA::PriorityQueue::~PriorityQueue
virtual ~PriorityQueue()
Definition PriorityQueue.h:108
ASSA::PriorityQueue::size
virtual size_t size()
Definition PriorityQueue.h:148
ASSA::PriorityQueue::PriorityQueue
PriorityQueue(const PriorityQueue &)
ASSA::PriorityQueue::insert
virtual void insert(const T &)
Definition PriorityQueue.h:116
ASSA::PriorityQueue::top
virtual const T & top() const
Definition PriorityQueue.h:132
ASSA::PriorityQueue::setHeapImpl
virtual void setHeapImpl(size_t, const Compare &)
Definition PriorityQueue.h:93
ASSA::PriorityQueue::getPriorityQueueImpl
const PriorityQueue_Impl< T, Compare > * getPriorityQueueImpl() const
Definition PriorityQueue.h:156
ASSA::PriorityQueue::remove
virtual bool remove(T &)
Definition PriorityQueue.h:140
ASSA::PriorityQueue::m_impl
PriorityQueue_Impl< T, Compare > * m_impl
Definition PriorityQueue.h:59
ASSA::PriorityQueue::m_comp
Compare m_comp
Definition PriorityQueue.h:53
ASSA
Definition Acceptor.h:40