lemon/iterable_maps.h
changeset 2103 a979fcdda073
parent 1993 2115143eceea
child 2112 f27dfd29c5c0
equal deleted inserted replaced
13:bb38b91157f6 14:7ce6017d9eb2
    18 
    18 
    19 #include <lemon/bits/traits.h>
    19 #include <lemon/bits/traits.h>
    20 #include <lemon/bits/invalid.h>
    20 #include <lemon/bits/invalid.h>
    21 
    21 
    22 #include <lemon/bits/default_map.h>
    22 #include <lemon/bits/default_map.h>
       
    23 #include <lemon/bits/map_extender.h>
    23 
    24 
    24 #include <vector>
    25 #include <vector>
    25 #include <map>
    26 #include <map>
    26 
    27 
    27 #include <iterator>
    28 #include <iterator>
   398   /// 
   399   /// 
   399   /// \param _Graph The graph type.
   400   /// \param _Graph The graph type.
   400   /// \param _Item One of the graph's item type, the key of the map.
   401   /// \param _Item One of the graph's item type, the key of the map.
   401   template <typename _Graph, typename _Item>
   402   template <typename _Graph, typename _Item>
   402   class IterableIntMap 
   403   class IterableIntMap 
   403     : protected DefaultMap<_Graph, _Item, _iterable_maps_bits::
   404     : protected MapExtender<DefaultMap<_Graph, _Item, _iterable_maps_bits::
   404                            IterableIntMapNode<_Item> > {
   405                                        IterableIntMapNode<_Item> > >{
   405   public:
   406   public:
   406     typedef DefaultMap<_Graph, _Item, _iterable_maps_bits::
   407     typedef MapExtender<DefaultMap<_Graph, _Item, _iterable_maps_bits::
   407                        IterableIntMapNode<_Item> >
   408                                    IterableIntMapNode<_Item> > > Parent;
   408     Parent;
       
   409 
   409 
   410     /// The key type
   410     /// The key type
   411     typedef _Item Key;
   411     typedef _Item Key;
   412     /// The value type
   412     /// The value type
   413     typedef int Value;
   413     typedef int Value;
   687   /// \param _Graph The graph type.
   687   /// \param _Graph The graph type.
   688   /// \param _Item One of the graph's item type, the key of the map.
   688   /// \param _Item One of the graph's item type, the key of the map.
   689   /// \param _Value Any comparable value type.
   689   /// \param _Value Any comparable value type.
   690   template <typename _Graph, typename _Item, typename _Value>
   690   template <typename _Graph, typename _Item, typename _Value>
   691   class IterableValueMap 
   691   class IterableValueMap 
   692     : protected DefaultMap<_Graph, _Item, _iterable_maps_bits::
   692     : protected MapExtender<DefaultMap<_Graph, _Item, _iterable_maps_bits::
   693                            IterableValueMapNode<_Item, _Value> > {
   693                                        IterableValueMapNode<_Item, _Value> > >{
   694   public:
   694   public:
   695     typedef DefaultMap<_Graph, _Item, _iterable_maps_bits::
   695     typedef MapExtender<DefaultMap<_Graph, _Item, _iterable_maps_bits::
   696                        IterableValueMapNode<_Item, _Value> > Parent;
   696                                    IterableValueMapNode<_Item, _Value> > >
       
   697     Parent;
   697 
   698 
   698     /// The key type
   699     /// The key type
   699     typedef _Item Key;
   700     typedef _Item Key;
   700     /// The value type
   701     /// The value type
   701     typedef _Value Value;
   702     typedef _Value Value;
   702     /// The graph type
   703     /// The graph type
   703     typedef _Graph Graph;
   704     typedef _Graph Graph;
   704 
   705 
   705   protected:
       
   706 
       
   707     typedef typename ItemSetTraits<_Graph, Key>::ItemIt KeyIt; 
       
   708 
       
   709   public:
   706   public:
   710 
   707 
   711     /// \brief Constructor of the Map with a given value.
   708     /// \brief Constructor of the Map with a given value.
   712     ///
   709     ///
   713     /// Constructor of the Map with a given value.
   710     /// Constructor of the Map with a given value.
   714     explicit IterableValueMap(const Graph& graph, 
   711     explicit IterableValueMap(const Graph& graph, 
   715                               const Value& value = Value()) 
   712                               const Value& value = Value()) 
   716       : Parent(graph, _iterable_maps_bits::
   713       : Parent(graph, _iterable_maps_bits::
   717                IterableValueMapNode<_Item, _Value>(value)) {
   714                IterableValueMapNode<_Item, _Value>(value)) {
   718       for (KeyIt it(*Parent::getGraph()); it != INVALID; ++it) {
   715       for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
   719         lace(it);
   716         lace(it);
   720       }
   717       }
   721     }
   718     }
   722 
   719 
   723   protected:
   720   protected:
   901       Parent::erase(keys);
   898       Parent::erase(keys);
   902     }
   899     }
   903 
   900 
   904     virtual void build() {
   901     virtual void build() {
   905       Parent::build();
   902       Parent::build();
   906       for (KeyIt it(*Parent::getGraph()); it != INVALID; ++it) {
   903       for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
   907         lace(it);
   904         lace(it);
   908       }
   905       }
   909     }
   906     }
   910 
   907 
   911     virtual void clear() {
   908     virtual void clear() {