]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/graph/matrix_as_graph.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / graph / matrix_as_graph.hpp
CommitLineData
7c673cae
FG
1//
2//=======================================================================
3// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
4// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
5//
6// Distributed under the Boost Software License, Version 1.0. (See
7// accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9//=======================================================================
10//
11#ifndef BOOST_GRAPH_MATRIX2GRAPH_HPP
12#define BOOST_GRAPH_MATRIX2GRAPH_HPP
13
14#include <utility>
92f5a8d4
TL
15#include <cstddef>
16#include <iterator>
7c673cae
FG
17#include <boost/config.hpp>
18#include <boost/operators.hpp>
19#include <boost/pending/detail/int_iterator.hpp>
20#include <boost/graph/graph_traits.hpp>
21
f67539c2
TL
22namespace boost
23{
7c673cae 24
f67539c2 25template < class Iter, class Vertex > class matrix_adj_iterator;
7c673cae 26
f67539c2 27template < class Iter, class Vertex > class matrix_incidence_iterator;
7c673cae
FG
28
29}
30
f67539c2
TL
31#define BOOST_GRAPH_ADAPT_MATRIX_TO_GRAPH(Matrix) \
32 namespace boost \
33 { \
34 template <> struct graph_traits< Matrix > \
35 { \
36 typedef Matrix::OneD::const_iterator Iter; \
37 typedef Matrix::size_type V; \
38 typedef V vertex_descriptor; \
39 typedef Iter E; \
40 typedef E edge_descriptor; \
41 typedef boost::matrix_incidence_iterator< Iter, V > \
42 out_edge_iterator; \
43 typedef boost::matrix_adj_iterator< Iter, V > adjacency_iterator; \
44 typedef Matrix::size_type size_type; \
45 typedef boost::int_iterator< size_type > vertex_iterator; \
46 \
47 friend std::pair< vertex_iterator, vertex_iterator > vertices( \
48 const Matrix& g) \
49 { \
50 typedef vertex_iterator VIter; \
51 return std::make_pair(VIter(0), VIter(g.nrows())); \
52 } \
53 \
54 friend std::pair< out_edge_iterator, out_edge_iterator > \
55 out_edges(V v, const Matrix& g) \
56 { \
57 typedef out_edge_iterator IncIter; \
58 return std::make_pair( \
59 IncIter(g[v].begin()), IncIter(g[v].end())); \
60 } \
61 friend std::pair< adjacency_iterator, adjacency_iterator > \
62 adjacent_vertices(V v, const Matrix& g) \
63 { \
64 typedef adjacency_iterator AdjIter; \
65 return std::make_pair( \
66 AdjIter(g[v].begin()), AdjIter(g[v].end())); \
67 } \
68 friend vertex_descriptor source(E e, const Matrix& g) \
69 { \
70 return e.row(); \
71 } \
72 friend vertex_descriptor target(E e, const Matrix& g) \
73 { \
74 return e.column(); \
75 } \
76 friend size_type num_vertices(const Matrix& g) \
77 { \
78 return g.nrows(); \
79 } \
80 friend size_type num_edges(const Matrix& g) { return g.nnz(); } \
81 friend size_type out_degree(V i, const Matrix& g) \
82 { \
83 return g[i].nnz(); \
84 } \
85 }; \
86 }
7c673cae 87
f67539c2
TL
88namespace boost
89{
7c673cae 90
f67539c2
TL
91template < class Iter, class Vertex > class matrix_adj_iterator
92{
7c673cae 93 typedef matrix_adj_iterator self;
f67539c2
TL
94
95public:
92f5a8d4
TL
96 typedef std::input_iterator_tag iterator_category;
97 typedef Vertex value_type;
98 typedef std::ptrdiff_t difference_type;
99 typedef Vertex* pointer;
100 typedef Vertex& reference;
f67539c2
TL
101 matrix_adj_iterator() {}
102 matrix_adj_iterator(Iter i) : _iter(i) {}
103 matrix_adj_iterator(const self& x) : _iter(x._iter) {}
104 self& operator=(const self& x)
105 {
106 _iter = x._iter;
107 return *this;
108 }
7c673cae 109 Vertex operator*() { return _iter.column(); }
f67539c2
TL
110 self& operator++()
111 {
112 ++_iter;
113 return *this;
114 }
115 self operator++(int)
116 {
117 self t = *this;
118 ++_iter;
119 return t;
120 }
7c673cae
FG
121 bool operator==(const self& x) const { return _iter == x._iter; }
122 bool operator!=(const self& x) const { return _iter != x._iter; }
f67539c2
TL
123
124protected:
7c673cae 125 Iter _iter;
f67539c2 126};
7c673cae 127
f67539c2
TL
128template < class Iter, class Vertex > class matrix_incidence_iterator
129{
7c673cae 130 typedef matrix_incidence_iterator self;
f67539c2
TL
131
132public:
92f5a8d4
TL
133 typedef std::input_iterator_tag iterator_category;
134 typedef Iter value_type;
135 typedef std::ptrdiff_t difference_type;
136 typedef Iter* pointer;
137 typedef Iter& reference;
f67539c2
TL
138 matrix_incidence_iterator() {}
139 matrix_incidence_iterator(Iter i) : _iter(i) {}
140 matrix_incidence_iterator(const self& x) : _iter(x._iter) {}
141 self& operator=(const self& x)
142 {
143 _iter = x._iter;
144 return *this;
145 }
7c673cae 146 Iter operator*() { return _iter; }
f67539c2
TL
147 self& operator++()
148 {
149 ++_iter;
150 return *this;
151 }
152 self operator++(int)
153 {
154 self t = *this;
155 ++_iter;
156 return t;
157 }
7c673cae
FG
158 bool operator==(const self& x) const { return _iter == x._iter; }
159 bool operator!=(const self& x) const { return _iter != x._iter; }
f67539c2
TL
160
161protected:
7c673cae 162 Iter _iter;
f67539c2
TL
163};
164
7c673cae
FG
165} /* namespace boost */
166
167#endif /* BOOST_GRAPH_MATRIX2GRAPH_HPP*/