00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _VM_MAPTABLE_H_
00018 #define _VM_MAPTABLE_H_ 1
00019
00027 #include <vm/vmconfig.h>
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() {}
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,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