home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / phpq.hp < prev    next >
Encoding:
Text File  |  1993-07-23  |  2.5 KB  |  113 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.     adapted for libg++ by Doug Lea (dl@rocky.oswego.edu)
  6.  
  7. This file is part of GNU CC.
  8.  
  9. GNU CC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the GNU CC General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. GNU CC, but only under the conditions described in the
  18. GNU CC General Public License.   A copy of this license is
  19. supposed to have been given to you along with GNU CC so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies.  
  23. */
  24.  
  25. #ifndef <T>PHPQ_h
  26. #pragma once
  27. #define <T>PHPQ_h 1
  28.  
  29. #include "<T>.PQ.h"
  30.  
  31. #ifndef <T>PHPQIndex
  32. #define <T>PHPQIndex unsigned short
  33. #endif
  34.  
  35. struct <T>PHPQNode
  36. {
  37.   <T>PHPQIndex   sibling;
  38.   <T>PHPQIndex   children;
  39.   <T>            item;
  40.   char           valid;
  41. };
  42.  
  43.  
  44. class <T>PHPQ : public <T>PQ
  45. {
  46.   <T>PHPQNode*  storage;        // table -- freelist in storage[0].sibling
  47.   int           root;
  48.   int           size;
  49.  
  50.   void          prealloc(int);
  51.   int           check_sibling_list(int, int);
  52.  
  53. public:
  54.  
  55.                 <T>PHPQ(int sz = DEFAULT_INITIAL_CAPACITY);
  56.                 <T>PHPQ(const <T>PHPQ&);
  57.                 ~<T>PHPQ();
  58.  
  59.   Pix           enq(<T&> item);
  60.   <T>           deq(); 
  61.  
  62.   <T>&          front();
  63.   void          del_front();
  64.  
  65.   int           contains(<T&> item);
  66.  
  67.   void          clear(); 
  68.  
  69.   Pix           first(); 
  70.   void          next(Pix& i);
  71.   <T>&          operator () (Pix i);
  72.   void          del(Pix i);
  73.   Pix           seek(<T&> item);
  74.  
  75.   int           OK();                    // rep invariant
  76. };
  77.  
  78.  
  79. inline <T>PHPQ::~<T>PHPQ()
  80. {
  81.   delete [size] storage;
  82. }
  83.  
  84.  
  85. inline <T> <T>PHPQ::deq()
  86. {
  87.   if (count == 0) error("deq of empty PQ");
  88.   <T> x = storage[root].item;
  89.   del_front();
  90.   return x;
  91. }
  92.  
  93.  
  94. inline <T>& <T>PHPQ::front()
  95. {
  96.   if (count == 0) error("front of empty PQ");
  97.   return storage[root].item;
  98. }
  99.  
  100. inline int <T>PHPQ::contains(<T&> item)
  101. {
  102.   return seek(item) != 0;
  103. }
  104.  
  105. inline <T>& <T>PHPQ::operator() (Pix p)
  106. {
  107.   if (p == 0) error("null Pix");
  108.   return storage[int(p)].item;
  109. }
  110.  
  111.  
  112. #endif
  113.