From 6d4329b4f39600a5e8ecee397937b2b3e17b96a0 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Tue, 6 Feb 2018 19:53:18 +0300 Subject: [PATCH] Some docs I missed earlier --- doc/array.md | 6 +++--- doc/graph.md | 8 ++++++++ doc/random.md | 6 +++++- doc/tree.md | 3 +++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/doc/array.md b/doc/array.md index 55b83b8..e2fd5c9 100644 --- a/doc/array.md +++ b/doc/array.md @@ -40,9 +40,9 @@ yields edges of a random graph with 10 vertices and 20 edges, possibly containin * Example: ```cpp TArray::randomf( - 10, - [](const char* pattern) { return rnd.next(pattern); }, - "[a-z]{5}") + 10, + [](const char* pattern) { return rnd.next(pattern); }, + "[a-z]{5}") ``` yields an array of 10 strings of 5 letters each. diff --git a/doc/graph.md b/doc/graph.md index e4701cb..78b6bcb 100644 --- a/doc/graph.md +++ b/doc/graph.md @@ -46,6 +46,14 @@ All graph generators return graph with sorted edges to make tests more human-rea * 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. +#### randomBipartite(int n1, int n2, int m) +* Returns: a random bipartite graph with *n1* vertices in one part, *n2* vertices in another part and *m* edges. Vertices from *1* to *n1* belong to the first part. +* Available modifiers: *connected*, *allowMulti*. + +#### completeBipartite(int n1, int n2) +* Returns: a complet bipartite graph with *n1* vertices in one part and *n2* vertices in another part. Vertices from *1* to *n1* belong to the first part. +* Available modifiers: none. + ### Modifiers All options are unset by default. If the generator contradicts some option (like *randomStretched*, which always produces a connected graph), it is ignored. #### connected(bool value = true) diff --git a/doc/random.md b/doc/random.md index 570feba..30b15d7 100644 --- a/doc/random.md +++ b/doc/random.md @@ -30,7 +30,7 @@ Default initialized *Random* is seeded with some hardware-generated random value * pattern followed by *{n}* is the same as the pattern repeated *n* times; * pattern followed by *{l,r}* is the same as the pattern repeated random number of times from *l* to *r*, inclusive; * "|" character yields either a pattern to its left or the pattern to its right equiprobably; - * several "|" characters between patterns yield any pattern between them equiprobably, e.g. *(a|b|c){100}* yields a string of length 100 with almost equal number of *a*'s, *b*'s and *c*'s; + * several "|" characters between patterns yield any pattern between them equiprobably, e.g. *(a|b|c|z){100}* yields a string of length 100 with almost equal number of *a*'s, *b*'s, *c*'s and *z*'s; * parentheses "()" are used for grouping. * examples: * `rnd.next("[1-9][0-9]{1,2}")`: random 2- or 3-digit number (note that the distribution on numbers is not uniform); @@ -54,6 +54,10 @@ Default initialized *Random* is seeded with some hardware-generated random value * Returns: random element of a range or of a container, respectively. * Note: *Container* may be *any* STL container, including *std::set*. In general case the runtime of this function is *O(container.size())*. However, if *Iterator* is a random-access iterator, the runtime is constant. +#### template size_t nextByDistribution(const std::vector& distribution) +* Returns: a random integer from *0* to *distribution.size() - 1*, where probability of *i* is proportional to *distribution[i]. +* Example: *rnd.nextByDistribution({1, 1, 100})* will likely return 2, but roughly each 50-th iteration will return 0 or 1. + ### Seeding #### void seed(uint32_t seed) #### void seed(const std::vector<uint32_t>& seed) diff --git a/doc/tree.md b/doc/tree.md index f177b90..5214148 100644 --- a/doc/tree.md +++ b/doc/tree.md @@ -38,6 +38,9 @@ Note that all generators return trees with sorted edges to make tests more human * Returns: a complete *k*-ary tree with *size* vertices. * Numeration: parent of vertex *i* is *(i-1)/k*, *0* is root. +#### Tree fromPruferSequence(const Array& code) +* Returns: a tree with given [Prüfer sequence](https://en.wikipedia.org/wiki/Pr%C3%BCfer_sequence). The tree contains *code.size() + 2* vertices. + ### Tree methods #### Tree& shuffle()