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

OrderedEdgelist.hpp

Go to the documentation of this file.
00001 #ifndef OrderedEdgelist_HPP
00002 #define OrderedEdgelist_HPP
00003 
00004 #include "common.hpp"
00005 #include "common/Edge.hpp"
00006 #include "datastructures/trie/edgelist/Edgelist.hpp"
00007 #include <vector>
00008 //#include <iterator>   //for test
00009 
00010 
00011 namespace Bodon
00012 {
00013 
00014    template < class VECTOR = std::vector<Edge> >         
00015    class OrderedEdgelist : public Edgelist<VECTOR>
00016    {
00017       public:
00018          OrderedEdgelist() : Edgelist<VECTOR>(){}
00019          void* find(item_t item) const;
00020          void findForward( item_t label, 
00021                            typename VECTOR::iterator& hint) const;
00022 
00023          void findForwardNoBoundaryCheck( 
00024             item_t label, typename VECTOR::iterator& hint) const;
00025 
00026          void findBackward( item_t label, 
00027                             typename VECTOR::iterator& hint) const;
00028          void findBackwardNoBoundaryCheck( 
00029             item_t label, typename VECTOR::iterator& hint) const;
00030 
00031 
00032          void*& findOrCreate(item_t label);
00033          bool lookup(item_t label, void*& subtrie) const;
00034          void lookupNocheck(item_t label, void*& subtrie) const;
00035          void lookupNoUppercheck(item_t label, void*& subtrie) const
00036          {
00037             lookupNocheck(label, subtrie);
00038          }
00039          void lower_bound(typename VECTOR::iterator& it, item_t label)
00040          {
00041             it = std::lower_bound(it, VECTOR::end(), label);
00042          }
00043          item_t largestEdgelabel() const
00044          {
00045             return VECTOR::back().first;
00046          }
00047          item_t smallestEdgelabel() const
00048          {
00049             return VECTOR::front().first;
00050          }
00051    };
00052    template <class VECTOR>
00053    inline void* OrderedEdgelist<VECTOR>::find(
00054       item_t label) const
00055    {
00056       typename VECTOR::const_iterator it = VECTOR::begin(); 
00057       while(it != VECTOR::end() && (*it).first < label)
00058          ++it;
00059       if(it != VECTOR::end() && (*it).first == label)
00060          return  (*it).second;
00061       else
00062          return NULL;
00063    }
00064    template <class VECTOR>
00065    inline void OrderedEdgelist<VECTOR>::findForward(
00066       item_t label, typename VECTOR::iterator& hint) const
00067    {
00068       while(hint != VECTOR::end() && (*hint).first < label)
00069          ++hint;
00070    }
00071    template <class VECTOR>
00072    inline void OrderedEdgelist<VECTOR>::findForwardNoBoundaryCheck(
00073       item_t label, typename VECTOR::iterator& hint) const
00074    {
00075       while((*hint).first < label)
00076          ++hint;
00077    }
00078 
00079    template <class VECTOR>
00080    inline void OrderedEdgelist<VECTOR>::findBackward(
00081       item_t label, typename VECTOR::iterator& hint) const
00082    {
00083       while(hint != VECTOR::begin() && (*hint).first > label)
00084          --hint;
00085    }
00086 
00087    template <class VECTOR>
00088    inline void OrderedEdgelist<VECTOR>::findBackwardNoBoundaryCheck(
00089       item_t label, typename VECTOR::iterator& hint) const
00090    {
00091       while((*hint).first > label)
00092          --hint;
00093    }
00094 
00095    template <class VECTOR>
00096    inline void*& OrderedEdgelist<VECTOR>::findOrCreate(
00097       item_t label)
00098    {
00099       typename VECTOR::iterator it = std::lower_bound( VECTOR::begin(), VECTOR::end(), label );
00100       if( it == VECTOR::end() || (*it).first != label )
00101          it = std::vector<Edge>::insert(it, Edge(label, NULL));
00102       return (*it).second;
00103    }
00104 
00105    template <class VECTOR>
00106    inline bool OrderedEdgelist<VECTOR>::lookup(
00107       item_t label, void*& subtrie) const
00108    {
00109       if(VECTOR::back() < label)
00110          return false;
00111       else
00112       {
00113          typename VECTOR::const_iterator it = 
00114             std::lower_bound( VECTOR::begin(), VECTOR::end(), 
00115                               label );
00116          if( (*it).first == label )
00117             subtrie = (*it).second;
00118          else 
00119             subtrie = NULL;
00120          return true;
00121       }
00122    }
00123    
00124    template <class VECTOR>
00125    inline void OrderedEdgelist<VECTOR>::lookupNocheck(
00126       item_t label, void*& subtrie) const
00127    {
00128         typename VECTOR::const_iterator it = 
00129             std::lower_bound( VECTOR::begin(), 
00130                               VECTOR::end(), label );
00131          if( (*it).first == label )
00132             subtrie = (*it).second;
00133          else 
00134             subtrie = NULL;
00135    }
00136 }
00137 
00138 #endif

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