Changelist.h

Go to the documentation of this file.
00001 // $Id: Changelist.h 243 2006-07-06 07:57:25Z bingmann $
00002 
00003 #ifndef VGS_ChangeList_H
00004 #define VGS_ChangeList_H
00005 
00006 #include "GraphTypes.h"
00007 #include "GraphData.h"
00008 #include "AttributeBlob.h"
00009 #include "GraphPort.h"
00010 
00011 #if defined(__GNUC__)
00012 #include <ext/hash_map>
00013 #include <ext/hash_set>
00014 #else
00015 #include <hash_map>
00016 #include <hash_set>
00017 #endif
00018 
00019 namespace VGServer {
00020 
00021 #if defined(__GNUC__)
00022 
00023 using __gnu_cxx::hash_set;
00024 using __gnu_cxx::hash_map;
00025 using __gnu_cxx::hash_multimap;
00026 
00027 #else
00028 
00029 using stdext::hash_set;
00030 using stdext::hash_map;
00031 using stdext::hash_multimap;
00032 
00033 #endif
00034 
00039 class Changelist
00040 {
00041 private:
00043     friend class GraphData;
00044 
00046     friend class GraphContainer;
00047 
00049     const class GraphData &graph;
00050 
00051     /* The Changelist consists of two hash_maps holding AttributeBlobs which
00052      * contain the attribute values of the changed vertices and edges. If a
00053      * vertex or edge is deleted, then the AttributeBlob at that position is
00054      * empty. Thus addVertex and addEdge allocate the default bitfield and/or
00055      * the varying attributes. Furthermore the addV/E function add a new entry
00056      * to the hash_sets of newly create vertices or edges. These are checked
00057      * when providing frame 0 in getArea. */
00058     
00059     typedef hash_map<vertexid_t, AttributeVertexTinyBlob> vertexchglist_t;
00060 
00062     hash_map<vertexid_t, AttributeVertexTinyBlob> vertexchglist;
00063 
00064     typedef hash_set<vertexid_t> vertexaddlist_t;
00065 
00067     hash_set<vertexid_t>        vertexaddlist;
00068 
00071     typedef std::pair<vertexid_t, vertexid_t> vertexidpair_t;
00072 
00073 #if defined(__GNUC__)
00074 
00077     struct vertexidpair_hashfunc {
00078         inline size_t operator()(const vertexidpair_t &p) const
00079         { return p.first; }
00080     };
00081 
00082     struct vertexidpair_equalfunc {
00083         inline bool operator()(const vertexidpair_t &a, const vertexidpair_t &b) const
00084         { return (a.first == b.first); }
00085     };
00086 
00087     struct vertexidpair_add_hashfunc { // another hash function for the add list
00088         inline size_t operator()(const vertexidpair_t &p) const
00089         { return (p.first ^ p.second); }
00090     };
00091 
00092     typedef hash_multimap<vertexidpair_t, AttributeEdgeTinyBlob,
00093                           vertexidpair_hashfunc, vertexidpair_equalfunc> edgechglist_t;
00094 
00095     typedef hash_set<vertexidpair_t, vertexidpair_add_hashfunc> edgeaddlist_t;
00096 
00097 #else
00098     // visual c++
00099 
00100     struct vertexidpair_hash_compare {
00101         static const size_t bucket_size = 4;
00102         static const size_t min_buckets = 8;
00103 
00105         inline size_t operator()(const vertexidpair_t &p) const
00106         { return p.first; }
00107 
00109         inline bool operator()(const vertexidpair_t &a, const vertexidpair_t &b) const
00110         { return (a.first == b.first); }
00111     };
00112 
00113     typedef hash_multimap<vertexidpair_t, AttributeEdgeTinyBlob,
00114                           vertexidpair_hash_compare> edgechglist_t;
00115 
00116     // TODO: typedef edgeaddlist_t
00117 
00118 #endif
00119 
00127 
00128     edgechglist_t edgechglist;
00129 
00131     edgeaddlist_t edgeaddlist;
00132     
00144     inline edgechglist_t::iterator find_edgechglist(vertexid_t src, vertexid_t tgt)
00145     {
00146         unsigned int ec = edgechglist.count(vertexidpair_t(src,tgt));
00147         if (ec == 0) return edgechglist.end();
00148 
00149         edgechglist_t::iterator e = edgechglist.find(vertexidpair_t(src,tgt));
00150 
00151         while( e != edgechglist.end() && !(e->first.first == src && e->first.second == tgt) )
00152         {
00153             if (e->first.first == src) {
00154                 if (--ec == 0)
00155                     return edgechglist.end();
00156             }
00157             e++; // find right target change entry
00158         }
00159 
00160         return e;
00161     }
00162 
00165     inline edgechglist_t::const_iterator find_edgechglist(vertexid_t src, vertexid_t tgt) const
00166     {
00167         unsigned int ec = edgechglist.count(vertexidpair_t(src,tgt));
00168         if (ec == 0) return edgechglist.end();
00169 
00170         edgechglist_t::const_iterator e = edgechglist.find(vertexidpair_t(src,tgt));
00171 
00172         while( e != edgechglist.end() && !(e->first.first == src && e->first.second == tgt) )
00173         {
00174             if (e->first.first == src) {
00175                 if (--ec == 0)
00176                     return edgechglist.end();
00177             }
00178             e++; // find right target change entry
00179         }
00180 
00181         return e;
00182     }
00183 
00184 public:
00186     explicit Changelist(const class GraphData &graph);
00187 
00189     void        clear();
00190 
00192     bool        addVertex(vertexid_t id);
00193 
00196     bool        addVertex(vertexid_t id, const AttributeVertexTinyBlob &vb);
00197 
00199     bool        setVertexAttr(vertexid_t id, unsigned int attrid, const AnyType &value);
00200 
00202     bool        setVertexAttr(vertexid_t id, const AttributeVertexTinyBlob &vb);
00203     
00205     bool        delVertex(vertexid_t id);
00206     
00208     bool        addEdge(vertexid_t src, vertexid_t tgt);
00209 
00211     bool        addEdge(vertexid_t src, vertexid_t tgt, const AttributeEdgeTinyBlob &eb);
00212     
00214     bool        setEdgeAttr(vertexid_t src, vertexid_t tgt, unsigned int attrid, const AnyType &value);
00215 
00217     bool        setEdgeAttr(vertexid_t src, vertexid_t tgt, const AttributeEdgeTinyBlob &eb);
00218     
00220     bool        delEdge(vertexid_t src, vertexid_t tgt);
00221 
00223     inline bool isVertexChanged(vertexid_t id) const
00224     { return (vertexchglist.find(id) != vertexchglist.end()); }
00225 
00227     inline const AttributeVertexTinyBlob& getVertexChange(vertexid_t vid) const
00228     { return vertexchglist.find(vid)->second; }
00229 
00231     inline bool isEdgeChanged(vertexid_t src, vertexid_t tgt) const
00232     {
00233         edgechglist_t::const_iterator e = find_edgechglist(src,tgt);
00234 
00235         return (e != edgechglist.end());
00236     }
00237 
00239     inline const AttributeEdgeTinyBlob& getEdgeChange(vertexid_t src, vertexid_t tgt) const
00240     {
00241         edgechglist_t::const_iterator e = find_edgechglist(src,tgt);
00242 
00243         assert(e != edgechglist.end());
00244         return e->second;
00245     }
00246 
00247     typedef std::pair<vertexid_t, const AttributeEdgeTinyBlob*> edgeblobpair_t;
00248     typedef std::vector<edgeblobpair_t> edgelist_t;
00249 
00252     std::vector<edgeblobpair_t> getEdgeListChange(vertexid_t src) const;
00253 
00254 };
00255 
00256 } // namespace VGServer
00257 
00258 #endif // VGS_Changelist_H

Generated on Wed Sep 27 14:34:00 2006 for VGServer by  doxygen 1.4.7