Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
RandomSubstringFactory.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/algorithm>
9#include <ext/random>
10
12
13#include <string/LinearString.h>
14
15namespace string {
16
17namespace generate {
18
24public:
35 template < class SymbolType >
37
38};
39
40template < class SymbolType >
42 if ( size > string.getContent ( ).size ( ) )
43 throw exception::CommonException ( "String not long enough" );
44
45 size_t begin = ext::random_devices::semirandom ( ) % ( string.getContent ( ).size ( ) - size + 1 );
46
47 ext::vector < SymbolType > data ( string.getContent ( ).begin ( ) + begin, string.getContent ( ).begin ( ) + begin + size );
48
49 return LinearString < SymbolType > ( string.getAlphabet ( ), data );
50}
51
52} /* namespace generate */
53
54} /* namespace string */
55
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
static semirandom_device & semirandom
The reference to singleton semirandom device.
Definition: random.hpp:147
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Linear string.
Definition: LinearString.h:57
Definition: RandomSubstringFactory.h:23
static string::LinearString< SymbolType > generateSubstring(size_t size, const string::LinearString< SymbolType > &string)
Definition: RandomSubstringFactory.h:41
auto begin(Container &&cont) -> decltype(std::forward(cont).begin())
Definition: iterator.hpp:900
Definition: RandomStringFactory.cpp:12