Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

avlset.h

00001 //
00002 // avlset.h --- definition for avl set class
00003 //
00004 // Copyright (C) 1998 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027 
00028 #ifndef _util_container_avlset_h
00029 #define _util_container_avlset_h
00030 
00031 #include <util/container/avlmap.h>
00032 
00033 
00034 template <class K>
00035 class AVLSet {
00036   private:
00037     AVLMap<K,int> map_;
00038   public:
00039     class iterator {
00040       private:
00041         const EAVLMMap<K, AVLMapNode<K,int> > *map_;
00042         const AVLMapNode<K, int> *node;
00043       public:
00044         iterator(): map_(0), node(0) {}
00045         iterator(const EAVLMMap<K,AVLMapNode<K,int> > *m,
00046                  const AVLMapNode<K,int> *n)
00047           :map_(m), node(n) {}
00048         iterator(const eavl_typename AVLSet<K>::iterator &i):map_(i.map_),node(i.node) {}
00049         void operator++() { map_->next(node); }
00050         void operator++(int) { operator++(); }
00051         int operator == (const eavl_typename AVLSet<K>::iterator &i) const
00052             { return map_ == i.map_ && node == i.node; }
00053         int operator != (const eavl_typename AVLSet<K>::iterator &i) const
00054             { return !(map_ == i.map_ && node == i.node); }
00055         void operator = (const eavl_typename AVLSet<K>::iterator &i)
00056             { map_ = i.map_; node = i.node; }
00057         const K &key() const { return node->node.key; }
00058         const K &operator *() const { return node->node.key; }
00059         //const K *operator ->() const { return &node->node.key; }
00060     };
00061   public:
00062     AVLSet() {};
00063     void clear() { map_.clear(); }
00064     void insert(const K& key) { map_.insert(key,0); }
00065     void remove(const K& key) { map_.remove(key); }
00066     int contains(const K& key) const { return map_.contains(key); }
00067     iterator find(const K& k) const;
00068 
00069     int height() { return map_.height(); }
00070     void check() { map_.check(); }
00071 
00072     int length() const { return map_.length(); }
00073 
00074     iterator begin() const { return iterator(&map_.map_,map_.map_.start()); }
00075     iterator end() const { return iterator(&map_.map_,0); }
00076 
00077     void operator -= (const AVLSet<K> &s);
00078     void operator |= (const AVLSet<K> &s);
00079 
00080     void print() { map_.print(); }
00081 };
00082 
00083 template <class K>
00084 void
00085 AVLSet<K>::operator -= (const AVLSet<K> &s)
00086 {
00087   for (AVLSet<K>::iterator i=s.begin(); i!=s.end(); i++) {
00088       remove(*i);
00089     }
00090 }
00091 
00092 template <class K>
00093 void
00094 AVLSet<K>::operator |= (const AVLSet<K> &s)
00095 {
00096   for (AVLSet<K>::iterator i=s.begin(); i!=s.end(); i++) {
00097       insert(*i);
00098     }
00099 }
00100 
00101 template <class K>
00102 inline typename AVLSet<K>::iterator
00103 AVLSet<K>::find(const K& k) const
00104 {
00105   return iterator(&map_.map_,map_.map_.find(k));
00106 }
00107 
00108 #endif
00109 
00110 // ///////////////////////////////////////////////////////////////////////////
00111 
00112 // Local Variables:
00113 // mode: c++
00114 // c-file-style: "CLJ"
00115 // End:

Generated at Thu Oct 4 18:08:42 2001 for MPQC 2.0.0 using the documentation package Doxygen 1.2.5.