COIN-OR::LEMON - Graph Library

Changeset 1805:d284f81f02a5 in lemon-0.x


Ignore:
Timestamp:
11/16/05 14:19:05 (18 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2348
Message:

Iterable Bool maps can count the number of true and false values.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/iterable_maps.h

    r1759 r1805  
    3131 
    3232  ///\todo This is only a static map!
     33  ///\todo Undocumented.
    3334  ///\param BaseMap is an interger map.
    3435  template<class BaseMap>
     
    6465    ///\e
    6566    void set(Key k,Value v) { if(v) setTrue(k); else setFalse(k);}
     67    ///Number of \c true items in the map
     68
     69    ///Returns the number of \c true values in the map.
     70    ///This is a constant time operation.
     71    int countTrue() { return vals.size()-sep; }
     72    ///Number of \c false items in the map
     73
     74    ///Returns the number of \c false values in the map.
     75    ///This is a constant time operation.
     76    int countFalse() { return sep; }
    6677
    6778    ///\e
     
    7182      int i;
    7283    public:
     84      ///\e
    7385      explicit FalseIt(const IterableBoolMap &_M) : M(_M), i(0) { }
     86      ///\e
    7487      FalseIt(Invalid)
    7588        : M(*((IterableBoolMap*)(0))), i(std::numeric_limits<int>::max()) { }
     89      ///\e
    7690      FalseIt &operator++() { ++i; return *this;}
     91      ///\e
    7792      operator Key() const { return i<M.sep ? M.vals[i] : INVALID; }
     93      ///\e
    7894      bool operator !=(Invalid) const { return i<M.sep; }
     95      ///\e
    7996      bool operator ==(Invalid) const { return i>=M.sep; }
    8097    };
     
    85102      int i;
    86103    public:
     104      ///\e
    87105      explicit TrueIt(const IterableBoolMap &_M)
    88106        : M(_M), i(M.vals.size()-1) { }
     107      ///\e
    89108      TrueIt(Invalid)
    90109        : M(*((IterableBoolMap*)(0))), i(-1) { }
     110      ///\e
    91111      TrueIt &operator++() { --i; return *this;}
     112      ///\e
    92113      operator Key() const { return i>=M.sep ? M.vals[i] : INVALID; }
     114      ///\e
    93115      bool operator !=(Invalid) const { return i>=M.sep; }
     116      ///\e
    94117      bool operator ==(Invalid) const { return i<M.sep; }
    95118    };
     
    123146      if(init) sep=0;
    124147    }
     148    ///\e
    125149    RefType operator[] (Key k) { return RefType(*this,k);} 
     150    ///\e
    126151    Value operator[] (Key k) const { return isTrue(k);} 
    127152  };
     
    164189    ///\e
    165190    void set(Key k, bool v) { imap.set(k,v);}
     191    ///Number of \c true items in the map
     192
     193    ///Returns the number of \c true values in the map.
     194    ///This is a constant time operation.
     195    int countTrue() { return imap.countTrue(); }
     196    ///Number of \c false items in the map
     197
     198    ///Returns the number of \c false values in the map.
     199    ///This is a constant time operation.
     200    int countFalse() { return imap.countFalse(); }
    166201#ifdef DOXYGEN
    167202    ///\e
     
    177212    {
    178213    public:
     214      ///\e
    179215      explicit FalseIt(const IterableBoolNodeMap &m)
    180216        : BimType::FalseIt(m.imap) { }
     217      ///\e
    181218      FalseIt(Invalid i) : BimType::FalseIt(i) { }
    182219    };
     
    185222    {
    186223    public:
     224      ///\e
    187225      explicit TrueIt(const IterableBoolNodeMap &m)
    188226        : BimType::TrueIt(m.imap) { }
     227      ///\e
    189228      TrueIt(Invalid i) : BimType::TrueIt(i) { }
    190229    }; 
     
    222261    ///\e
    223262    void set(Key k, bool v) { imap.set(k,v);}
     263    ///Returns the number of \c true values in the map.
     264    ///This is a constant time operation.
     265    int countTrue() { return imap.countTrue(); }
     266    ///Number of \c false items in the map
     267
     268    ///Returns the number of \c false values in the map.
     269    ///This is a constant time operation.
     270    int countFalse() { return imap.countFalse(); }
    224271#ifdef DOXYGEN
    225272    ///\e
     
    235282    {
    236283    public:
     284      ///\e
    237285      explicit FalseIt(const IterableBoolEdgeMap &m)
    238286        : BimType::FalseIt(m.imap) { }
     287      ///\e
    239288      FalseIt(Invalid i) : BimType::FalseIt(i) { }
    240289    };
     
    243292    {
    244293    public:
     294      ///\e
    245295      explicit TrueIt(const IterableBoolEdgeMap &m)
    246296        : BimType::TrueIt(m.imap) { }
     297      ///\e
    247298      TrueIt(Invalid i) : BimType::TrueIt(i) { }
    248299    }; 
Note: See TracChangeset for help on using the changeset viewer.