_p_queue.h
Upload User: gzelex
Upload Date: 2007-01-07
Package Size: 707k
Code Size: 3k
Development Platform:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  _p_queue.h
  6. +
  7. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  8. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  9. +  All rights reserved.
  10. *******************************************************************************/
  11. #ifndef _LEDA_P_QUEUE_H
  12. #define _LEDA_P_QUEUE_H
  13. #include <LEDA/p_queue.h>
  14. //------------------------------------------------------------------------------
  15. //
  16. // Priority queues with implementation parameter:
  17. //
  18. //   _p_queue<priotype,inftype,prio_impl> 
  19. //
  20. //------------------------------------------------------------------------------
  21. /*{Manpage {_p_queue} {P,I,impl} {Priority Queues with Implementation Parameter} }*/
  22. /*{Mdefinition
  23. An instance of type name is a priority queue implemented by data type $impl$.
  24. $impl$ must be one of the priority queue implementations listed in
  25. section ref{Implementations Priority Queues} or a user defined data structure
  26. fulfilling the specification given in section ref{User Implementations
  27. Priority Queues}. Note that the priority type $P$ must linearly ordered.
  28. }*/
  29. template <class P, class I, class impl> 
  30. class _p_queue : private impl, public p_queue<P,I>
  31. {
  32. int  int_type()              const { return LEDA_INT_TYPE(P); }
  33. int  cmp(GenPtr x, GenPtr y) const { return LEDA_COMPARE(P,x,y); }
  34. void clear_key(GenPtr& x)    const { LEDA_CLEAR(P,x); }
  35. void clear_inf(GenPtr& x)    const { LEDA_CLEAR(I,x); }
  36. void copy_key(GenPtr& x)     const { LEDA_COPY(P,x); }
  37. void copy_inf(GenPtr& x)     const { LEDA_COPY(I,x); }
  38. void print_key(GenPtr x)     const { LEDA_PRINT(P,x,cout); }
  39. void print_inf(GenPtr x)     const { LEDA_PRINT(I,x,cout); }
  40. public:
  41. pq_item insert(P k,I i) { return pq_item(impl::insert(Convert(k),Convert(i)));}
  42. pq_item find_min() const { return pq_item(impl::find_min());}
  43. P del_min() 
  44. { pq_item it = find_min();
  45.   P x = prio(it);
  46.   del_item(it);
  47.   return x; 
  48.  }
  49. P prio(pq_item x) const { return LEDA_ACCESS(P,impl::key(impl::item(x)));}
  50. I inf(pq_item x) const { return LEDA_ACCESS(I,impl::inf(impl::item(x)));}
  51. void change_inf(pq_item x, I i)
  52. { impl::change_inf(impl::item(x),Convert(i)); }
  53. void decrease_p(pq_item x,P k)
  54. { impl::decrease_key(impl::item(x),Convert(k));}
  55. void del_item(pq_item x) { impl::del_item(impl::item(x)); }
  56. int  size() const { return impl::size(); }
  57. bool empty() const { return impl::size()==0; }
  58. pq_item first_item() const { return pq_item(impl::first_item()); }
  59. pq_item next_item(pq_item it) const 
  60. { return pq_item(impl::next_item(impl::item(it))); }
  61. _p_queue<P,I,impl>& operator=(const _p_queue<P,I,impl>& Q)
  62. { impl::operator=(Q); return *this; }
  63.  _p_queue() {}
  64.  _p_queue(int n) : impl(n) {}
  65.  _p_queue(const _p_queue<P,I,impl>& Q) : impl(Q) {}
  66. ~_p_queue() { impl::clear(); }
  67. };
  68. #endif