| Polaris: cdg_types.cc Source File | ||
|
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members
cdg_types.ccGo to the documentation of this file.00001 /// 00002 /// $Documentation Manager$ = "Doxygen" 00003 /// 00004 /*! 00005 \file cdg_types.cc 00006 \author Silvius Rus 00007 \date 9/19/00 00008 \brief Implementation of all non-inline methods defined in cdg.h. 00009 */ 00010 /// 00011 #include "cdg_types.h" 00012 00013 00014 /// For class CDSet. 00015 00016 void CDSet::ins(CDElement& e){ 00017 CDElement* ee=new CDElement(e.node(), e.value()); 00018 if (this->entries()==0) { 00019 ins_first(ee); 00020 return; 00021 } 00022 Iterator<CDElement> it=*this; 00023 for ( ; it.valid(); ++it){ 00024 if ( 00025 (it.current().node() > ee->node()) || 00026 ( (it.current().node() == ee->node()) && 00027 (it.current().value() >= ee->value()) )){ 00028 ins_before(ee,&it.current()); 00029 return; 00030 } 00031 } 00032 ins_last(ee); 00033 } 00034 00035 bool CDSet::operator==(CDSet& another){ 00036 if (entries()!=another.entries()){ 00037 return False; 00038 } 00039 Iterator<CDElement> it1=*this; 00040 Iterator<CDElement> it2=another; 00041 for ( ; it1.valid() && it2.valid(); ++it1, ++it2){ 00042 if (it1.current().node()!=it2.current().node()) return False; 00043 if (it1.current().value()!=it2.current().value()) return False; 00044 } 00045 return True; 00046 } 00047 00048 bool CDSet::operator <=(CDSet& another){ 00049 if (entries()>another.entries()){ 00050 return False; 00051 } 00052 00053 Iterator<CDElement> it1=*this; 00054 Iterator<CDElement> it2=another; 00055 int matched=0; 00056 00057 for ( ; it1.valid() && it2.valid(); ){ 00058 CDElement& cd1=it1.current(); 00059 CDElement& cd2=it2.current(); 00060 if (cd1.node()<cd2.node()){ 00061 return False; 00062 } 00063 if (cd1.node()==cd2.node()){ 00064 if (cd1.value()<cd2.value()){ 00065 return False; 00066 } 00067 if (cd1.value()==cd2.value()){ 00068 matched++; 00069 ++it1; 00070 ++it2; 00071 continue; 00072 } 00073 } 00074 /// ... If it gets here, cd1 is greater than cd2. 00075 ++it2; 00076 } 00077 00078 if (matched==entries()) return True; 00079 return False; 00080 } 00081 00082 00083 00084 /// For class CDRepository. 00085 int CDRepository::hash(CDSet& cd){ 00086 unsigned int sum=0; 00087 for(Iterator<CDElement> it=cd; it.valid(); ++it){ 00088 sum+=((unsigned int)it.current().node()); 00089 } 00090 return (sum/8) % entries(); 00091 } 00092 00093 void CDRepository::ins(CDSet& cd, CDGNode* node){ 00094 List<CDRepositoryEntry>& row=(*this)[hash(cd)]; 00095 row.ins_first(new CDRepositoryEntry(cd,node)); 00096 } 00097 00098 CDGNode* CDRepository::lookup(CDSet& cd){ 00099 List<CDRepositoryEntry>& row=(*this)[hash(cd)]; 00100 for (Iterator<CDRepositoryEntry> it=row; it.valid(); ++it){ 00101 if (it.current().cdset==cd) return it.current().rnode; 00102 } 00103 return 0; 00104 } |
||
|