Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Edgelist.hpp

Go to the documentation of this file.
00001 #ifndef Edgelist_HPP
00002 #define Edgelist_HPP
00003 
00004 #include "common.hpp"
00005 #include "common/Edge.hpp"
00006 #include <vector>
00007 //#include <iterator>   //for test
00008 
00009 
00010 namespace Bodon
00011 {
00017    template <class VECTOR = std::vector<Edge> >
00018    class Edgelist : public VECTOR
00019    {
00020       public:
00021          Edgelist() : VECTOR(){}
00022 
00023          void* find(item_t item) const;
00024          void*& findOrCreate(item_t label);
00025          bool lookup(item_t label, void*& subtrie) const;
00026          void insert(const std::vector<Edge>& new_edges)
00027          {
00028 //option I.         VECTOR::swap(new_edges);
00030             VECTOR::reserve(new_edges.size());
00031             for(std::vector<Edge>::const_iterator it = new_edges.begin();
00032                it != new_edges.end(); ++it)
00033                VECTOR::push_back(*it);
00034 //option III.
00035 //          VECTOR::insert(VECTOR::end(), new_edges.begin(), new_edges.end());
00036 //option IV.
00037 //          VECTOR::operator=(new_edges);
00038          }
00039          size_t edgeNumber() const
00040          {
00041             return VECTOR::size();
00042          }
00043    };
00044    
00045    template <class VECTOR>
00046    inline void* Edgelist<VECTOR>::find(
00047       item_t label) const
00048    {
00049       typename VECTOR::const_iterator it = 
00050          std::find( VECTOR::begin(), VECTOR::end(), label );
00051       if( it != VECTOR::end() )
00052          return  (*it).second;
00053       else 
00054          return NULL;
00055    }
00056 
00057    template <class VECTOR>
00058    inline void*& Edgelist<VECTOR>::findOrCreate(
00059       item_t label)
00060    {
00061       typename VECTOR::iterator it = 
00062          std::find( VECTOR::begin(), VECTOR::end(), label );
00063       if( it == VECTOR::end() )
00064       {
00065          VECTOR::push_back(Edge(label, NULL));
00066          it = --VECTOR::end();
00067       }
00068       return (*it).second;
00069    }
00070 
00071    template <class VECTOR>
00072    inline bool Edgelist<VECTOR>::
00073    lookup(item_t label, void*& subtrie) const
00074    {
00075       bool return_value = false;
00076       for(typename VECTOR::const_iterator it = VECTOR::begin(); 
00077           it != VECTOR::end(); ++it)
00078       {
00079          if(*it == label)
00080          {
00081             subtrie = (*it).second;
00082             return true;
00083          }
00084          else if(*it > label)
00085             return_value = true;
00086       }
00087       return return_value;
00088    }
00089 }
00090 
00091 #endif

Generated on Sun Sep 17 17:50:38 2006 for FIM environment by  doxygen 1.4.4