gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
DescriptorMap->RangeIdMap, InvertableMap->CrossRefMap (#160)
0 2 0
default
2 files changed with 44 insertions and 45 deletions:
↑ Collapse diff ↑
Ignore white space 384 line context
... ...
@@ -1643,851 +1643,850 @@
1643 1643
  template<typename M1, typename M2>
1644 1644
  inline EqualMap<M1, M2> equalMap(const M1 &m1, const M2 &m2) {
1645 1645
    return EqualMap<M1, M2>(m1,m2);
1646 1646
  }
1647 1647

	
1648 1648

	
1649 1649
  /// Combination of two maps using the \c < operator
1650 1650

	
1651 1651
  /// This \ref concepts::ReadMap "read-only map" assigns \c true to
1652 1652
  /// the keys for which the corresponding value of the first map is
1653 1653
  /// less then the value of the second map.
1654 1654
  /// Its \c Key type is inherited from \c M1 and its \c Value type is
1655 1655
  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
1656 1656
  ///
1657 1657
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
1658 1658
  /// \code
1659 1659
  ///   LessMap<M1,M2> lm(m1,m2);
1660 1660
  /// \endcode
1661 1661
  /// <tt>lm[x]</tt> will be equal to <tt>m1[x]<m2[x]</tt>.
1662 1662
  ///
1663 1663
  /// The simplest way of using this map is through the lessMap()
1664 1664
  /// function.
1665 1665
  ///
1666 1666
  /// \sa EqualMap
1667 1667
  template<typename M1, typename M2>
1668 1668
  class LessMap : public MapBase<typename M1::Key, bool> {
1669 1669
    const M1 &_m1;
1670 1670
    const M2 &_m2;
1671 1671
  public:
1672 1672
    ///\e
1673 1673
    typedef typename M1::Key Key;
1674 1674
    ///\e
1675 1675
    typedef bool Value;
1676 1676

	
1677 1677
    /// Constructor
1678 1678
    LessMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1679 1679
    ///\e
1680 1680
    Value operator[](const Key &k) const { return _m1[k]<_m2[k]; }
1681 1681
  };
1682 1682

	
1683 1683
  /// Returns an \c LessMap class
1684 1684

	
1685 1685
  /// This function just returns an \c LessMap class.
1686 1686
  ///
1687 1687
  /// For example, if \c m1 and \c m2 are maps with keys and values of
1688 1688
  /// the same type, then <tt>lessMap(m1,m2)[x]</tt> will be equal to
1689 1689
  /// <tt>m1[x]<m2[x]</tt>.
1690 1690
  ///
1691 1691
  /// \relates LessMap
1692 1692
  template<typename M1, typename M2>
1693 1693
  inline LessMap<M1, M2> lessMap(const M1 &m1, const M2 &m2) {
1694 1694
    return LessMap<M1, M2>(m1,m2);
1695 1695
  }
1696 1696

	
1697 1697
  namespace _maps_bits {
1698 1698

	
1699 1699
    template <typename _Iterator, typename Enable = void>
1700 1700
    struct IteratorTraits {
1701 1701
      typedef typename std::iterator_traits<_Iterator>::value_type Value;
1702 1702
    };
1703 1703

	
1704 1704
    template <typename _Iterator>
1705 1705
    struct IteratorTraits<_Iterator,
1706 1706
      typename exists<typename _Iterator::container_type>::type>
1707 1707
    {
1708 1708
      typedef typename _Iterator::container_type::value_type Value;
1709 1709
    };
1710 1710

	
1711 1711
  }
1712 1712

	
1713 1713
  /// @}
1714 1714

	
1715 1715
  /// \addtogroup maps
1716 1716
  /// @{
1717 1717

	
1718 1718
  /// \brief Writable bool map for logging each \c true assigned element
1719 1719
  ///
1720 1720
  /// A \ref concepts::WriteMap "writable" bool map for logging
1721 1721
  /// each \c true assigned element, i.e it copies subsequently each
1722 1722
  /// keys set to \c true to the given iterator.
1723 1723
  /// The most important usage of it is storing certain nodes or arcs
1724 1724
  /// that were marked \c true by an algorithm.
1725 1725
  ///
1726 1726
  /// There are several algorithms that provide solutions through bool
1727 1727
  /// maps and most of them assign \c true at most once for each key.
1728 1728
  /// In these cases it is a natural request to store each \c true
1729 1729
  /// assigned elements (in order of the assignment), which can be
1730 1730
  /// easily done with LoggerBoolMap.
1731 1731
  ///
1732 1732
  /// The simplest way of using this map is through the loggerBoolMap()
1733 1733
  /// function.
1734 1734
  ///
1735 1735
  /// \tparam IT The type of the iterator.
1736 1736
  /// \tparam KEY The key type of the map. The default value set
1737 1737
  /// according to the iterator type should work in most cases.
1738 1738
  ///
1739 1739
  /// \note The container of the iterator must contain enough space
1740 1740
  /// for the elements or the iterator should be an inserter iterator.
1741 1741
#ifdef DOXYGEN
1742 1742
  template <typename IT, typename KEY>
1743 1743
#else
1744 1744
  template <typename IT,
1745 1745
            typename KEY = typename _maps_bits::IteratorTraits<IT>::Value>
1746 1746
#endif
1747 1747
  class LoggerBoolMap : public MapBase<KEY, bool> {
1748 1748
  public:
1749 1749

	
1750 1750
    ///\e
1751 1751
    typedef KEY Key;
1752 1752
    ///\e
1753 1753
    typedef bool Value;
1754 1754
    ///\e
1755 1755
    typedef IT Iterator;
1756 1756

	
1757 1757
    /// Constructor
1758 1758
    LoggerBoolMap(Iterator it)
1759 1759
      : _begin(it), _end(it) {}
1760 1760

	
1761 1761
    /// Gives back the given iterator set for the first key
1762 1762
    Iterator begin() const {
1763 1763
      return _begin;
1764 1764
    }
1765 1765

	
1766 1766
    /// Gives back the the 'after the last' iterator
1767 1767
    Iterator end() const {
1768 1768
      return _end;
1769 1769
    }
1770 1770

	
1771 1771
    /// The set function of the map
1772 1772
    void set(const Key& key, Value value) {
1773 1773
      if (value) {
1774 1774
        *_end++ = key;
1775 1775
      }
1776 1776
    }
1777 1777

	
1778 1778
  private:
1779 1779
    Iterator _begin;
1780 1780
    Iterator _end;
1781 1781
  };
1782 1782

	
1783 1783
  /// Returns a \c LoggerBoolMap class
1784 1784

	
1785 1785
  /// This function just returns a \c LoggerBoolMap class.
1786 1786
  ///
1787 1787
  /// The most important usage of it is storing certain nodes or arcs
1788 1788
  /// that were marked \c true by an algorithm.
1789 1789
  /// For example it makes easier to store the nodes in the processing
1790 1790
  /// order of Dfs algorithm, as the following examples show.
1791 1791
  /// \code
1792 1792
  ///   std::vector<Node> v;
1793 1793
  ///   dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
1794 1794
  /// \endcode
1795 1795
  /// \code
1796 1796
  ///   std::vector<Node> v(countNodes(g));
1797 1797
  ///   dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
1798 1798
  /// \endcode
1799 1799
  ///
1800 1800
  /// \note The container of the iterator must contain enough space
1801 1801
  /// for the elements or the iterator should be an inserter iterator.
1802 1802
  ///
1803 1803
  /// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so
1804 1804
  /// it cannot be used when a readable map is needed, for example as
1805 1805
  /// \c ReachedMap for \c Bfs, \c Dfs and \c Dijkstra algorithms.
1806 1806
  ///
1807 1807
  /// \relates LoggerBoolMap
1808 1808
  template<typename Iterator>
1809 1809
  inline LoggerBoolMap<Iterator> loggerBoolMap(Iterator it) {
1810 1810
    return LoggerBoolMap<Iterator>(it);
1811 1811
  }
1812 1812

	
1813 1813
  /// @}
1814 1814

	
1815 1815
  /// \addtogroup graph_maps
1816 1816
  /// @{
1817 1817

	
1818 1818
  /// \brief Provides an immutable and unique id for each item in a graph.
1819 1819
  ///
1820 1820
  /// IdMap provides a unique and immutable id for each item of the
1821 1821
  /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is 
1822 1822
  ///  - \b unique: different items get different ids,
1823 1823
  ///  - \b immutable: the id of an item does not change (even if you
1824 1824
  ///    delete other nodes).
1825 1825
  ///
1826 1826
  /// Using this map you get access (i.e. can read) the inner id values of
1827 1827
  /// the items stored in the graph, which is returned by the \c id()
1828 1828
  /// function of the graph. This map can be inverted with its member
1829 1829
  /// class \c InverseMap or with the \c operator() member.
1830 1830
  ///
1831 1831
  /// \tparam GR The graph type.
1832 1832
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1833 1833
  /// \c GR::Edge).
1834 1834
  ///
1835
  /// \see DescriptorMap
1835
  /// \see RangeIdMap
1836 1836
  template <typename GR, typename K>
1837 1837
  class IdMap : public MapBase<K, int> {
1838 1838
  public:
1839 1839
    /// The graph type of IdMap.
1840 1840
    typedef GR Graph;
1841 1841
    /// The key type of IdMap (\c Node, \c Arc or \c Edge).
1842 1842
    typedef K Item;
1843 1843
    /// The key type of IdMap (\c Node, \c Arc or \c Edge).
1844 1844
    typedef K Key;
1845 1845
    /// The value type of IdMap.
1846 1846
    typedef int Value;
1847 1847

	
1848 1848
    /// \brief Constructor.
1849 1849
    ///
1850 1850
    /// Constructor of the map.
1851 1851
    explicit IdMap(const Graph& graph) : _graph(&graph) {}
1852 1852

	
1853 1853
    /// \brief Gives back the \e id of the item.
1854 1854
    ///
1855 1855
    /// Gives back the immutable and unique \e id of the item.
1856 1856
    int operator[](const Item& item) const { return _graph->id(item);}
1857 1857

	
1858 1858
    /// \brief Gives back the \e item by its id.
1859 1859
    ///
1860 1860
    /// Gives back the \e item by its id.
1861 1861
    Item operator()(int id) { return _graph->fromId(id, Item()); }
1862 1862

	
1863 1863
  private:
1864 1864
    const Graph* _graph;
1865 1865

	
1866 1866
  public:
1867 1867

	
1868 1868
    /// \brief This class represents the inverse of its owner (IdMap).
1869 1869
    ///
1870 1870
    /// This class represents the inverse of its owner (IdMap).
1871 1871
    /// \see inverse()
1872 1872
    class InverseMap {
1873 1873
    public:
1874 1874

	
1875 1875
      /// \brief Constructor.
1876 1876
      ///
1877 1877
      /// Constructor for creating an id-to-item map.
1878 1878
      explicit InverseMap(const Graph& graph) : _graph(&graph) {}
1879 1879

	
1880 1880
      /// \brief Constructor.
1881 1881
      ///
1882 1882
      /// Constructor for creating an id-to-item map.
1883 1883
      explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
1884 1884

	
1885 1885
      /// \brief Gives back the given item from its id.
1886 1886
      ///
1887 1887
      /// Gives back the given item from its id.
1888 1888
      Item operator[](int id) const { return _graph->fromId(id, Item());}
1889 1889

	
1890 1890
    private:
1891 1891
      const Graph* _graph;
1892 1892
    };
1893 1893

	
1894 1894
    /// \brief Gives back the inverse of the map.
1895 1895
    ///
1896 1896
    /// Gives back the inverse of the IdMap.
1897 1897
    InverseMap inverse() const { return InverseMap(*_graph);}
1898 1898
  };
1899 1899

	
1900 1900

	
1901
  /// \brief General invertable graph map type.
1901
  /// \brief General cross reference graph map type.
1902 1902

	
1903 1903
  /// This class provides simple invertable graph maps.
1904 1904
  /// It wraps an arbitrary \ref concepts::ReadWriteMap "ReadWriteMap"
1905 1905
  /// and if a key is set to a new value then store it
1906 1906
  /// in the inverse map.
1907 1907
  ///
1908 1908
  /// The values of the map can be accessed
1909 1909
  /// with stl compatible forward iterator.
1910 1910
  ///
1911 1911
  /// \tparam GR The graph type.
1912 1912
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1913 1913
  /// \c GR::Edge).
1914 1914
  /// \tparam V The value type of the map.
1915 1915
  ///
1916 1916
  /// \see IterableValueMap
1917 1917
  template <typename GR, typename K, typename V>
1918
  class InvertableMap
1918
  class CrossRefMap
1919 1919
    : protected ItemSetTraits<GR, K>::template Map<V>::Type {
1920 1920
  private:
1921 1921

	
1922 1922
    typedef typename ItemSetTraits<GR, K>::
1923 1923
      template Map<V>::Type Map;
1924 1924

	
1925 1925
    typedef std::map<V, K> Container;
1926 1926
    Container _inv_map;
1927 1927

	
1928 1928
  public:
1929 1929

	
1930
    /// The graph type of InvertableMap.
1930
    /// The graph type of CrossRefMap.
1931 1931
    typedef GR Graph;
1932
    /// The key type of InvertableMap (\c Node, \c Arc or \c Edge).
1932
    /// The key type of CrossRefMap (\c Node, \c Arc or \c Edge).
1933 1933
    typedef K Item;
1934
    /// The key type of InvertableMap (\c Node, \c Arc or \c Edge).
1934
    /// The key type of CrossRefMap (\c Node, \c Arc or \c Edge).
1935 1935
    typedef K Key;
1936
    /// The value type of InvertableMap.
1936
    /// The value type of CrossRefMap.
1937 1937
    typedef V Value;
1938 1938

	
1939 1939
    /// \brief Constructor.
1940 1940
    ///
1941
    /// Construct a new InvertableMap for the given graph.
1942
    explicit InvertableMap(const Graph& graph) : Map(graph) {}
1941
    /// Construct a new CrossRefMap for the given graph.
1942
    explicit CrossRefMap(const Graph& graph) : Map(graph) {}
1943 1943

	
1944 1944
    /// \brief Forward iterator for values.
1945 1945
    ///
1946 1946
    /// This iterator is an stl compatible forward
1947 1947
    /// iterator on the values of the map. The values can
1948 1948
    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
1949 1949
    class ValueIterator
1950 1950
      : public std::iterator<std::forward_iterator_tag, Value> {
1951
      friend class InvertableMap;
1951
      friend class CrossRefMap;
1952 1952
    private:
1953 1953
      ValueIterator(typename Container::const_iterator _it)
1954 1954
        : it(_it) {}
1955 1955
    public:
1956 1956

	
1957 1957
      ValueIterator() {}
1958 1958

	
1959 1959
      ValueIterator& operator++() { ++it; return *this; }
1960 1960
      ValueIterator operator++(int) {
1961 1961
        ValueIterator tmp(*this);
1962 1962
        operator++();
1963 1963
        return tmp;
1964 1964
      }
1965 1965

	
1966 1966
      const Value& operator*() const { return it->first; }
1967 1967
      const Value* operator->() const { return &(it->first); }
1968 1968

	
1969 1969
      bool operator==(ValueIterator jt) const { return it == jt.it; }
1970 1970
      bool operator!=(ValueIterator jt) const { return it != jt.it; }
1971 1971

	
1972 1972
    private:
1973 1973
      typename Container::const_iterator it;
1974 1974
    };
1975 1975

	
1976 1976
    /// \brief Returns an iterator to the first value.
1977 1977
    ///
1978 1978
    /// Returns an stl compatible iterator to the
1979 1979
    /// first value of the map. The values of the
1980 1980
    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
1981 1981
    /// range.
1982 1982
    ValueIterator beginValue() const {
1983 1983
      return ValueIterator(_inv_map.begin());
1984 1984
    }
1985 1985

	
1986 1986
    /// \brief Returns an iterator after the last value.
1987 1987
    ///
1988 1988
    /// Returns an stl compatible iterator after the
1989 1989
    /// last value of the map. The values of the
1990 1990
    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
1991 1991
    /// range.
1992 1992
    ValueIterator endValue() const {
1993 1993
      return ValueIterator(_inv_map.end());
1994 1994
    }
1995 1995

	
1996 1996
    /// \brief Sets the value associated with the given key.
1997 1997
    ///
1998 1998
    /// Sets the value associated with the given key.
1999 1999
    void set(const Key& key, const Value& val) {
2000 2000
      Value oldval = Map::operator[](key);
2001 2001
      typename Container::iterator it = _inv_map.find(oldval);
2002 2002
      if (it != _inv_map.end() && it->second == key) {
2003 2003
        _inv_map.erase(it);
2004 2004
      }
2005 2005
      _inv_map.insert(make_pair(val, key));
2006 2006
      Map::set(key, val);
2007 2007
    }
2008 2008

	
2009 2009
    /// \brief Returns the value associated with the given key.
2010 2010
    ///
2011 2011
    /// Returns the value associated with the given key.
2012 2012
    typename MapTraits<Map>::ConstReturnValue
2013 2013
    operator[](const Key& key) const {
2014 2014
      return Map::operator[](key);
2015 2015
    }
2016 2016

	
2017 2017
    /// \brief Gives back the item by its value.
2018 2018
    ///
2019 2019
    /// Gives back the item by its value.
2020 2020
    Key operator()(const Value& key) const {
2021 2021
      typename Container::const_iterator it = _inv_map.find(key);
2022 2022
      return it != _inv_map.end() ? it->second : INVALID;
2023 2023
    }
2024 2024

	
2025 2025
  protected:
2026 2026

	
2027 2027
    /// \brief Erase the key from the map and the inverse map.
2028 2028
    ///
2029 2029
    /// Erase the key from the map and the inverse map. It is called by the
2030 2030
    /// \c AlterationNotifier.
2031 2031
    virtual void erase(const Key& key) {
2032 2032
      Value val = Map::operator[](key);
2033 2033
      typename Container::iterator it = _inv_map.find(val);
2034 2034
      if (it != _inv_map.end() && it->second == key) {
2035 2035
        _inv_map.erase(it);
2036 2036
      }
2037 2037
      Map::erase(key);
2038 2038
    }
2039 2039

	
2040 2040
    /// \brief Erase more keys from the map and the inverse map.
2041 2041
    ///
2042 2042
    /// Erase more keys from the map and the inverse map. It is called by the
2043 2043
    /// \c AlterationNotifier.
2044 2044
    virtual void erase(const std::vector<Key>& keys) {
2045 2045
      for (int i = 0; i < int(keys.size()); ++i) {
2046 2046
        Value val = Map::operator[](keys[i]);
2047 2047
        typename Container::iterator it = _inv_map.find(val);
2048 2048
        if (it != _inv_map.end() && it->second == keys[i]) {
2049 2049
          _inv_map.erase(it);
2050 2050
        }
2051 2051
      }
2052 2052
      Map::erase(keys);
2053 2053
    }
2054 2054

	
2055 2055
    /// \brief Clear the keys from the map and the inverse map.
2056 2056
    ///
2057 2057
    /// Clear the keys from the map and the inverse map. It is called by the
2058 2058
    /// \c AlterationNotifier.
2059 2059
    virtual void clear() {
2060 2060
      _inv_map.clear();
2061 2061
      Map::clear();
2062 2062
    }
2063 2063

	
2064 2064
  public:
2065 2065

	
2066 2066
    /// \brief The inverse map type.
2067 2067
    ///
2068 2068
    /// The inverse of this map. The subscript operator of the map
2069 2069
    /// gives back the item that was last assigned to the value.
2070 2070
    class InverseMap {
2071 2071
    public:
2072 2072
      /// \brief Constructor
2073 2073
      ///
2074 2074
      /// Constructor of the InverseMap.
2075
      explicit InverseMap(const InvertableMap& inverted)
2075
      explicit InverseMap(const CrossRefMap& inverted)
2076 2076
        : _inverted(inverted) {}
2077 2077

	
2078 2078
      /// The value type of the InverseMap.
2079
      typedef typename InvertableMap::Key Value;
2079
      typedef typename CrossRefMap::Key Value;
2080 2080
      /// The key type of the InverseMap.
2081
      typedef typename InvertableMap::Value Key;
2081
      typedef typename CrossRefMap::Value Key;
2082 2082

	
2083 2083
      /// \brief Subscript operator.
2084 2084
      ///
2085 2085
      /// Subscript operator. It gives back the item
2086 2086
      /// that was last assigned to the given value.
2087 2087
      Value operator[](const Key& key) const {
2088 2088
        return _inverted(key);
2089 2089
      }
2090 2090

	
2091 2091
    private:
2092
      const InvertableMap& _inverted;
2092
      const CrossRefMap& _inverted;
2093 2093
    };
2094 2094

	
2095 2095
    /// \brief It gives back the read-only inverse map.
2096 2096
    ///
2097 2097
    /// It gives back the read-only inverse map.
2098 2098
    InverseMap inverse() const {
2099 2099
      return InverseMap(*this);
2100 2100
    }
2101 2101

	
2102 2102
  };
2103 2103

	
2104
  /// \brief Provides a mutable, continuous and unique descriptor for each
2105
  /// item in a graph.
2104
  /// \brief Provides continuous and unique ID for the
2105
  /// items of a graph.
2106 2106
  ///
2107
  /// DescriptorMap provides a unique and continuous (but mutable)
2108
  /// descriptor (id) for each item of the same type (\c Node, \c Arc or
2107
  /// RangeIdMap provides a unique and continuous
2108
  /// ID for each item of a given type (\c Node, \c Arc or
2109 2109
  /// \c Edge) in a graph. This id is
2110 2110
  ///  - \b unique: different items get different ids,
2111 2111
  ///  - \b continuous: the range of the ids is the set of integers
2112 2112
  ///    between 0 and \c n-1, where \c n is the number of the items of
2113
  ///    this type (\c Node, \c Arc or \c Edge). So the id of an item can
2114
  ///    change if you delete an other item of the same type, i.e. this
2115
  ///    id is mutable.
2113
  ///    this type (\c Node, \c Arc or \c Edge).
2114
  ///  - So, the ids can change when deleting an item of the same type.
2116 2115
  ///
2117 2116
  /// Thus this id is not (necessarily) the same as what can get using
2118 2117
  /// the \c id() function of the graph or \ref IdMap.
2119 2118
  /// This map can be inverted with its member class \c InverseMap,
2120 2119
  /// or with the \c operator() member.
2121 2120
  ///
2122 2121
  /// \tparam GR The graph type.
2123 2122
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
2124 2123
  /// \c GR::Edge).
2125 2124
  ///
2126 2125
  /// \see IdMap
2127 2126
  template <typename GR, typename K>
2128
  class DescriptorMap
2127
  class RangeIdMap
2129 2128
    : protected ItemSetTraits<GR, K>::template Map<int>::Type {
2130 2129

	
2131 2130
    typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Map;
2132 2131

	
2133 2132
  public:
2134
    /// The graph type of DescriptorMap.
2133
    /// The graph type of RangeIdMap.
2135 2134
    typedef GR Graph;
2136
    /// The key type of DescriptorMap (\c Node, \c Arc or \c Edge).
2135
    /// The key type of RangeIdMap (\c Node, \c Arc or \c Edge).
2137 2136
    typedef K Item;
2138
    /// The key type of DescriptorMap (\c Node, \c Arc or \c Edge).
2137
    /// The key type of RangeIdMap (\c Node, \c Arc or \c Edge).
2139 2138
    typedef K Key;
2140
    /// The value type of DescriptorMap.
2139
    /// The value type of RangeIdMap.
2141 2140
    typedef int Value;
2142 2141

	
2143 2142
    /// \brief Constructor.
2144 2143
    ///
2145
    /// Constructor for descriptor map.
2146
    explicit DescriptorMap(const Graph& gr) : Map(gr) {
2144
    /// Constructor.
2145
    explicit RangeIdMap(const Graph& gr) : Map(gr) {
2147 2146
      Item it;
2148 2147
      const typename Map::Notifier* nf = Map::notifier();
2149 2148
      for (nf->first(it); it != INVALID; nf->next(it)) {
2150 2149
        Map::set(it, _inv_map.size());
2151 2150
        _inv_map.push_back(it);
2152 2151
      }
2153 2152
    }
2154 2153

	
2155 2154
  protected:
2156 2155

	
2157 2156
    /// \brief Adds a new key to the map.
2158 2157
    ///
2159 2158
    /// Add a new key to the map. It is called by the
2160 2159
    /// \c AlterationNotifier.
2161 2160
    virtual void add(const Item& item) {
2162 2161
      Map::add(item);
2163 2162
      Map::set(item, _inv_map.size());
2164 2163
      _inv_map.push_back(item);
2165 2164
    }
2166 2165

	
2167 2166
    /// \brief Add more new keys to the map.
2168 2167
    ///
2169 2168
    /// Add more new keys to the map. It is called by the
2170 2169
    /// \c AlterationNotifier.
2171 2170
    virtual void add(const std::vector<Item>& items) {
2172 2171
      Map::add(items);
2173 2172
      for (int i = 0; i < int(items.size()); ++i) {
2174 2173
        Map::set(items[i], _inv_map.size());
2175 2174
        _inv_map.push_back(items[i]);
2176 2175
      }
2177 2176
    }
2178 2177

	
2179 2178
    /// \brief Erase the key from the map.
2180 2179
    ///
2181 2180
    /// Erase the key from the map. It is called by the
2182 2181
    /// \c AlterationNotifier.
2183 2182
    virtual void erase(const Item& item) {
2184 2183
      Map::set(_inv_map.back(), Map::operator[](item));
2185 2184
      _inv_map[Map::operator[](item)] = _inv_map.back();
2186 2185
      _inv_map.pop_back();
2187 2186
      Map::erase(item);
2188 2187
    }
2189 2188

	
2190 2189
    /// \brief Erase more keys from the map.
2191 2190
    ///
2192 2191
    /// Erase more keys from the map. It is called by the
2193 2192
    /// \c AlterationNotifier.
2194 2193
    virtual void erase(const std::vector<Item>& items) {
2195 2194
      for (int i = 0; i < int(items.size()); ++i) {
2196 2195
        Map::set(_inv_map.back(), Map::operator[](items[i]));
2197 2196
        _inv_map[Map::operator[](items[i])] = _inv_map.back();
2198 2197
        _inv_map.pop_back();
2199 2198
      }
2200 2199
      Map::erase(items);
2201 2200
    }
2202 2201

	
2203 2202
    /// \brief Build the unique map.
2204 2203
    ///
2205 2204
    /// Build the unique map. It is called by the
2206 2205
    /// \c AlterationNotifier.
2207 2206
    virtual void build() {
2208 2207
      Map::build();
2209 2208
      Item it;
2210 2209
      const typename Map::Notifier* nf = Map::notifier();
2211 2210
      for (nf->first(it); it != INVALID; nf->next(it)) {
2212 2211
        Map::set(it, _inv_map.size());
2213 2212
        _inv_map.push_back(it);
2214 2213
      }
2215 2214
    }
2216 2215

	
2217 2216
    /// \brief Clear the keys from the map.
2218 2217
    ///
2219 2218
    /// Clear the keys from the map. It is called by the
2220 2219
    /// \c AlterationNotifier.
2221 2220
    virtual void clear() {
2222 2221
      _inv_map.clear();
2223 2222
      Map::clear();
2224 2223
    }
2225 2224

	
2226 2225
  public:
2227 2226

	
2228 2227
    /// \brief Returns the maximal value plus one.
2229 2228
    ///
2230 2229
    /// Returns the maximal value plus one in the map.
2231 2230
    unsigned int size() const {
2232 2231
      return _inv_map.size();
2233 2232
    }
2234 2233

	
2235 2234
    /// \brief Swaps the position of the two items in the map.
2236 2235
    ///
2237 2236
    /// Swaps the position of the two items in the map.
2238 2237
    void swap(const Item& p, const Item& q) {
2239 2238
      int pi = Map::operator[](p);
2240 2239
      int qi = Map::operator[](q);
2241 2240
      Map::set(p, qi);
2242 2241
      _inv_map[qi] = p;
2243 2242
      Map::set(q, pi);
2244 2243
      _inv_map[pi] = q;
2245 2244
    }
2246 2245

	
2247
    /// \brief Gives back the \e descriptor of the item.
2246
    /// \brief Gives back the \e RangeId of the item
2248 2247
    ///
2249
    /// Gives back the mutable and unique \e descriptor of the map.
2248
    /// Gives back the \e RangeId of the item.
2250 2249
    int operator[](const Item& item) const {
2251 2250
      return Map::operator[](item);
2252 2251
    }
2253 2252

	
2254
    /// \brief Gives back the item by its descriptor.
2255
    ///
2256
    /// Gives back th item by its descriptor.
2253
    /// \brief Gives back the item belonging to a \e RangeId
2254
    /// 
2255
    /// Gives back the item belonging to a \e RangeId.
2257 2256
    Item operator()(int id) const {
2258 2257
      return _inv_map[id];
2259 2258
    }
2260 2259

	
2261 2260
  private:
2262 2261

	
2263 2262
    typedef std::vector<Item> Container;
2264 2263
    Container _inv_map;
2265 2264

	
2266 2265
  public:
2267 2266

	
2268
    /// \brief The inverse map type of DescriptorMap.
2267
    /// \brief The inverse map type of RangeIdMap.
2269 2268
    ///
2270
    /// The inverse map type of DescriptorMap.
2269
    /// The inverse map type of RangeIdMap.
2271 2270
    class InverseMap {
2272 2271
    public:
2273 2272
      /// \brief Constructor
2274 2273
      ///
2275 2274
      /// Constructor of the InverseMap.
2276
      explicit InverseMap(const DescriptorMap& inverted)
2275
      explicit InverseMap(const RangeIdMap& inverted)
2277 2276
        : _inverted(inverted) {}
2278 2277

	
2279 2278

	
2280 2279
      /// The value type of the InverseMap.
2281
      typedef typename DescriptorMap::Key Value;
2280
      typedef typename RangeIdMap::Key Value;
2282 2281
      /// The key type of the InverseMap.
2283
      typedef typename DescriptorMap::Value Key;
2282
      typedef typename RangeIdMap::Value Key;
2284 2283

	
2285 2284
      /// \brief Subscript operator.
2286 2285
      ///
2287 2286
      /// Subscript operator. It gives back the item
2288 2287
      /// that the descriptor currently belongs to.
2289 2288
      Value operator[](const Key& key) const {
2290 2289
        return _inverted(key);
2291 2290
      }
2292 2291

	
2293 2292
      /// \brief Size of the map.
2294 2293
      ///
2295 2294
      /// Returns the size of the map.
2296 2295
      unsigned int size() const {
2297 2296
        return _inverted.size();
2298 2297
      }
2299 2298

	
2300 2299
    private:
2301
      const DescriptorMap& _inverted;
2300
      const RangeIdMap& _inverted;
2302 2301
    };
2303 2302

	
2304 2303
    /// \brief Gives back the inverse of the map.
2305 2304
    ///
2306 2305
    /// Gives back the inverse of the map.
2307 2306
    const InverseMap inverse() const {
2308 2307
      return InverseMap(*this);
2309 2308
    }
2310 2309
  };
2311 2310

	
2312 2311
  /// \brief Map of the source nodes of arcs in a digraph.
2313 2312
  ///
2314 2313
  /// SourceMap provides access for the source node of each arc in a digraph,
2315 2314
  /// which is returned by the \c source() function of the digraph.
2316 2315
  /// \tparam GR The digraph type.
2317 2316
  /// \see TargetMap
2318 2317
  template <typename GR>
2319 2318
  class SourceMap {
2320 2319
  public:
2321 2320

	
2322 2321
    ///\e
2323 2322
    typedef typename GR::Arc Key;
2324 2323
    ///\e
2325 2324
    typedef typename GR::Node Value;
2326 2325

	
2327 2326
    /// \brief Constructor
2328 2327
    ///
2329 2328
    /// Constructor.
2330 2329
    /// \param digraph The digraph that the map belongs to.
2331 2330
    explicit SourceMap(const GR& digraph) : _graph(digraph) {}
2332 2331

	
2333 2332
    /// \brief Returns the source node of the given arc.
2334 2333
    ///
2335 2334
    /// Returns the source node of the given arc.
2336 2335
    Value operator[](const Key& arc) const {
2337 2336
      return _graph.source(arc);
2338 2337
    }
2339 2338

	
2340 2339
  private:
2341 2340
    const GR& _graph;
2342 2341
  };
2343 2342

	
2344 2343
  /// \brief Returns a \c SourceMap class.
2345 2344
  ///
2346 2345
  /// This function just returns an \c SourceMap class.
2347 2346
  /// \relates SourceMap
2348 2347
  template <typename GR>
2349 2348
  inline SourceMap<GR> sourceMap(const GR& graph) {
2350 2349
    return SourceMap<GR>(graph);
2351 2350
  }
2352 2351

	
2353 2352
  /// \brief Map of the target nodes of arcs in a digraph.
2354 2353
  ///
2355 2354
  /// TargetMap provides access for the target node of each arc in a digraph,
2356 2355
  /// which is returned by the \c target() function of the digraph.
2357 2356
  /// \tparam GR The digraph type.
2358 2357
  /// \see SourceMap
2359 2358
  template <typename GR>
2360 2359
  class TargetMap {
2361 2360
  public:
2362 2361

	
2363 2362
    ///\e
2364 2363
    typedef typename GR::Arc Key;
2365 2364
    ///\e
2366 2365
    typedef typename GR::Node Value;
2367 2366

	
2368 2367
    /// \brief Constructor
2369 2368
    ///
2370 2369
    /// Constructor.
2371 2370
    /// \param digraph The digraph that the map belongs to.
2372 2371
    explicit TargetMap(const GR& digraph) : _graph(digraph) {}
2373 2372

	
2374 2373
    /// \brief Returns the target node of the given arc.
2375 2374
    ///
2376 2375
    /// Returns the target node of the given arc.
2377 2376
    Value operator[](const Key& e) const {
2378 2377
      return _graph.target(e);
2379 2378
    }
2380 2379

	
2381 2380
  private:
2382 2381
    const GR& _graph;
2383 2382
  };
2384 2383

	
2385 2384
  /// \brief Returns a \c TargetMap class.
2386 2385
  ///
2387 2386
  /// This function just returns a \c TargetMap class.
2388 2387
  /// \relates TargetMap
2389 2388
  template <typename GR>
2390 2389
  inline TargetMap<GR> targetMap(const GR& graph) {
2391 2390
    return TargetMap<GR>(graph);
2392 2391
  }
2393 2392

	
2394 2393
  /// \brief Map of the "forward" directed arc view of edges in a graph.
2395 2394
  ///
2396 2395
  /// ForwardMap provides access for the "forward" directed arc view of
2397 2396
  /// each edge in a graph, which is returned by the \c direct() function
2398 2397
  /// of the graph with \c true parameter.
2399 2398
  /// \tparam GR The graph type.
2400 2399
  /// \see BackwardMap
2401 2400
  template <typename GR>
2402 2401
  class ForwardMap {
2403 2402
  public:
2404 2403

	
2405 2404
    typedef typename GR::Arc Value;
2406 2405
    typedef typename GR::Edge Key;
2407 2406

	
2408 2407
    /// \brief Constructor
2409 2408
    ///
2410 2409
    /// Constructor.
2411 2410
    /// \param graph The graph that the map belongs to.
2412 2411
    explicit ForwardMap(const GR& graph) : _graph(graph) {}
2413 2412

	
2414 2413
    /// \brief Returns the "forward" directed arc view of the given edge.
2415 2414
    ///
2416 2415
    /// Returns the "forward" directed arc view of the given edge.
2417 2416
    Value operator[](const Key& key) const {
2418 2417
      return _graph.direct(key, true);
2419 2418
    }
2420 2419

	
2421 2420
  private:
2422 2421
    const GR& _graph;
2423 2422
  };
2424 2423

	
2425 2424
  /// \brief Returns a \c ForwardMap class.
2426 2425
  ///
2427 2426
  /// This function just returns an \c ForwardMap class.
2428 2427
  /// \relates ForwardMap
2429 2428
  template <typename GR>
2430 2429
  inline ForwardMap<GR> forwardMap(const GR& graph) {
2431 2430
    return ForwardMap<GR>(graph);
2432 2431
  }
2433 2432

	
2434 2433
  /// \brief Map of the "backward" directed arc view of edges in a graph.
2435 2434
  ///
2436 2435
  /// BackwardMap provides access for the "backward" directed arc view of
2437 2436
  /// each edge in a graph, which is returned by the \c direct() function
2438 2437
  /// of the graph with \c false parameter.
2439 2438
  /// \tparam GR The graph type.
2440 2439
  /// \see ForwardMap
2441 2440
  template <typename GR>
2442 2441
  class BackwardMap {
2443 2442
  public:
2444 2443

	
2445 2444
    typedef typename GR::Arc Value;
2446 2445
    typedef typename GR::Edge Key;
2447 2446

	
2448 2447
    /// \brief Constructor
2449 2448
    ///
2450 2449
    /// Constructor.
2451 2450
    /// \param graph The graph that the map belongs to.
2452 2451
    explicit BackwardMap(const GR& graph) : _graph(graph) {}
2453 2452

	
2454 2453
    /// \brief Returns the "backward" directed arc view of the given edge.
2455 2454
    ///
2456 2455
    /// Returns the "backward" directed arc view of the given edge.
2457 2456
    Value operator[](const Key& key) const {
2458 2457
      return _graph.direct(key, false);
2459 2458
    }
2460 2459

	
2461 2460
  private:
2462 2461
    const GR& _graph;
2463 2462
  };
2464 2463

	
2465 2464
  /// \brief Returns a \c BackwardMap class
2466 2465

	
2467 2466
  /// This function just returns a \c BackwardMap class.
2468 2467
  /// \relates BackwardMap
2469 2468
  template <typename GR>
2470 2469
  inline BackwardMap<GR> backwardMap(const GR& graph) {
2471 2470
    return BackwardMap<GR>(graph);
2472 2471
  }
2473 2472

	
2474 2473
  /// \brief Map of the in-degrees of nodes in a digraph.
2475 2474
  ///
2476 2475
  /// This map returns the in-degree of a node. Once it is constructed,
2477 2476
  /// the degrees are stored in a standard \c NodeMap, so each query is done
2478 2477
  /// in constant time. On the other hand, the values are updated automatically
2479 2478
  /// whenever the digraph changes.
2480 2479
  ///
2481 2480
  /// \warning Besides \c addNode() and \c addArc(), a digraph structure 
2482 2481
  /// may provide alternative ways to modify the digraph.
2483 2482
  /// The correct behavior of InDegMap is not guarantied if these additional
2484 2483
  /// features are used. For example the functions
2485 2484
  /// \ref ListDigraph::changeSource() "changeSource()",
2486 2485
  /// \ref ListDigraph::changeTarget() "changeTarget()" and
2487 2486
  /// \ref ListDigraph::reverseArc() "reverseArc()"
2488 2487
  /// of \ref ListDigraph will \e not update the degree values correctly.
2489 2488
  ///
2490 2489
  /// \sa OutDegMap
2491 2490
  template <typename GR>
2492 2491
  class InDegMap
2493 2492
    : protected ItemSetTraits<GR, typename GR::Arc>
Ignore white space 384 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2009
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#include <cstdlib>
20 20
#include <ctime>
21 21

	
22 22
#include <lemon/random.h>
23 23
#include <lemon/list_graph.h>
24 24
#include <lemon/smart_graph.h>
25 25
#include <lemon/maps.h>
26 26

	
27 27
#include "graph_test.h"
28 28
#include "test_tools.h"
29 29

	
30 30
using namespace lemon;
31 31

	
32 32
template <typename Digraph>
33 33
void checkFindArcs() {
34 34
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
35 35

	
36 36
  {
37 37
    Digraph digraph;
38 38
    for (int i = 0; i < 10; ++i) {
39 39
      digraph.addNode();
40 40
    }
41
    DescriptorMap<Digraph, Node> nodes(digraph);
42
    typename DescriptorMap<Digraph, Node>::InverseMap invNodes(nodes);
41
    RangeIdMap<Digraph, Node> nodes(digraph);
42
    typename RangeIdMap<Digraph, Node>::InverseMap invNodes(nodes);
43 43
    for (int i = 0; i < 100; ++i) {
44 44
      int src = rnd[invNodes.size()];
45 45
      int trg = rnd[invNodes.size()];
46 46
      digraph.addArc(invNodes[src], invNodes[trg]);
47 47
    }
48 48
    typename Digraph::template ArcMap<bool> found(digraph, false);
49
    DescriptorMap<Digraph, Arc> arcs(digraph);
49
    RangeIdMap<Digraph, Arc> arcs(digraph);
50 50
    for (NodeIt src(digraph); src != INVALID; ++src) {
51 51
      for (NodeIt trg(digraph); trg != INVALID; ++trg) {
52 52
        for (ConArcIt<Digraph> con(digraph, src, trg); con != INVALID; ++con) {
53 53
          check(digraph.source(con) == src, "Wrong source.");
54 54
          check(digraph.target(con) == trg, "Wrong target.");
55 55
          check(found[con] == false, "The arc found already.");
56 56
          found[con] = true;
57 57
        }
58 58
      }
59 59
    }
60 60
    for (ArcIt it(digraph); it != INVALID; ++it) {
61 61
      check(found[it] == true, "The arc is not found.");
62 62
    }
63 63
  }
64 64

	
65 65
  {
66 66
    int num = 5;
67 67
    Digraph fg;
68 68
    std::vector<Node> nodes;
69 69
    for (int i = 0; i < num; ++i) {
70 70
      nodes.push_back(fg.addNode());
71 71
    }
72 72
    for (int i = 0; i < num * num; ++i) {
73 73
      fg.addArc(nodes[i / num], nodes[i % num]);
74 74
    }
75 75
    check(countNodes(fg) == num, "Wrong node number.");
76 76
    check(countArcs(fg) == num*num, "Wrong arc number.");
77 77
    for (NodeIt src(fg); src != INVALID; ++src) {
78 78
      for (NodeIt trg(fg); trg != INVALID; ++trg) {
79 79
        ConArcIt<Digraph> con(fg, src, trg);
80 80
        check(con != INVALID, "There is no connecting arc.");
81 81
        check(fg.source(con) == src, "Wrong source.");
82 82
        check(fg.target(con) == trg, "Wrong target.");
83 83
        check(++con == INVALID, "There is more connecting arc.");
84 84
      }
85 85
    }
86 86
    ArcLookUp<Digraph> al1(fg);
87 87
    DynArcLookUp<Digraph> al2(fg);
88 88
    AllArcLookUp<Digraph> al3(fg);
89 89
    for (NodeIt src(fg); src != INVALID; ++src) {
90 90
      for (NodeIt trg(fg); trg != INVALID; ++trg) {
91 91
        Arc con1 = al1(src, trg);
92 92
        Arc con2 = al2(src, trg);
93 93
        Arc con3 = al3(src, trg);
94 94
        Arc con4 = findArc(fg, src, trg);
95 95
        check(con1 == con2 && con2 == con3 && con3 == con4,
96 96
              "Different results.")
97 97
        check(con1 != INVALID, "There is no connecting arc.");
98 98
        check(fg.source(con1) == src, "Wrong source.");
99 99
        check(fg.target(con1) == trg, "Wrong target.");
100 100
        check(al3(src, trg, con3) == INVALID,
101 101
              "There is more connecting arc.");
102 102
        check(findArc(fg, src, trg, con4) == INVALID,
103 103
              "There is more connecting arc.");
104 104
      }
105 105
    }
106 106
  }
107 107
}
108 108

	
109 109
template <typename Graph>
110 110
void checkFindEdges() {
111 111
  TEMPLATE_GRAPH_TYPEDEFS(Graph);
112 112
  Graph graph;
113 113
  for (int i = 0; i < 10; ++i) {
114 114
    graph.addNode();
115 115
  }
116
  DescriptorMap<Graph, Node> nodes(graph);
117
  typename DescriptorMap<Graph, Node>::InverseMap invNodes(nodes);
116
  RangeIdMap<Graph, Node> nodes(graph);
117
  typename RangeIdMap<Graph, Node>::InverseMap invNodes(nodes);
118 118
  for (int i = 0; i < 100; ++i) {
119 119
    int src = rnd[invNodes.size()];
120 120
    int trg = rnd[invNodes.size()];
121 121
    graph.addEdge(invNodes[src], invNodes[trg]);
122 122
  }
123 123
  typename Graph::template EdgeMap<int> found(graph, 0);
124
  DescriptorMap<Graph, Edge> edges(graph);
124
  RangeIdMap<Graph, Edge> edges(graph);
125 125
  for (NodeIt src(graph); src != INVALID; ++src) {
126 126
    for (NodeIt trg(graph); trg != INVALID; ++trg) {
127 127
      for (ConEdgeIt<Graph> con(graph, src, trg); con != INVALID; ++con) {
128 128
        check( (graph.u(con) == src && graph.v(con) == trg) ||
129 129
               (graph.v(con) == src && graph.u(con) == trg),
130 130
               "Wrong end nodes.");
131 131
        ++found[con];
132 132
        check(found[con] <= 2, "The edge found more than twice.");
133 133
      }
134 134
    }
135 135
  }
136 136
  for (EdgeIt it(graph); it != INVALID; ++it) {
137 137
    check( (graph.u(it) != graph.v(it) && found[it] == 2) ||
138 138
           (graph.u(it) == graph.v(it) && found[it] == 1),
139 139
           "The edge is not found correctly.");
140 140
  }
141 141
}
142 142

	
143 143
template <class Digraph>
144 144
void checkDeg()
145 145
{
146 146
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
147 147

	
148 148
  const int nodeNum = 10;
149 149
  const int arcNum = 100;
150 150
  Digraph digraph;
151 151
  InDegMap<Digraph> inDeg(digraph);
152 152
  OutDegMap<Digraph> outDeg(digraph);
153 153
  std::vector<Node> nodes(nodeNum);
154 154
  for (int i = 0; i < nodeNum; ++i) {
155 155
    nodes[i] = digraph.addNode();
156 156
  }
157 157
  std::vector<Arc> arcs(arcNum);
158 158
  for (int i = 0; i < arcNum; ++i) {
159 159
    arcs[i] = digraph.addArc(nodes[rnd[nodeNum]], nodes[rnd[nodeNum]]);
160 160
  }
161 161
  for (int i = 0; i < nodeNum; ++i) {
162 162
    check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]),
163 163
          "Wrong in degree map");
164 164
  }
165 165
  for (int i = 0; i < nodeNum; ++i) {
166 166
    check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]),
167 167
          "Wrong out degree map");
168 168
  }
169 169
}
170 170

	
171 171
template <class Digraph>
172 172
void checkSnapDeg()
173 173
{
174 174
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
175 175

	
176 176
  Digraph g;
177 177
  Node n1=g.addNode();
178 178
  Node n2=g.addNode();
179 179

	
180 180
  InDegMap<Digraph> ind(g);
181 181

	
182 182
  g.addArc(n1,n2);
183 183

	
184 184
  typename Digraph::Snapshot snap(g);
185 185

	
186 186
  OutDegMap<Digraph> outd(g);
187 187

	
188 188
  check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value.");
189 189
  check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value.");
190 190

	
191 191
  g.addArc(n1,n2);
192 192
  g.addArc(n2,n1);
193 193

	
194 194
  check(ind[n1]==1 && ind[n2]==2, "Wrong InDegMap value.");
195 195
  check(outd[n1]==2 && outd[n2]==1, "Wrong OutDegMap value.");
196 196

	
197 197
  snap.restore();
198 198

	
199 199
  check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value.");
200 200
  check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value.");
201 201
}
202 202

	
203 203
int main() {
204 204
  // Checking ConArcIt, ConEdgeIt, ArcLookUp, AllArcLookUp, and DynArcLookUp
205 205
  checkFindArcs<ListDigraph>();
206 206
  checkFindArcs<SmartDigraph>();
207 207
  checkFindEdges<ListGraph>();
208 208
  checkFindEdges<SmartGraph>();
209 209

	
210 210
  // Checking In/OutDegMap (and Snapshot feature)
211 211
  checkDeg<ListDigraph>();
212 212
  checkDeg<SmartDigraph>();
213 213
  checkSnapDeg<ListDigraph>();
214 214
  checkSnapDeg<SmartDigraph>();
215 215

	
216 216
  return 0;
217 217
}
0 comments (0 inline)