Rev | Line | |
---|
[d83d64] | 1 | /*
|
---|
| 2 | * Graph6Reader.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Sep 26, 2017
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | #ifndef GRAPH_GRAPH6READER_HPP_
|
---|
| 10 | #define GRAPH_GRAPH6READER_HPP_
|
---|
| 11 |
|
---|
| 12 | // include config.h
|
---|
| 13 | #ifdef HAVE_CONFIG_H
|
---|
| 14 | #include <config.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
| 17 | #include <istream>
|
---|
[7f17c7] | 18 | #include <iterator>
|
---|
[d83d64] | 19 | #include <string>
|
---|
| 20 | #include <vector>
|
---|
| 21 |
|
---|
| 22 | /** This functor parses graph6 formatted strings and returns number of nodes
|
---|
| 23 | * and a edge list.
|
---|
| 24 | *
|
---|
| 25 | * This is inspired by https://github.com/adrianN/graph6/, only I found the code
|
---|
| 26 | * there quite ugly and unnecessarily complicated: inheriting from std::iterator,
|
---|
| 27 | * overriding all the operators (++, *, ...) for no apparent reason instead of
|
---|
| 28 | * adding normal functions, ...
|
---|
| 29 | *
|
---|
| 30 | */
|
---|
| 31 | struct Graph6Reader
|
---|
| 32 | {
|
---|
| 33 | typedef std::pair<int, int> edge_t;
|
---|
| 34 | typedef std::vector< edge_t > edges_t;
|
---|
| 35 |
|
---|
| 36 | Graph6Reader() :
|
---|
[7f17c7] | 37 | column(1),
|
---|
| 38 | row(-1),
|
---|
| 39 | eos(false),
|
---|
| 40 | bit_pos(-1),
|
---|
[d83d64] | 41 | num_nodes(0)
|
---|
| 42 | {}
|
---|
| 43 |
|
---|
| 44 | void operator()(std::istream &_graph_string);
|
---|
| 45 |
|
---|
| 46 | int get_num_nodes() const
|
---|
| 47 | { return num_nodes; }
|
---|
| 48 |
|
---|
| 49 | const edges_t& get_edges() const
|
---|
| 50 | { return edges; }
|
---|
| 51 |
|
---|
| 52 | private:
|
---|
| 53 |
|
---|
| 54 | void scan_num_nodes(std::istream_iterator<unsigned char> &_it);
|
---|
| 55 | void scan_edges(std::istream_iterator<unsigned char> &_it);
|
---|
| 56 | void next_edge(std::istream_iterator<unsigned char> &_it);
|
---|
| 57 |
|
---|
| 58 | private:
|
---|
| 59 | int column;
|
---|
| 60 | int row;
|
---|
[7f17c7] | 61 | bool eos;
|
---|
[d83d64] | 62 | int bit_pos;
|
---|
| 63 | static const int packet_size;
|
---|
| 64 |
|
---|
| 65 | //!> contains number of edges
|
---|
| 66 | int num_nodes;
|
---|
| 67 | //!> contains edge list
|
---|
| 68 | std::vector< edge_t > edges;
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | #endif /* GRAPH_GRAPH6READER_HPP_ */
|
---|
Note:
See
TracBrowser
for help on using the repository browser.