/*
 * Copyright (c) 1999 Johnny C. Lam.
 * All rights reserved.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  The author makes no representations
 * about the suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 */

#ifndef __SGI_STL_INTERNAL_DYNAMIC_PRIORITY_QUEUE_H
#define __SGI_STL_INTERNAL_DYNAMIC_PRIORITY_QUEUE_H

__STL_BEGIN_NAMESPACE

#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Priority, class T, class Compare = less<Priority> >
#else
template <class Priority, class T, class Compare>
#endif
class __dynamic_priority_compare {
public:
    typedef pair<Priority, T> value_type;
    inline bool	operator()(const value_type& lhs,const value_type& rhs) {
	return Compare()(lhs.first, rhs.first);
    }
};

#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Priority, class T, class PriorityCompare = less<Priority>,
	class Sequence = vector<pair<Priority, T> > >
#else
template <class Priority, class T, class PriorityCompare, Sequence>
#endif
class dynamic_priority_queue
    : public priority_queue<pair<Priority, T>, Sequence,
      __dynamic_priority_compare<Priority, T, PriorityCompare> > {
public:
    typedef Priority priority_type;
    typedef T data_type;
    typedef PriorityCompare priority_compare_type;
    typedef __dynamic_priority_compare<Priority, T, PriorityCompare> compare_type;

public:
    dynamic_priority_queue() {}

#ifdef __STL_MEMBER_TEMPLATES
    template <class InputIterator>
    dynamic_priority_queue(InputIterator first, InputIterator last,
			   const compare_type& x)
	: priority_queue<value_type, Sequence, compare_type>(first, last, x) {}
    template <class InputIterator>
    dynamic_priority_queue(InputIterator first, InputIterator last)
	: priority_queue<value_type, Sequence, compare_type>(first, last) {}
#else /* __STL_MEMBER_TEMPLATES */
    dynamic_priority_queue(const value_type* first, const value_type* last,
			   const compare_type& x)
	: priority_queue<value_type, Sequence, compare_type>(first, last, x) {}
    dynamic_priority_queue(const value_type* first, const value_type* last)
	: priority_queue<value_type, Sequence, compare_type>(first, last) {}
#endif /* __STL_MEMBER_TEMPLATES */

    int change_priority(const data_type&, const priority_type&);
};
			       
template <class Priority, class T, class Compare, class Sequence>
int
dynamic_priority_queue<class Priority, class T, class Compare, class Sequence>::
change_priority(const data_type& data, const priority_type& prio)
{
    typename Sequence::iterator f = c.begin(), l = c.end();
    typename Sequence::iterator i = f;
    int count = 0;
    while (i != l) {
	if (i->second == data) {
	    i->first = prio;
	    ++count;
	}
	++i;
    }
    make_heap(f, l, comp);
    return count;
}

// no equality is provided

__STL_END_NAMESPACE

#endif /* __SGI_STL_INTERNAL_DYNAMIC_PRIORITY_QUEUE_H */

// Local Variables:
// mode:C++
// End:
