lemon/graph_utils.h
changeset 2333 8070a099ffb6
parent 2329 3f4a04a9b7bf
child 2350 eb371753e814
equal deleted inserted replaced
59:91fc0753ba21 60:a392aabfa5fb
  1580     typedef _Item Item;
  1580     typedef _Item Item;
  1581     typedef _Item Key;
  1581     typedef _Item Key;
  1582 
  1582 
  1583     /// \brief Constructor.
  1583     /// \brief Constructor.
  1584     ///
  1584     ///
  1585     /// Constructor for creating id map.
  1585     /// Constructor of the map.
  1586     explicit IdMap(const Graph& _graph) : graph(&_graph) {}
  1586     explicit IdMap(const Graph& _graph) : graph(&_graph) {}
  1587 
  1587 
  1588     /// \brief Gives back the \e id of the item.
  1588     /// \brief Gives back the \e id of the item.
  1589     ///
  1589     ///
  1590     /// Gives back the immutable and unique \e id of the map.
  1590     /// Gives back the immutable and unique \e id of the item.
  1591     int operator[](const Item& item) const { return graph->id(item);}
  1591     int operator[](const Item& item) const { return graph->id(item);}
  1592 
  1592 
       
  1593     /// \brief Gives back the item by its id.
       
  1594     ///
       
  1595     /// Gives back the item by its id.
       
  1596     Item operator()(int id) { return graph->fromId(id, Item()); }
  1593 
  1597 
  1594   private:
  1598   private:
  1595     const Graph* graph;
  1599     const Graph* graph;
  1596 
  1600 
  1597   public:
  1601   public:
  1616       /// \brief Gives back the given item from its id.
  1620       /// \brief Gives back the given item from its id.
  1617       ///
  1621       ///
  1618       /// Gives back the given item from its id.
  1622       /// Gives back the given item from its id.
  1619       /// 
  1623       /// 
  1620       Item operator[](int id) const { return graph->fromId(id, Item());}
  1624       Item operator[](int id) const { return graph->fromId(id, Item());}
       
  1625 
  1621     private:
  1626     private:
  1622       const Graph* graph;
  1627       const Graph* graph;
  1623     };
  1628     };
  1624 
  1629 
  1625     /// \brief Gives back the inverse of the map.
  1630     /// \brief Gives back the inverse of the map.
  1742     typename MapTraits<Map>::ConstReturnValue 
  1747     typename MapTraits<Map>::ConstReturnValue 
  1743     operator[](const Key& key) const {
  1748     operator[](const Key& key) const {
  1744       return Map::operator[](key);
  1749       return Map::operator[](key);
  1745     }
  1750     }
  1746 
  1751 
       
  1752     /// \brief Gives back the item by its value.
       
  1753     ///
       
  1754     /// Gives back the item by its value.
       
  1755     Key operator()(const Value& key) const {
       
  1756       typename Container::const_iterator it = invMap.find(key);
       
  1757       return it != invMap.end() ? it->second : INVALID;
       
  1758     }
       
  1759 
  1747   protected:
  1760   protected:
  1748 
  1761 
  1749     /// \brief Erase the key from the map.
  1762     /// \brief Erase the key from the map.
  1750     ///
  1763     ///
  1751     /// Erase the key to the map. It is called by the
  1764     /// Erase the key to the map. It is called by the
  1805       /// \brief Subscript operator. 
  1818       /// \brief Subscript operator. 
  1806       ///
  1819       ///
  1807       /// Subscript operator. It gives back always the item 
  1820       /// Subscript operator. It gives back always the item 
  1808       /// what was last assigned to the value.
  1821       /// what was last assigned to the value.
  1809       Value operator[](const Key& key) const {
  1822       Value operator[](const Key& key) const {
  1810 	typename Container::const_iterator it = inverted.invMap.find(key);
  1823 	return inverted(key);
  1811 	return it->second;
       
  1812       }
  1824       }
  1813       
  1825       
  1814     private:
  1826     private:
  1815       const InvertableMap& inverted;
  1827       const InvertableMap& inverted;
  1816     };
  1828     };
  1964     ///
  1976     ///
  1965     /// Gives back the mutable and unique \e descriptor of the map.
  1977     /// Gives back the mutable and unique \e descriptor of the map.
  1966     int operator[](const Item& item) const {
  1978     int operator[](const Item& item) const {
  1967       return Map::operator[](item);
  1979       return Map::operator[](item);
  1968     }
  1980     }
       
  1981 
       
  1982     /// \brief Gives back the item by its descriptor.
       
  1983     ///
       
  1984     /// Gives back th item by its descriptor.
       
  1985     Item operator()(int id) const {
       
  1986       return invMap[id];
       
  1987     }
  1969     
  1988     
  1970   private:
  1989   private:
  1971 
  1990 
  1972     typedef std::vector<Item> Container;
  1991     typedef std::vector<Item> Container;
  1973     Container invMap;
  1992     Container invMap;
  1993       /// \brief Subscript operator. 
  2012       /// \brief Subscript operator. 
  1994       ///
  2013       ///
  1995       /// Subscript operator. It gives back the item 
  2014       /// Subscript operator. It gives back the item 
  1996       /// that the descriptor belongs to currently.
  2015       /// that the descriptor belongs to currently.
  1997       Value operator[](const Key& key) const {
  2016       Value operator[](const Key& key) const {
  1998 	return inverted.invMap[key];
  2017 	return inverted(key);
  1999       }
  2018       }
  2000 
  2019 
  2001       /// \brief Size of the map.
  2020       /// \brief Size of the map.
  2002       ///
  2021       ///
  2003       /// Returns the size of the map.
  2022       /// Returns the size of the map.
  2004       unsigned int size() const {
  2023       unsigned int size() const {
  2005 	return inverted.invMap.size();
  2024 	return inverted.size();
  2006       }
  2025       }
  2007       
  2026       
  2008     private:
  2027     private:
  2009       const DescriptorMap& inverted;
  2028       const DescriptorMap& inverted;
  2010     };
  2029     };