Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/vm/maptable.h

Go to the documentation of this file.
00001 /*
00002  * vm/maptable.h
00003  * 
00004  * B-tree based O(log(n)) ID-to-INFO map. 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #ifndef _VM_MAPTABLE_H_
00018 #define _VM_MAPTABLE_H_ 1
00019 
00027 #include <vm/vmconfig.h>    /* MUST be first */
00028 
00029 #include <lib/tl/tlbtree.h>
00030 
00031 
00040 template<typename ID,typename INFO>struct IDMapTableNode
00041 {
00042     ID id;
00043     INFO info;
00044     
00045     inline IDMapTableNode() : id(0),info((INFO)0) {}
00046     inline IDMapTableNode(ID _tid,INFO _info) : 
00047         id(_tid),info(_info) {}
00048     inline IDMapTableNode(const IDMapTableNode &n) : 
00049         id(n.id),info(n.info) {}
00050     inline ~IDMapTableNode() { info=(INFO)0; }
00051     
00052     inline IDMapTableNode &operator=(const IDMapTableNode &n)
00053         {  id=n.id;  info=n.info;  return(*this);  }
00054     
00056     inline bool operator==(const IDMapTableNode &n) const  { return(id==n.id); }
00057     inline bool operator!=(const IDMapTableNode &n) const  { return(id!=n.id); }
00058     inline bool operator<(const IDMapTableNode &n)  const  { return(id<n.id);  }
00059     inline bool operator>(const IDMapTableNode &n)  const  { return(id>n.id);  }
00060     inline bool operator<=(const IDMapTableNode &n) const  { return(id<=n.id); }
00061     inline bool operator>=(const IDMapTableNode &n) const  { return(id>=n.id); }
00062     inline bool operator==(const ID &b) const  { return(id==b); }
00063     inline bool operator!=(const ID &b) const  { return(id!=b); }
00064     inline bool operator<(const ID &b) const   { return(id<b);  }
00065     inline bool operator>(const ID &b) const   { return(id>b);  }
00066     inline bool operator<=(const ID &b) const  { return(id<=b); }
00067     inline bool operator>=(const ID &b) const  { return(id>=b); }
00068 };
00069 
00070 
00080 template<typename ID,typename INFO>class IDMapTable
00081 {
00082     public:
00083         typedef IDMapTableNode<ID,INFO> Node;
00084         
00085     private:
00087         TLBTree< Node,TLDefaultOperators_CDT<Node> > map;
00088         
00090         IDMapTable(const IDMapTable &);
00092         void operator=(const IDMapTable &);
00093     public:
00095         inline IDMapTable() : map(/*m=16 (default)*/) {}
00097         inline IDMapTable(uint m) : map(m) {}
00099         inline ~IDMapTable() {}
00100         
00108         INFO AddNode(ID id,INFO info,bool *is_known=NULL)
00109         {
00110             Node tmp(id,info);
00111             Node old_val;
00112             if(map.store(tmp,/*allow_update=*/0,&old_val))
00113             {
00114                 if(is_known)  *is_known=1;
00115                 return(old_val.info);
00116             }
00117             if(is_known)  *is_known=0;
00118             return((INFO)0);
00119         }
00120         
00128         INFO lookup(ID id,bool *was_found=NULL)
00129         {
00130             Node *tmp=map.search(id);
00131             if(was_found)  *was_found=tmp;
00132             return(tmp ? tmp->info : (INFO)0);
00133         }
00134         
00136         inline void clear()
00137             {  map.clear();  }
00138 };
00139 
00140 #endif  /* _VM_MAPTABLE_H_ */

Generated on Sat Feb 19 22:33:47 2005 for Ray by doxygen 1.3.5