1// This may look like C code, but it is really -*- C++ -*- 2/* 3Copyright (C) 1988 Free Software Foundation 4 written by Doug Lea (dl@rocky.oswego.edu) 5 6This file is part of GNU CC. 7 8GNU CC is distributed in the hope that it will be useful, 9but WITHOUT ANY WARRANTY. No author or distributor 10accepts responsibility to anyone for the consequences of using it 11or for whether it serves any particular purpose or works at all, 12unless he says so in writing. Refer to the GNU CC General Public 13License for full details. 14 15Everyone is granted permission to copy, modify and redistribute 16GNU CC, but only under the conditions described in the 17GNU CC General Public License. A copy of this license is 18supposed to have been given to you along with GNU CC so you 19can know your rights and responsibilities. It should be in a 20file named COPYING. Among other things, the copyright notice 21and this notice must be preserved on all copies. 22*/ 23 24 25#ifndef _<T>SplaySet_h 26#ifdef __GNUG__ 27#pragma once 28#pragma interface 29#endif 30#define _<T>SplaySet_h 1 31 32#include "<T>.Set.h" 33 34#ifndef _<T>SplayNode 35#define _<T>SplayNode 1 36 37struct <T>SplayNode 38{ 39 <T>SplayNode* lt; 40 <T>SplayNode* rt; 41 <T>SplayNode* par; 42 <T> item; 43 <T>SplayNode(<T&> h, <T>SplayNode* l=0, <T>SplayNode* r=0); 44 ~<T>SplayNode(); 45}; 46 47#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES) 48 49inline <T>SplayNode::<T>SplayNode(<T&> h, <T>SplayNode* l, <T>SplayNode* r) 50:item(h), lt(l), rt(r), par(0) {} 51 52inline <T>SplayNode::~<T>SplayNode() {} 53 54#endif 55 56typedef <T>SplayNode* <T>SplayNodePtr; 57 58#endif 59 60class <T>SplaySet : public <T>Set 61{ 62protected: 63 <T>SplayNode* root; 64 65 <T>SplayNode* leftmost(); 66 <T>SplayNode* rightmost(); 67 <T>SplayNode* pred(<T>SplayNode* t); 68 <T>SplayNode* succ(<T>SplayNode* t); 69 void _kill(<T>SplayNode* t); 70 <T>SplayNode* _copy(<T>SplayNode* t); 71 72public: 73 <T>SplaySet(); 74 <T>SplaySet(<T>SplaySet& a); 75 ~<T>SplaySet(); 76 77 Pix add(<T&> item); 78 void del(<T&> item); 79 int contains(<T&> item); 80 81 void clear(); 82 83 Pix first(); 84 void next(Pix& i); 85 <T>& operator () (Pix i); 86 Pix seek(<T&> item); 87 88 Pix last(); 89 void prev(Pix& i); 90 91 void operator |= (<T>SplaySet& b); 92 void operator -= (<T>SplaySet& b); 93 void operator &= (<T>SplaySet& b); 94 95 int operator == (<T>SplaySet& b); 96 int operator != (<T>SplaySet& b); 97 int operator <= (<T>SplaySet& b); 98 99 int OK(); 100}; 101 102#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES) 103 104inline <T>SplaySet::~<T>SplaySet() 105{ 106 _kill(root); 107} 108 109inline <T>SplaySet::<T>SplaySet() 110{ 111 root = 0; 112 count = 0; 113} 114 115inline <T>SplaySet::<T>SplaySet(<T>SplaySet& b) 116{ 117 count = b.count; 118 root = _copy(b.root); 119} 120 121 122inline int <T>SplaySet::operator != (<T>SplaySet& b) 123{ 124 return ! (*this == b); 125} 126 127inline Pix <T>SplaySet::first() 128{ 129 return Pix(leftmost()); 130} 131 132inline Pix <T>SplaySet::last() 133{ 134 return Pix(rightmost()); 135} 136 137inline void <T>SplaySet::next(Pix& i) 138{ 139 if (i != 0) i = Pix(succ((<T>SplayNode*)i)); 140} 141 142inline void <T>SplaySet::prev(Pix& i) 143{ 144 if (i != 0) i = Pix(pred((<T>SplayNode*)i)); 145} 146 147inline <T>& <T>SplaySet::operator () (Pix i) 148{ 149 if (i == 0) error("null Pix"); 150 return ((<T>SplayNode*)i)->item; 151} 152 153inline void <T>SplaySet::clear() 154{ 155 _kill(root); 156 count = 0; 157 root = 0; 158} 159 160inline int <T>SplaySet::contains(<T&> key) 161{ 162 return seek(key) != 0; 163} 164 165 166#endif 167#endif 168