COIN-OR::LEMON - Graph Library

Changeset 1778:4ba7965386fb in lemon-0.x


Ignore:
Timestamp:
11/04/05 20:19:52 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2310
Message:

Some just writeable bool maps.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/maps.h

    r1725 r1778  
    1818#define LEMON_MAPS_H
    1919
     20#include <iterator>
     21
    2022#include <lemon/utility.h>
    2123#include <lemon/traits.h>
     
    843845    typedef typename Parent::Value Value;
    844846
    845     ///Constructor
     847    /// Constructor
    846848    NotMap(const M &_m) : m(_m) {};
    847849    Value operator[](Key k) const {return !m[k];}
     
    857859  }
    858860
     861  /// \brief Writeable bool map for store each true assigned elements.
     862  ///
     863  /// Writeable bool map for store each true assigned elements. It will
     864  /// copies all the true setted keys to the given iterator.
     865  ///
     866  /// \note The container of the iterator should contain for each element.
     867  template <typename _Iterator>
     868  class StoreBoolMap {
     869  public:
     870    typedef _Iterator Iterator;
     871
     872    typedef typename std::iterator_traits<Iterator>::value_type Key;
     873    typedef bool Value;
     874
     875    /// Constructor
     876    StoreBoolMap(Iterator it) : _begin(it), _end(it) {}
     877
     878    /// Gives back the given first setted iterator.
     879    Iterator begin() const {
     880      return _begin;
     881    }
     882 
     883    /// Gives back the iterator after the last setted.
     884    Iterator end() const {
     885      return _end;
     886    }
     887
     888    /// Setter function of the map
     889    void set(const Key& key, Value value) {
     890      if (value) {
     891        *_end++ = key;
     892      }
     893    }
     894   
     895  private:
     896    Iterator _begin, _end;
     897  };
     898
     899  /// \brief Writeable bool map for store each true assigned elements in
     900  /// a back insertable container.
     901  ///
     902  /// Writeable bool map for store each true assigned elements in a back
     903  /// insertable container. It will push back all the true setted keys into
     904  /// the container.
     905  template <typename Container>
     906  class BackInserterBoolMap {
     907  public:
     908    typedef typename Container::value_type Key;
     909    typedef bool Value;
     910
     911    /// Constructor
     912    BackInserterBoolMap(Container& _container) : container(_container) {}
     913
     914    /// Setter function of the map
     915    void set(const Key& key, Value value) {
     916      if (value) {
     917        container.push_back(key);
     918      }
     919    }
     920   
     921  private:
     922    Container& container;   
     923  };
     924
     925  /// \brief Writeable bool map for store each true assigned elements in
     926  /// a front insertable container.
     927  ///
     928  /// Writeable bool map for store each true assigned elements in a front
     929  /// insertable container. It will push front all the true setted keys into
     930  /// the container.
     931  template <typename Container>
     932  class FrontInserterBoolMap {
     933  public:
     934    typedef typename Container::value_type Key;
     935    typedef bool Value;
     936
     937    /// Constructor
     938    FrontInserterBoolMap(Container& _container) : container(_container) {}
     939
     940    /// Setter function of the map
     941    void set(const Key& key, Value value) {
     942      if (value) {
     943        container.push_front(key);
     944      }
     945    }
     946   
     947  private:
     948    Container& container;   
     949  };
     950
     951  /// \brief Writeable bool map for store each true assigned elements in
     952  /// an insertable container.
     953  ///
     954  /// Writeable bool map for store each true assigned elements in an
     955  /// insertable container. It will insert all the true setted keys into
     956  /// the container.
     957  template <typename Container>
     958  class InserterBoolMap {
     959  public:
     960    typedef typename Container::value_type Key;
     961    typedef bool Value;
     962
     963    /// Constructor
     964    InserterBoolMap(Container& _container) : container(_container) {}
     965
     966    /// Setter function of the map
     967    void set(const Key& key, Value value) {
     968      if (value) {
     969        container.insert(key);
     970      }
     971    }
     972   
     973  private:
     974    Container& container;   
     975  };
     976
     977  /// \brief Fill the true setted elements with a given value.
     978  ///
     979  /// Writeable bool map for fill the true setted elements with a given value.
     980  /// The value can be setted
     981  /// the container.
     982  template <typename Map>
     983  class FillBoolMap {
     984  public:
     985    typedef typename Map::Key Key;
     986    typedef bool Value;
     987
     988    /// Constructor
     989    FillBoolMap(Map& _map, const typename Map::Value& _fill)
     990      : map(_map), fill(_fill) {}
     991
     992    /// Constructor
     993    FillBoolMap(Map& _map)
     994      : map(_map), fill() {}
     995
     996    /// Gives back the current fill value
     997    typename Map::Value fillValue() const {
     998      return fill;
     999    }
     1000
     1001    /// Sets the current fill value
     1002    void fillValue(const typename Map::Value& _fill) {
     1003      fill = _fill;
     1004    }
     1005
     1006    /// Setter function of the map
     1007    void set(const Key& key, Value value) {
     1008      if (value) {
     1009        map.set(key, fill);
     1010      }
     1011    }
     1012   
     1013  private:
     1014    Map& map;
     1015    typename Map::Value fill;
     1016  };
     1017
     1018
     1019  /// \brief Writeable bool map which stores for each true assigned elements 
     1020  /// the setting order number.
     1021  ///
     1022  /// Writeable bool map which stores for each true assigned elements 
     1023  /// the setting order number.
     1024  template <typename Map>
     1025  class SettingOrderBoolMap {
     1026  public:
     1027    typedef typename Map::Key Key;
     1028    typedef bool Value;
     1029
     1030    /// Constructor
     1031    SettingOrderBoolMap(Map& _map)
     1032      : map(_map), counter(0) {}
     1033
     1034    /// Number of setted keys.
     1035    int num() const {
     1036      return counter;
     1037    }
     1038
     1039    /// Setter function of the map
     1040    void set(const Key& key, Value value) {
     1041      if (value) {
     1042        map.set(key, counter++);
     1043      }
     1044    }
     1045   
     1046  private:
     1047    Map& map;
     1048    int counter;
     1049  };
     1050
    8591051  /// @}
    8601052}
Note: See TracChangeset for help on using the changeset viewer.