Changeset 2386:81b47fc5c444 in lemon-0.x for lemon/graph_adaptor.h
- Timestamp:
- 03/02/07 19:04:28 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3217
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/graph_adaptor.h
r2384 r2386 94 94 95 95 typedef FindEdgeTagIndicator<Graph> FindEdgeTag; 96 Edge findEdge(const Node& source, const Node& target,96 Edge findEdge(const Node& u, const Node& v, 97 97 const Edge& prev = INVALID) { 98 return graph->findEdge( source, target, prev);98 return graph->findEdge(u, v, prev); 99 99 } 100 100 … … 103 103 } 104 104 105 Edge addEdge(const Node& source, const Node& target) const {106 return Edge(graph->addEdge( source, target));105 Edge addEdge(const Node& u, const Node& v) const { 106 return Edge(graph->addEdge(u, v)); 107 107 } 108 108 … … 115 115 int id(const Edge& e) const { return graph->id(e); } 116 116 117 Node fromNodeId(int i d) const {118 return graph->fromNodeId(i d);119 } 120 121 Edge fromEdgeId(int i d) const {122 return graph->fromEdgeId(i d);117 Node fromNodeId(int ix) const { 118 return graph->fromNodeId(ix); 119 } 120 121 Edge fromEdgeId(int ix) const { 122 return graph->fromEdgeId(ix); 123 123 } 124 124 … … 244 244 245 245 typedef FindEdgeTagIndicator<Graph> FindEdgeTag; 246 Edge findEdge(const Node& source, const Node& target,246 Edge findEdge(const Node& u, const Node& v, 247 247 const Edge& prev = INVALID) { 248 return Parent::findEdge( target, source, prev);248 return Parent::findEdge(v, u, prev); 249 249 } 250 250 … … 461 461 template NodeMap<_Value> > Parent; 462 462 463 NodeMap(const Graph& g raph)464 : Parent(g raph) {}465 NodeMap(const Graph& g raph, const _Value& value)466 : Parent(g raph, value) {}463 NodeMap(const Graph& g) 464 : Parent(g) {} 465 NodeMap(const Graph& g, const _Value& v) 466 : Parent(g, v) {} 467 467 468 468 NodeMap& operator=(const NodeMap& cmap) { … … 487 487 template EdgeMap<_Value> > Parent; 488 488 489 EdgeMap(const Graph& g raph)490 : Parent(g raph) {}491 EdgeMap(const Graph& g raph, const _Value& value)492 : Parent(g raph, value) {}489 EdgeMap(const Graph& g) 490 : Parent(g) {} 491 EdgeMap(const Graph& g, const _Value& v) 492 : Parent(g, v) {} 493 493 494 494 EdgeMap& operator=(const EdgeMap& cmap) { … … 634 634 template NodeMap<_Value> > Parent; 635 635 636 NodeMap(const Graph& g raph)637 : Parent(g raph) {}638 NodeMap(const Graph& g raph, const _Value& value)639 : Parent(g raph, value) {}636 NodeMap(const Graph& g) 637 : Parent(g) {} 638 NodeMap(const Graph& g, const _Value& v) 639 : Parent(g, v) {} 640 640 641 641 NodeMap& operator=(const NodeMap& cmap) { … … 660 660 template EdgeMap<_Value> > Parent; 661 661 662 EdgeMap(const Graph& g raph)663 : Parent(g raph) {}664 EdgeMap(const Graph& g raph, const _Value& value)665 : Parent(g raph, value) {}662 EdgeMap(const Graph& g) 663 : Parent(g) {} 664 EdgeMap(const Graph& g, const _Value& v) 665 : Parent(g, v) {} 666 666 667 667 EdgeMap& operator=(const EdgeMap& cmap) { … … 1106 1106 typedef SubMapExtender<Adaptor, EdgeMapBase<_Value> > Parent; 1107 1107 1108 EdgeMap(const Graph& g raph)1109 : Parent(g raph) {}1110 EdgeMap(const Graph& g raph, const _Value& value)1111 : Parent(g raph, value) {}1108 EdgeMap(const Graph& g) 1109 : Parent(g) {} 1110 EdgeMap(const Graph& g, const _Value& v) 1111 : Parent(g, v) {} 1112 1112 1113 1113 EdgeMap& operator=(const EdgeMap& cmap) { … … 1181 1181 : Parent(), edge_notifier(*this), edge_notifier_proxy(*this) {} 1182 1182 1183 void setGraph(_Graph& g raph) {1184 Parent::setGraph(g raph);1185 edge_notifier_proxy.setNotifier(g raph.notifier(GraphEdge()));1183 void setGraph(_Graph& g) { 1184 Parent::setGraph(g); 1185 edge_notifier_proxy.setNotifier(g.notifier(GraphEdge())); 1186 1186 } 1187 1187 … … 1221 1221 } 1222 1222 1223 void setNotifier(typename Graph::EdgeNotifier& n otifier) {1224 Parent::attach(n otifier);1223 void setNotifier(typename Graph::EdgeNotifier& nf) { 1224 Parent::attach(nf); 1225 1225 } 1226 1226 … … 1236 1236 virtual void add(const std::vector<GraphEdge>& ge) { 1237 1237 std::vector<Edge> edges; 1238 for (int i = 0; i < (int)ge.size(); ++i) {1238 for (int i = 0; i < int(ge.size()); ++i) { 1239 1239 edges.push_back(AdaptorBase::Parent::direct(ge[i], true)); 1240 1240 edges.push_back(AdaptorBase::Parent::direct(ge[i], false)); … … 1250 1250 virtual void erase(const std::vector<GraphEdge>& ge) { 1251 1251 std::vector<Edge> edges; 1252 for (int i = 0; i < (int)ge.size(); ++i) {1252 for (int i = 0; i < int(ge.size()); ++i) { 1253 1253 edges.push_back(AdaptorBase::Parent::direct(ge[i], true)); 1254 1254 edges.push_back(AdaptorBase::Parent::direct(ge[i], false)); … … 1822 1822 }; 1823 1823 1824 void first(Node& n ode) const {1825 Parent::first(n ode);1826 n ode.in_node = true;1827 } 1828 1829 void next(Node& n ode) const {1830 if (n ode.in_node) {1831 n ode.in_node = false;1824 void first(Node& n) const { 1825 Parent::first(n); 1826 n.in_node = true; 1827 } 1828 1829 void next(Node& n) const { 1830 if (n.in_node) { 1831 n.in_node = false; 1832 1832 } else { 1833 n ode.in_node = true;1834 Parent::next(n ode);1835 } 1836 } 1837 1838 void first(Edge& e dge) const {1839 e dge.item.setSecond();1840 Parent::first(e dge.item.second());1841 if (e dge.item.second() == INVALID) {1842 e dge.item.setFirst();1843 Parent::first(e dge.item.first());1844 } 1845 } 1846 1847 void next(Edge& e dge) const {1848 if (e dge.item.secondState()) {1849 Parent::next(e dge.item.second());1850 if (e dge.item.second() == INVALID) {1851 e dge.item.setFirst();1852 Parent::first(e dge.item.first());1833 n.in_node = true; 1834 Parent::next(n); 1835 } 1836 } 1837 1838 void first(Edge& e) const { 1839 e.item.setSecond(); 1840 Parent::first(e.item.second()); 1841 if (e.item.second() == INVALID) { 1842 e.item.setFirst(); 1843 Parent::first(e.item.first()); 1844 } 1845 } 1846 1847 void next(Edge& e) const { 1848 if (e.item.secondState()) { 1849 Parent::next(e.item.second()); 1850 if (e.item.second() == INVALID) { 1851 e.item.setFirst(); 1852 Parent::first(e.item.first()); 1853 1853 } 1854 1854 } else { 1855 Parent::next(e dge.item.first());1855 Parent::next(e.item.first()); 1856 1856 } 1857 1857 } 1858 1858 1859 void firstOut(Edge& e dge, const Node& node) const {1860 if (n ode.in_node) {1861 e dge.item.setSecond(node);1859 void firstOut(Edge& e, const Node& n) const { 1860 if (n.in_node) { 1861 e.item.setSecond(n); 1862 1862 } else { 1863 e dge.item.setFirst();1864 Parent::firstOut(e dge.item.first(), node);1865 } 1866 } 1867 1868 void nextOut(Edge& e dge) const {1869 if (!e dge.item.firstState()) {1870 e dge.item.setFirst(INVALID);1863 e.item.setFirst(); 1864 Parent::firstOut(e.item.first(), n); 1865 } 1866 } 1867 1868 void nextOut(Edge& e) const { 1869 if (!e.item.firstState()) { 1870 e.item.setFirst(INVALID); 1871 1871 } else { 1872 Parent::nextOut(e dge.item.first());1872 Parent::nextOut(e.item.first()); 1873 1873 } 1874 1874 } 1875 1875 1876 void firstIn(Edge& e dge, const Node& node) const {1877 if (!n ode.in_node) {1878 e dge.item.setSecond(node);1876 void firstIn(Edge& e, const Node& n) const { 1877 if (!n.in_node) { 1878 e.item.setSecond(n); 1879 1879 } else { 1880 e dge.item.setFirst();1881 Parent::firstIn(e dge.item.first(), node);1882 } 1883 } 1884 1885 void nextIn(Edge& e dge) const {1886 if (!e dge.item.firstState()) {1887 e dge.item.setFirst(INVALID);1880 e.item.setFirst(); 1881 Parent::firstIn(e.item.first(), n); 1882 } 1883 } 1884 1885 void nextIn(Edge& e) const { 1886 if (!e.item.firstState()) { 1887 e.item.setFirst(INVALID); 1888 1888 } else { 1889 Parent::nextIn(e dge.item.first());1890 } 1891 } 1892 1893 Node source(const Edge& e dge) const {1894 if (e dge.item.firstState()) {1895 return Node(Parent::source(e dge.item.first()), false);1889 Parent::nextIn(e.item.first()); 1890 } 1891 } 1892 1893 Node source(const Edge& e) const { 1894 if (e.item.firstState()) { 1895 return Node(Parent::source(e.item.first()), false); 1896 1896 } else { 1897 return Node(e dge.item.second(), true);1898 } 1899 } 1900 1901 Node target(const Edge& e dge) const {1902 if (e dge.item.firstState()) {1903 return Node(Parent::target(e dge.item.first()), true);1897 return Node(e.item.second(), true); 1898 } 1899 } 1900 1901 Node target(const Edge& e) const { 1902 if (e.item.firstState()) { 1903 return Node(Parent::target(e.item.first()), true); 1904 1904 } else { 1905 return Node(e dge.item.second(), false);1906 } 1907 } 1908 1909 int id(const Node& n ode) const {1910 return (Parent::id(n ode) << 1) | (node.in_node ? 0 : 1);1911 } 1912 Node nodeFromId(int i d) const {1913 return Node(Parent::nodeFromId(i d >> 1), (id& 1) == 0);1905 return Node(e.item.second(), false); 1906 } 1907 } 1908 1909 int id(const Node& n) const { 1910 return (Parent::id(n) << 1) | (n.in_node ? 0 : 1); 1911 } 1912 Node nodeFromId(int ix) const { 1913 return Node(Parent::nodeFromId(ix >> 1), (ix & 1) == 0); 1914 1914 } 1915 1915 int maxNodeId() const { … … 1917 1917 } 1918 1918 1919 int id(const Edge& e dge) const {1920 if (e dge.item.firstState()) {1921 return Parent::id(e dge.item.first()) << 1;1919 int id(const Edge& e) const { 1920 if (e.item.firstState()) { 1921 return Parent::id(e.item.first()) << 1; 1922 1922 } else { 1923 return (Parent::id(e dge.item.second()) << 1) | 1;1924 } 1925 } 1926 Edge edgeFromId(int i d) const {1927 if ((i d& 1) == 0) {1928 return Edge(Parent::edgeFromId(i d>> 1));1923 return (Parent::id(e.item.second()) << 1) | 1; 1924 } 1925 } 1926 Edge edgeFromId(int ix) const { 1927 if ((ix & 1) == 0) { 1928 return Edge(Parent::edgeFromId(ix >> 1)); 1929 1929 } else { 1930 return Edge(Parent::nodeFromId(i d>> 1));1930 return Edge(Parent::nodeFromId(ix >> 1)); 1931 1931 } 1932 1932 } … … 1939 1939 /// 1940 1940 /// Returns true when the node is in-node. 1941 static bool inNode(const Node& n ode) {1942 return n ode.in_node;1941 static bool inNode(const Node& n) { 1942 return n.in_node; 1943 1943 } 1944 1944 … … 1946 1946 /// 1947 1947 /// Returns true when the node is out-node. 1948 static bool outNode(const Node& n ode) {1949 return !n ode.in_node;1948 static bool outNode(const Node& n) { 1949 return !n.in_node; 1950 1950 } 1951 1951 … … 1953 1953 /// 1954 1954 /// Returns true when the edge is edge in the original graph. 1955 static bool origEdge(const Edge& e dge) {1956 return e dge.item.firstState();1955 static bool origEdge(const Edge& e) { 1956 return e.item.firstState(); 1957 1957 } 1958 1958 … … 1960 1960 /// 1961 1961 /// Returns true when the edge binds an in-node and an out-node. 1962 static bool bindEdge(const Edge& e dge) {1963 return e dge.item.secondState();1962 static bool bindEdge(const Edge& e) { 1963 return e.item.secondState(); 1964 1964 } 1965 1965 … … 1967 1967 /// 1968 1968 /// Gives back the in-node created from the \c node. 1969 static Node inNode(const GraphNode& n ode) {1970 return Node(n ode, true);1969 static Node inNode(const GraphNode& n) { 1970 return Node(n, true); 1971 1971 } 1972 1972 … … 1974 1974 /// 1975 1975 /// Gives back the out-node created from the \c node. 1976 static Node outNode(const GraphNode& n ode) {1977 return Node(n ode, false);1976 static Node outNode(const GraphNode& n) { 1977 return Node(n, false); 1978 1978 } 1979 1979 … … 1981 1981 /// 1982 1982 /// Gives back the edge binds the two part of the node. 1983 static Edge edge(const GraphNode& n ode) {1984 return Edge(n ode);1983 static Edge edge(const GraphNode& n) { 1984 return Edge(n); 1985 1985 } 1986 1986 … … 1988 1988 /// 1989 1989 /// Gives back the edge of the original edge. 1990 static Edge edge(const GraphEdge& e dge) {1991 return Edge(e dge);1990 static Edge edge(const GraphEdge& e) { 1991 return Edge(e); 1992 1992 } 1993 1993 … … 2006 2006 typedef True FindEdgeTag; 2007 2007 2008 Edge findEdge(const Node& source, const Node& target,2008 Edge findEdge(const Node& u, const Node& v, 2009 2009 const Edge& prev = INVALID) const { 2010 if (inNode(source)) { 2011 if (outNode(target)) { 2012 if ((GraphNode&)source == (GraphNode&)target && prev == INVALID) { 2013 return Edge(source); 2010 if (inNode(u)) { 2011 if (outNode(v)) { 2012 if (static_cast<const GraphNode&>(u) == 2013 static_cast<const GraphNode&>(v) && prev == INVALID) { 2014 return Edge(u); 2014 2015 } 2015 2016 } 2016 2017 } else { 2017 if (inNode( target)) {2018 return Edge(findEdge(*Parent::graph, source, target, prev));2018 if (inNode(v)) { 2019 return Edge(findEdge(*Parent::graph, u, v, prev)); 2019 2020 } 2020 2021 } … … 2192 2193 virtual void add(const std::vector<GraphNode>& gn) { 2193 2194 std::vector<Node> nodes; 2194 for (int i = 0; i < (int)gn.size(); ++i) {2195 for (int i = 0; i < int(gn.size()); ++i) { 2195 2196 nodes.push_back(AdaptorBase::Parent::inNode(gn[i])); 2196 2197 nodes.push_back(AdaptorBase::Parent::outNode(gn[i])); … … 2208 2209 virtual void erase(const std::vector<GraphNode>& gn) { 2209 2210 std::vector<Node> nodes; 2210 for (int i = 0; i < (int)gn.size(); ++i) {2211 for (int i = 0; i < int(gn.size()); ++i) { 2211 2212 nodes.push_back(AdaptorBase::Parent::inNode(gn[i])); 2212 2213 nodes.push_back(AdaptorBase::Parent::outNode(gn[i])); … … 2254 2255 node_notifier_proxy(*this), edge_notifier_proxy(*this) {} 2255 2256 2256 void setGraph(_Graph& g raph) {2257 Parent::setGraph(g raph);2258 node_notifier_proxy.setNotifier(g raph.notifier(GraphNode()));2259 edge_notifier_proxy.setNotifier(g raph.notifier(GraphEdge()));2257 void setGraph(_Graph& g) { 2258 Parent::setGraph(g); 2259 node_notifier_proxy.setNotifier(g.notifier(GraphNode())); 2260 edge_notifier_proxy.setNotifier(g.notifier(GraphEdge())); 2260 2261 } 2261 2262 … … 2308 2309 std::vector<Node> nodes; 2309 2310 std::vector<Edge> edges; 2310 for (int i = 0; i < (int)gn.size(); ++i) {2311 for (int i = 0; i < int(gn.size()); ++i) { 2311 2312 edges.push_back(AdaptorBase::Parent::edge(gn[i])); 2312 2313 nodes.push_back(AdaptorBase::Parent::inNode(gn[i])); … … 2326 2327 std::vector<Node> nodes; 2327 2328 std::vector<Edge> edges; 2328 for (int i = 0; i < (int)gn.size(); ++i) {2329 for (int i = 0; i < int(gn.size()); ++i) { 2329 2330 edges.push_back(AdaptorBase::Parent::edge(gn[i])); 2330 2331 nodes.push_back(AdaptorBase::Parent::inNode(gn[i])); … … 2336 2337 virtual void build() { 2337 2338 std::vector<Edge> edges; 2338 const typename Parent::Notifier* n otifier= Parent::notifier();2339 const typename Parent::Notifier* nf = Parent::notifier(); 2339 2340 GraphNode it; 2340 for (n otifier->first(it); it != INVALID; notifier->next(it)) {2341 for (nf->first(it); it != INVALID; nf->next(it)) { 2341 2342 edges.push_back(AdaptorBase::Parent::edge(it)); 2342 2343 } … … 2346 2347 virtual void clear() { 2347 2348 std::vector<Edge> edges; 2348 const typename Parent::Notifier* n otifier= Parent::notifier();2349 const typename Parent::Notifier* nf = Parent::notifier(); 2349 2350 GraphNode it; 2350 for (n otifier->first(it); it != INVALID; notifier->next(it)) {2351 for (nf->first(it); it != INVALID; nf->next(it)) { 2351 2352 edges.push_back(AdaptorBase::Parent::edge(it)); 2352 2353 } … … 2386 2387 virtual void add(const std::vector<GraphEdge>& ge) { 2387 2388 std::vector<Edge> edges; 2388 for (int i = 0; i < (int)ge.size(); ++i) {2389 for (int i = 0; i < int(ge.size()); ++i) { 2389 2390 edges.push_back(AdaptorBase::edge(ge[i])); 2390 2391 } … … 2396 2397 virtual void erase(const std::vector<GraphEdge>& ge) { 2397 2398 std::vector<Edge> edges; 2398 for (int i = 0; i < (int)ge.size(); ++i) {2399 for (int i = 0; i < int(ge.size()); ++i) { 2399 2400 edges.push_back(AdaptorBase::edge(ge[i])); 2400 2401 } … … 2403 2404 virtual void build() { 2404 2405 std::vector<Edge> edges; 2405 const typename Parent::Notifier* n otifier= Parent::notifier();2406 const typename Parent::Notifier* nf = Parent::notifier(); 2406 2407 GraphEdge it; 2407 for (n otifier->first(it); it != INVALID; notifier->next(it)) {2408 for (nf->first(it); it != INVALID; nf->next(it)) { 2408 2409 edges.push_back(AdaptorBase::Parent::edge(it)); 2409 2410 } … … 2412 2413 virtual void clear() { 2413 2414 std::vector<Edge> edges; 2414 const typename Parent::Notifier* n otifier= Parent::notifier();2415 const typename Parent::Notifier* nf = Parent::notifier(); 2415 2416 GraphEdge it; 2416 for (n otifier->first(it); it != INVALID; notifier->next(it)) {2417 for (nf->first(it); it != INVALID; nf->next(it)) { 2417 2418 edges.push_back(AdaptorBase::Parent::edge(it)); 2418 2419 } … … 2510 2511 /// 2511 2512 /// Constructor of the adaptor. 2512 SplitGraphAdaptor(_Graph& g raph) {2513 Parent::setGraph(g raph);2513 SplitGraphAdaptor(_Graph& g) { 2514 Parent::setGraph(g); 2514 2515 } 2515 2516
Note: See TracChangeset
for help on using the changeset viewer.