// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) ranking code from Paul Anderson (paul%lfcs.ed.ac.uk) This file is part of the GNU C++ Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef _RAVLMap_h #ifdef __GNUG__ #pragma interface #endif #define _RAVLMap_h 1 #include "..Map.h" struct RAVLNode { RAVLNode* lt; RAVLNode* rt; item; cont; int rank; char stat; RAVLNode( h, c, RAVLNode* l=0, RAVLNode* r=0, int k=1); ~RAVLNode(); }; inline RAVLNode::RAVLNode( h, c, RAVLNode* l, RAVLNode* r, int k) :item(h), cont(c), lt(l), rt(r), rank(k), stat(0) {} inline RAVLNode::~RAVLNode() {} typedef RAVLNode* RAVLNodePtr; class RAVLMap : public Map { protected: RAVLNode* root; RAVLNode* leftmost(); RAVLNode* rightmost(); RAVLNode* pred(RAVLNode* t); RAVLNode* succ(RAVLNode* t); void _kill(RAVLNode* t); void _add(RAVLNode*& t); void _del(RAVLNode* p, RAVLNode*& t); public: RAVLMap( dflt); RAVLMap(RAVLMap& a); ~RAVLMap(); & operator [] ( key); void del( key); Pix first(); void next(Pix& i); & key(Pix i); & contents(Pix i); Pix seek( key); int contains( key); Pix ranktoPix(int i); int rankof( key); void clear(); Pix last(); void prev(Pix& i); int OK(); }; inline RAVLMap::~RAVLMap() { _kill(root); } inline RAVLMap::RAVLMap( dflt) :Map(dflt) { root = 0; } inline Pix RAVLMap::first() { return Pix(leftmost()); } inline Pix RAVLMap::last() { return Pix(rightmost()); } inline void RAVLMap::next(Pix& i) { if (i != 0) i = Pix(succ((RAVLNode*)i)); } inline void RAVLMap::prev(Pix& i) { if (i != 0) i = Pix(pred((RAVLNode*)i)); } inline & RAVLMap::key(Pix i) { if (i == 0) error("null Pix"); return ((RAVLNode*)i)->item; } inline & RAVLMap::contents(Pix i) { if (i == 0) error("null Pix"); return ((RAVLNode*)i)->cont; } inline void RAVLMap::clear() { _kill(root); count = 0; root = 0; } inline int RAVLMap::contains( key) { return seek(key) != 0; } #endif