gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Rename StoreBoolMap to LoggerBoolMap (ticket #34).
0 3 0
default
3 files changed with 20 insertions and 20 deletions:
↑ Collapse diff ↑
Ignore white space 48 line context
... ...
@@ -208,49 +208,49 @@
208 208

	
209 209
        std::sort(seq.begin(), seq.end(), PairComp<Sequence>());
210 210
        return KruskalOutputSelector<Graph, Sequence, Out>::
211 211
          kruskal(graph, seq, out);
212 212
      }
213 213
    };
214 214

	
215 215
    template <typename T>
216 216
    struct RemoveConst {
217 217
      typedef T type;
218 218
    };
219 219

	
220 220
    template <typename T>
221 221
    struct RemoveConst<const T> {
222 222
      typedef T type;
223 223
    };
224 224

	
225 225
    template <typename Graph, typename In, typename Out>
226 226
    struct KruskalOutputSelector<Graph, In, Out,
227 227
      typename enable_if<SequenceOutputIndicator<Out>, void>::type > 
228 228
    {
229 229
      typedef typename In::value_type::second_type Value;
230 230

	
231 231
      static Value kruskal(const Graph& graph, const In& in, Out& out) {
232
        typedef StoreBoolMap<typename RemoveConst<Out>::type> Map;
232
        typedef LoggerBoolMap<typename RemoveConst<Out>::type> Map;
233 233
        Map map(out);
234 234
        return _kruskal_bits::kruskal(graph, in, map);
235 235
      }
236 236

	
237 237
    };
238 238

	
239 239
    template <typename Graph, typename In, typename Out>
240 240
    struct KruskalOutputSelector<Graph, In, Out,
241 241
      typename enable_if<MapOutputIndicator<Out>, void>::type > 
242 242
    {
243 243
      typedef typename In::value_type::second_type Value;
244 244

	
245 245
      static Value kruskal(const Graph& graph, const In& in, Out& out) {
246 246
        return _kruskal_bits::kruskal(graph, in, out);
247 247
      }
248 248
    };
249 249

	
250 250
  }
251 251

	
252 252
  /// \ingroup spantree
253 253
  ///
254 254
  /// \brief Kruskal's algorithm to find a minimum cost tree of a graph.
255 255
  ///
256 256
  /// This function runs Kruskal's algorithm to find a minimum cost tree.
Ignore white space 6 line context
... ...
@@ -1679,108 +1679,108 @@
1679 1679
      typedef typename std::iterator_traits<_Iterator>::value_type Value;
1680 1680
    };
1681 1681

	
1682 1682
    template <typename _Iterator>
1683 1683
    struct IteratorTraits<_Iterator,
1684 1684
      typename exists<typename _Iterator::container_type>::type>
1685 1685
    {
1686 1686
      typedef typename _Iterator::container_type::value_type Value;
1687 1687
    };
1688 1688

	
1689 1689
  }
1690 1690

	
1691 1691
  /// \brief Writable bool map for logging each \c true assigned element
1692 1692
  ///
1693 1693
  /// A \ref concepts::WriteMap "writable" bool map for logging
1694 1694
  /// each \c true assigned element, i.e it copies subsequently each
1695 1695
  /// keys set to \c true to the given iterator.
1696 1696
  /// The most important usage of it is storing certain nodes or arcs
1697 1697
  /// that were marked \c true by an algorithm.
1698 1698
  ///
1699 1699
  /// There are several algorithms that provide solutions through bool
1700 1700
  /// maps and most of them assign \c true at most once for each key.
1701 1701
  /// In these cases it is a natural request to store each \c true
1702 1702
  /// assigned elements (in order of the assignment), which can be
1703
  /// easily done with StoreBoolMap.
1703
  /// easily done with LoggerBoolMap.
1704 1704
  ///
1705
  /// The simplest way of using this map is through the storeBoolMap()
1705
  /// The simplest way of using this map is through the loggerBoolMap()
1706 1706
  /// function.
1707 1707
  ///
1708 1708
  /// \tparam It The type of the iterator.
1709 1709
  /// \tparam Ke The key type of the map. The default value set
1710 1710
  /// according to the iterator type should work in most cases.
1711 1711
  ///
1712 1712
  /// \note The container of the iterator must contain enough space
1713 1713
  /// for the elements or the iterator should be an inserter iterator.
1714 1714
#ifdef DOXYGEN
1715 1715
  template <typename It, typename Ke>
1716 1716
#else
1717 1717
  template <typename It,
1718 1718
	    typename Ke=typename _maps_bits::IteratorTraits<It>::Value>
1719 1719
#endif
1720
  class StoreBoolMap {
1720
  class LoggerBoolMap {
1721 1721
  public:
1722 1722
    typedef It Iterator;
1723 1723

	
1724 1724
    typedef Ke Key;
1725 1725
    typedef bool Value;
1726 1726

	
1727 1727
    /// Constructor
1728
    StoreBoolMap(Iterator it)
1728
    LoggerBoolMap(Iterator it)
1729 1729
      : _begin(it), _end(it) {}
1730 1730

	
1731 1731
    /// Gives back the given iterator set for the first key
1732 1732
    Iterator begin() const {
1733 1733
      return _begin;
1734 1734
    }
1735 1735

	
1736 1736
    /// Gives back the the 'after the last' iterator
1737 1737
    Iterator end() const {
1738 1738
      return _end;
1739 1739
    }
1740 1740

	
1741 1741
    /// The set function of the map
1742 1742
    void set(const Key& key, Value value) {
1743 1743
      if (value) {
1744 1744
	*_end++ = key;
1745 1745
      }
1746 1746
    }
1747 1747

	
1748 1748
  private:
1749 1749
    Iterator _begin;
1750 1750
    Iterator _end;
1751 1751
  };
1752 1752
  
1753
  /// Returns a \ref StoreBoolMap class
1753
  /// Returns a \ref LoggerBoolMap class
1754 1754

	
1755
  /// This function just returns a \ref StoreBoolMap class.
1755
  /// This function just returns a \ref LoggerBoolMap class.
1756 1756
  ///
1757 1757
  /// The most important usage of it is storing certain nodes or arcs
1758 1758
  /// that were marked \c true by an algorithm.
1759 1759
  /// For example it makes easier to store the nodes in the processing
1760 1760
  /// order of Dfs algorithm, as the following examples show.
1761 1761
  /// \code
1762 1762
  ///   std::vector<Node> v;
1763
  ///   dfs(g,s).processedMap(storeBoolMap(std::back_inserter(v))).run();
1763
  ///   dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
1764 1764
  /// \endcode
1765 1765
  /// \code
1766 1766
  ///   std::vector<Node> v(countNodes(g));
1767
  ///   dfs(g,s).processedMap(storeBoolMap(v.begin())).run();
1767
  ///   dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
1768 1768
  /// \endcode
1769 1769
  ///
1770 1770
  /// \note The container of the iterator must contain enough space
1771 1771
  /// for the elements or the iterator should be an inserter iterator.
1772 1772
  ///
1773
  /// \note StoreBoolMap is just \ref concepts::WriteMap "writable", so
1773
  /// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so
1774 1774
  /// it cannot be used when a readable map is needed, for example as
1775
  /// \c ReachedMap for Bfs, Dfs and Dijkstra algorithms.
1775
  /// \c ReachedMap for \ref Bfs, \ref Dfs and \ref Dijkstra algorithms.
1776 1776
  ///
1777
  /// \relates StoreBoolMap
1777
  /// \relates LoggerBoolMap
1778 1778
  template<typename Iterator>
1779
  inline StoreBoolMap<Iterator> storeBoolMap(Iterator it) {
1780
    return StoreBoolMap<Iterator>(it);
1779
  inline LoggerBoolMap<Iterator> loggerBoolMap(Iterator it) {
1780
    return LoggerBoolMap<Iterator>(it);
1781 1781
  }
1782 1782

	
1783 1783
  /// @}
1784 1784
}
1785 1785

	
1786 1786
#endif // LEMON_MAPS_H
Ignore white space 6 line context
... ...
@@ -284,48 +284,48 @@
284 284
    checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
285 285
    checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
286 286
    checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
287 287

	
288 288
    TrueMap<int> tm;
289 289
    FalseMap<int> fm;
290 290
    RangeMap<bool> rm(2);
291 291
    rm[0] = true; rm[1] = false;
292 292
    check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] && !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
293 293
          "Something is wrong with AndMap");
294 294
    check(orMap(tm,rm)[0] && orMap(tm,rm)[1] && orMap(fm,rm)[0] && !orMap(fm,rm)[1],
295 295
          "Something is wrong with OrMap");
296 296
    check(!notMap(rm)[0] && notMap(rm)[1], "Something is wrong with NotMap");
297 297
    check(!notWriteMap(rm)[0] && notWriteMap(rm)[1], "Something is wrong with NotWriteMap");
298 298

	
299 299
    ConstMap<int, double> cm(2.0);
300 300
    IdentityMap<int> im;
301 301
    ConvertMap<IdentityMap<int>, double> id(im);
302 302
    check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
303 303
          "Something is wrong with LessMap");
304 304
    check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
305 305
          "Something is wrong with EqualMap");
306 306
  }
307 307
  
308
  // StoreBoolMap
308
  // LoggerBoolMap
309 309
  {
310 310
    typedef std::vector<int> vec;
311 311
    vec v1;
312 312
    vec v2(10);
313
    StoreBoolMap<std::back_insert_iterator<vec> > map1(std::back_inserter(v1));
314
    StoreBoolMap<vec::iterator> map2(v2.begin());
313
    LoggerBoolMap<std::back_insert_iterator<vec> > map1(std::back_inserter(v1));
314
    LoggerBoolMap<vec::iterator> map2(v2.begin());
315 315
    map1.set(10, false);
316 316
    map1.set(20, true);   map2.set(20, true);
317 317
    map1.set(30, false);  map2.set(40, false);
318 318
    map1.set(50, true);   map2.set(50, true);
319 319
    map1.set(60, true);   map2.set(60, true);
320 320
    check(v1.size() == 3 && v2.size() == 10 &&
321 321
          v1[0]==20 && v1[1]==50 && v1[2]==60 && v2[0]==20 && v2[1]==50 && v2[2]==60,
322
          "Something is wrong with StoreBoolMap");
322
          "Something is wrong with LoggerBoolMap");
323 323
          
324 324
    int i = 0;
325
    for ( StoreBoolMap<vec::iterator>::Iterator it = map2.begin();
325
    for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
326 326
          it != map2.end(); ++it )
327
      check(v1[i++] == *it, "Something is wrong with StoreBoolMap");
327
      check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
328 328
  }
329 329

	
330 330
  return 0;
331 331
}
0 comments (0 inline)