home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / TXI2IPF1 / SOURCE.ZIP / gen / String_Name_AVLMap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-04  |  4.2 KB  |  155 lines

  1. /*****************************************************************************
  2.  * $Id: String_Name_AVLMap.h,v 1.1.1.1 1993/02/04 15:18:08 ak Exp $
  3.  *****************************************************************************
  4.  * $Log: String_Name_AVLMap.h,v $
  5.  * Revision 1.1.1.1  1993/02/04  15:18:08  ak
  6.  * Please Edit this file to contain the RCS log information
  7.  * to be associated with this file (please remove these lines)
  8.  *
  9.  * Revision 1.1  1993/02/04  15:18:05  ak
  10.  * Initial revision
  11.  *
  12.  *****************************************************************************/
  13.  
  14. // This may look like C code, but it is really -*- C++ -*-
  15. /*
  16. Copyright (C) 1988 Free Software Foundation
  17.     written by Doug Lea (dl@rocky.oswego.edu)
  18.  
  19. This file is part of the GNU C++ Library.  This library is free
  20. software; you can redistribute it and/or modify it under the terms of
  21. the GNU Library General Public License as published by the Free
  22. Software Foundation; either version 2 of the License, or (at your
  23. option) any later version.  This library is distributed in the hope
  24. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  25. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  26. PURPOSE.  See the GNU Library General Public License for more details.
  27. You should have received a copy of the GNU Library General Public
  28. License along with this library; if not, write to the Free Software
  29. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  30. */
  31.  
  32.  
  33. #ifndef _StringNameAVLMap_h
  34. #ifdef __GNUG__
  35. #pragma interface
  36. #endif
  37. #define _StringNameAVLMap_h 1
  38.  
  39. #include "String_Name_Map.h"
  40.  
  41. struct StringNameAVLNode
  42. {
  43.   StringNameAVLNode*      lt;
  44.   StringNameAVLNode*      rt;
  45.   String                 item;
  46.   Name                 cont;
  47.   char                stat;
  48.                       StringNameAVLNode(String& h, Name& c,
  49.                                     StringNameAVLNode* l=0, StringNameAVLNode* r=0);
  50.                       ~StringNameAVLNode();
  51. };
  52.  
  53. inline StringNameAVLNode::StringNameAVLNode(String& h, Name& c,
  54.                                     StringNameAVLNode* l, StringNameAVLNode* r)
  55.      :item(h), cont(c), lt(l), rt(r), stat(0) {}
  56.  
  57. inline StringNameAVLNode::~StringNameAVLNode() {}
  58.  
  59. typedef StringNameAVLNode* StringNameAVLNodePtr;
  60.  
  61.  
  62. class StringNameAVLMap : public StringNameMap
  63. {
  64. protected:
  65.   StringNameAVLNode*   root;
  66.  
  67.   StringNameAVLNode*   leftmost();
  68.   StringNameAVLNode*   rightmost();
  69.   StringNameAVLNode*   pred(StringNameAVLNode* t);
  70.   StringNameAVLNode*   succ(StringNameAVLNode* t);
  71.   void            _kill(StringNameAVLNode* t);
  72.   void            _add(StringNameAVLNode*& t);
  73.   void            _del(StringNameAVLNode* p, StringNameAVLNode*& t);
  74.  
  75. public:
  76.                 StringNameAVLMap(Name& dflt);
  77.                 StringNameAVLMap(StringNameAVLMap& a);
  78.                 ~StringNameAVLMap();
  79.  
  80.   Name&          operator [] (String& key);
  81.  
  82.   void          del(String& key);
  83.  
  84.   Pix           first();
  85.   void          next(Pix& i);
  86.   String&          key(Pix i);
  87.   Name&          contents(Pix i);
  88.  
  89.   Pix           seek(String& key);
  90.   int           contains(String& key);
  91.  
  92.   void          clear();
  93.  
  94.   Pix           last();
  95.   void          prev(Pix& i);
  96.  
  97.   int           OK();
  98. };
  99.  
  100. inline StringNameAVLMap::~StringNameAVLMap()
  101. {
  102.   _kill(root);
  103. }
  104.  
  105. inline StringNameAVLMap::StringNameAVLMap(Name& dflt) :StringNameMap(dflt)
  106. {
  107.   root = 0;
  108. }
  109.  
  110. inline Pix StringNameAVLMap::first()
  111. {
  112.   return Pix(leftmost());
  113. }
  114.  
  115. inline Pix StringNameAVLMap::last()
  116. {
  117.   return Pix(rightmost());
  118. }
  119.  
  120. inline void StringNameAVLMap::next(Pix& i)
  121. {
  122.   if (i != 0) i = Pix(succ((StringNameAVLNode*)i));
  123. }
  124.  
  125. inline void StringNameAVLMap::prev(Pix& i)
  126. {
  127.   if (i != 0) i = Pix(pred((StringNameAVLNode*)i));
  128. }
  129.  
  130. inline String& StringNameAVLMap::key(Pix i)
  131. {
  132.   if (i == 0) error("null Pix");
  133.   return ((StringNameAVLNode*)i)->item;
  134. }
  135.  
  136. inline Name& StringNameAVLMap::contents(Pix i)
  137. {
  138.   if (i == 0) error("null Pix");
  139.   return ((StringNameAVLNode*)i)->cont;
  140. }
  141.  
  142. inline void StringNameAVLMap::clear()
  143. {
  144.   _kill(root);
  145.   count = 0;
  146.   root = 0;
  147. }
  148.  
  149. inline int StringNameAVLMap::contains(String& key)
  150. {
  151.   return seek(key) != 0;
  152. }
  153.  
  154. #endif
  155.