lemon/iterable_maps.h
changeset 1990 15fb7a4ea6be
parent 1956 a055123339d5
child 1993 2115143eceea
     1.1 --- a/lemon/iterable_maps.h	Wed Mar 01 10:04:47 2006 +0000
     1.2 +++ b/lemon/iterable_maps.h	Wed Mar 01 10:17:25 2006 +0000
     1.3 @@ -19,6 +19,8 @@
     1.4  #include <lemon/traits.h>
     1.5  #include <lemon/invalid.h>
     1.6  
     1.7 +#include <lemon/bits/default_map.h>
     1.8 +
     1.9  #include <vector>
    1.10  #include <map>
    1.11  
    1.12 @@ -47,14 +49,12 @@
    1.13    /// \param _Graph The graph type.
    1.14    /// \param _Item One of the graph's item type, the key of the map.
    1.15    template <typename _Graph, typename _Item>
    1.16 -  class IterableBoolMap 
    1.17 -    : protected ItemSetTraits<_Graph, _Item>::template Map<int>::Parent {
    1.18 +  class IterableBoolMap : protected DefaultMap<_Graph, _Item, int> {
    1.19    private:
    1.20      typedef _Graph Graph;
    1.21      
    1.22      typedef typename ItemSetTraits<Graph, _Item>::ItemIt KeyIt;
    1.23 -    typedef typename ItemSetTraits<Graph, _Item>
    1.24 -    ::template Map<int>::Parent Parent;
    1.25 +    typedef DefaultMap<_Graph, _Item, int> Parent;
    1.26      
    1.27      std::vector<_Item> array;
    1.28      int sep;
    1.29 @@ -399,12 +399,13 @@
    1.30    /// \param _Graph The graph type.
    1.31    /// \param _Item One of the graph's item type, the key of the map.
    1.32    template <typename _Graph, typename _Item>
    1.33 -  class IterableIntMap : protected ItemSetTraits<_Graph, _Item> 
    1.34 -  ::template Map<_iterable_maps_bits::IterableIntMapNode<_Item> >::Parent {
    1.35 +  class IterableIntMap 
    1.36 +    : protected DefaultMap<_Graph, _Item, _iterable_maps_bits::
    1.37 +                           IterableIntMapNode<_Item> > {
    1.38    public:
    1.39 -    typedef typename ItemSetTraits<_Graph, _Item> 
    1.40 -    ::template Map<_iterable_maps_bits::IterableIntMapNode<_Item> >
    1.41 -    ::Parent Parent;
    1.42 +    typedef DefaultMap<_Graph, _Item, _iterable_maps_bits::
    1.43 +                       IterableIntMapNode<_Item> >
    1.44 +    Parent;
    1.45  
    1.46      /// The key type
    1.47      typedef _Item Key;
    1.48 @@ -687,13 +688,12 @@
    1.49    /// \param _Item One of the graph's item type, the key of the map.
    1.50    /// \param _Value Any comparable value type.
    1.51    template <typename _Graph, typename _Item, typename _Value>
    1.52 -  class IterableValueMap : protected ItemSetTraits<_Graph, _Item> 
    1.53 -  ::template Map<_iterable_maps_bits::IterableValueMapNode<_Item, _Value> >
    1.54 -  ::Parent {
    1.55 +  class IterableValueMap 
    1.56 +    : protected DefaultMap<_Graph, _Item, _iterable_maps_bits::
    1.57 +                           IterableValueMapNode<_Item, _Value> > {
    1.58    public:
    1.59 -    typedef typename ItemSetTraits<_Graph, _Item> 
    1.60 -    ::template Map<_iterable_maps_bits::IterableValueMapNode<_Item, _Value> >
    1.61 -    ::Parent Parent;
    1.62 +    typedef DefaultMap<_Graph, _Item, _iterable_maps_bits::
    1.63 +                       IterableValueMapNode<_Item, _Value> > Parent;
    1.64  
    1.65      /// The key type
    1.66      typedef _Item Key;
    1.67 @@ -702,19 +702,25 @@
    1.68      /// The graph type
    1.69      typedef _Graph Graph;
    1.70  
    1.71 +  protected:
    1.72 +
    1.73 +    typedef typename ItemSetTraits<_Graph, Key>::ItemIt KeyIt; 
    1.74 +
    1.75 +  public:
    1.76 +
    1.77      /// \brief Constructor of the Map with a given value.
    1.78      ///
    1.79      /// Constructor of the Map with a given value.
    1.80      explicit IterableValueMap(const Graph& graph, 
    1.81                                const Value& value = Value()) 
    1.82 -      : Parent(graph, _iterable_maps_bits::IterableValueMapNode<_Item, 
    1.83 -               _Value>(value)) {
    1.84 -      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
    1.85 +      : Parent(graph, _iterable_maps_bits::
    1.86 +               IterableValueMapNode<_Item, _Value>(value)) {
    1.87 +      for (KeyIt it(*Parent::getGraph()); it != INVALID; ++it) {
    1.88          lace(it);
    1.89        }
    1.90      }
    1.91  
    1.92 -  private:
    1.93 +  protected:
    1.94      
    1.95      void unlace(const Key& key) {
    1.96        typename Parent::Value& node = Parent::operator[](key);
    1.97 @@ -871,6 +877,18 @@
    1.98  
    1.99    protected:
   1.100      
   1.101 +    virtual void add(const Key& key) {
   1.102 +      Parent::add(key);
   1.103 +      unlace(key);
   1.104 +    }
   1.105 +
   1.106 +    virtual void add(const std::vector<Key>& keys) {
   1.107 +      Parent::add(keys);
   1.108 +      for (int i = 0; i < (int)keys.size(); ++i) {
   1.109 +        lace(keys[i]);
   1.110 +      }
   1.111 +    }
   1.112 +
   1.113      virtual void erase(const Key& key) {
   1.114        unlace(key);
   1.115        Parent::erase(key);
   1.116 @@ -883,6 +901,13 @@
   1.117        Parent::erase(keys);
   1.118      }
   1.119  
   1.120 +    virtual void build() {
   1.121 +      Parent::build();
   1.122 +      for (KeyIt it(*Parent::getGraph()); it != INVALID; ++it) {
   1.123 +        lace(it);
   1.124 +      }
   1.125 +    }
   1.126 +
   1.127      virtual void clear() {
   1.128        first.clear();
   1.129        Parent::clear();