Skip to content

Commit

Permalink
Range options parser (draft)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsmirnov committed Oct 28, 2017
1 parent 51126a2 commit bca3707
Show file tree
Hide file tree
Showing 5 changed files with 1,168 additions and 939 deletions.
30 changes: 30 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdexcept>
#include <string>
#include <type_traits>
#include <vector>

#ifdef JNGEN_DECLARE_ONLY
#define JNGEN_EXTERN extern
Expand Down Expand Up @@ -167,6 +168,35 @@ inline long long gcd(long long a, long long b) {
return a + b;
}

inline std::vector<std::string> split(std::string s, char delimiter) {
auto strip = [](std::string s) {
size_t l = 0;
while (l < s.size() && s[l] == ' ') {
++l;
}
s = s.substr(l);
while (!s.empty() && s.back() == ' ') {
s.pop_back();
}
return s;
};

std::vector<std::string> result;
s += delimiter;
std::string cur;

for (char c: s) {
if (c == delimiter) {
result.push_back(strip(cur));
cur.clear();
} else {
cur += c;
}
}

return result;
}

} // namespace util

} // namespace jngen
Expand Down
2 changes: 1 addition & 1 deletion doc/graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ All graph generators return graph with sorted edges to make tests more human-rea
#### randomStretched(int n, int m, int elongation, int spread)
* Returns: a connected stretched graph with *n* vertices and *m* vertices.
* Available modifiers: *allowLoops*, *allowMulti*, *directed*, *allowAntiparallel*, *acyclic*.
* Description: first a random tree on *n* vertices with given *elongation* (see [tree docs](/tree.md)) is generated. Then remaining *m*-*n*+*1* edges are added. One endpoint of an edge is selected at random. The second is a result of jumping to a tree parent of the first endoint a random number of times, from 0 to *spread*.
* Description: first a random tree on *n* vertices with given *elongation* (see [tree docs](/tree.md)) is generated. Then remaining *m*-*n*+*1* edges are added. One endpoint of an edge is selected at random. The second is a result of jumping to a tree parent of the first endoint a random number of times, from 0 to *spread*, inclusive.
* If the graph is directed, the direction of each edge is selected at random, unless it is acyclic: in this case the direction of all edges is down the tree.

### Modifiers
Expand Down
Loading

0 comments on commit bca3707

Please sign in to comment.