← comparison
tgen
Loading...
Searching...
No Matches

String value. More...

Inheritance diagram for tgen::str::value:

Public Member Functions

 value (const std::string &str)
 Creates a string value from a std::string.
int size () const
 Returns the size of the string value.
char & operator[] (int idx)
 Accesses the character at some position of the string.
valuesort ()
 Sorts the characters in non-decreasing order.
valuereverse ()
 Reverses the string.
valuelowercase ()
 Sets all characters to lowercase.
valueuppercase ()
 Sets all characters to uppercase.
value operator+ (const value &rhs) const
 Concatenates two strings.
valueshuffle ()
 Shuffles the string.
char pick () const
 Returns a uniformly random element.
template<typename Dist>
char pick_by_distribution (const std::vector< Dist > &distribution) const
 Returns a random element from the string with given probabilities.
value choose (int k) const
 Chooses a uniformly random subsequence of given length.
std::string to_std () const
 Converts the string to a std::string.
Public Member Functions inherited from tgen::gen_value_base< value >
bool operator< (const value &rhs) const

Friends

std::ostream & operator<< (std::ostream &out, const value &val)
 Prints the string to an output stream.

Detailed Description

String value.

It can be printed through std::cout.

Definition at line 3801 of file tgen.h.

Constructor & Destructor Documentation

◆ value()

tgen::str::value::value ( const std::string & str)
inline

Creates a string value from a std::string.

Parameters
strThe std::string representing the string.

Examples

// Creates and prints a string from a std::string.
std::string s = "aba";
std::cout << val << std::endl; // Prints "aba".
String value.
Definition tgen.h:3801

Definition at line 3808 of file tgen.h.

Member Function Documentation

◆ choose()

value tgen::str::value::choose ( int k) const
inline

Chooses a uniformly random subsequence of given length.

Parameters
kSubsequence length.
Returns
A uniformly random subsequence of length k.

Complexity

O(n).

Examples

tgen::str::value val("abc");
std::cout << val.choose(2) << std::endl;

Definition at line 3891 of file tgen.h.

◆ lowercase()

value & tgen::str::value::lowercase ( )
inline

Sets all characters to lowercase.

Complexity

O(n).

Examples

// Sets the string to lowercase and prints it.
tgen::str::value val("abC");
std::cout << val.lowercase() << std::endl; // Prints "abc".

Definition at line 3843 of file tgen.h.

◆ operator+()

value tgen::str::value::operator+ ( const value & rhs) const
inline

Concatenates two strings.

Parameters
rhsThe right-hand side.
Returns
The concatenation.

Complexity

Linear.

Examples

// Concatenates and prints two strings.
tgen::str s = tgen::str(5, 'a', 'z').all_different();
std::cout << s.gen() + s.gen() << std::endl;
String generator.
Definition tgen.h:3693
value gen() const
Generates a uniformly random value from the set of valid strings.
Definition tgen.h:3918
str & all_different()
Restricts generator s.t. all characters are different.
Definition tgen.h:3794

Definition at line 3859 of file tgen.h.

◆ operator[]()

char & tgen::str::value::operator[] ( int idx)
inline

Accesses the character at some position of the string.

Parameters
idxIndex to be accessed.
Returns
The character at index idx.

Examples

// Changes and prints a position of a string.
tgen::str::value val("aba");
++val[1];
std::cout << val[1] << std::endl; // Prints "c".

Definition at line 3816 of file tgen.h.

◆ pick()

char tgen::str::value::pick ( ) const
inline

Returns a uniformly random element.

Returns
A uniformly random element from the string.

Complexity

O(1).

Examples

tgen::str::value val("abc");
std::cout << val.pick() << std::endl;

Definition at line 3873 of file tgen.h.

◆ pick_by_distribution()

template<typename Dist>
char tgen::str::value::pick_by_distribution ( const std::vector< Dist > & distribution) const
inline

Returns a random element from the string with given probabilities.

Parameters
distributionProbability distribution.
Returns
A random element from the string, chosen with probability proportional to distribution.
Warning
For integral Dist, assumes that the sum of distribution fits in type unsigned __int128.

Complexity

O(1).

Examples

tgen::str::value val("abc");
std::cout << val.pick_by_distribution({1, 2, 3}) << std::endl;

Definition at line 3878 of file tgen.h.

◆ reverse()

value & tgen::str::value::reverse ( )
inline

Reverses the string.

Complexity

O(n).

Examples

// Reverses and prints a string.
tgen::str::value val("bac");
std::cout << val.reverse() << std::endl; // Prints "cab".

Definition at line 3836 of file tgen.h.

◆ shuffle()

value & tgen::str::value::shuffle ( )
inline

Shuffles the string.

Complexity

O(n).

Examples

tgen::str::value val("abc");
std::cout << val.shuffle() << std::endl;

Definition at line 3865 of file tgen.h.

◆ size()

int tgen::str::value::size ( ) const
inline

Returns the size of the string value.

Returns
The number of characters in the string.

Examples

// Prints the size of a string.
tgen::str::value val("aba");
std::cout << val.size() << std::endl; // Prints "3".

Definition at line 3813 of file tgen.h.

◆ sort()

value & tgen::str::value::sort ( )
inline

Sorts the characters in non-decreasing order.

Complexity

O(n log n).

Examples

// Sorts and prints a string.
tgen::str::value val("aba");
std::cout << val.sort() << std::endl; // Prints "aab".

Definition at line 3829 of file tgen.h.

◆ to_std()

std::string tgen::str::value::to_std ( ) const
inline

Converts the string to a std::string.

Returns
A std::string representing the string.

Examples

// Convoluted way to reverse a string.
std::string s = "bac";
// s = "cab".
value & reverse()
Reverses the string.
Definition tgen.h:3836
std::string to_std() const
Converts the string to a std::string.
Definition tgen.h:3912

Definition at line 3912 of file tgen.h.

◆ uppercase()

value & tgen::str::value::uppercase ( )
inline

Sets all characters to uppercase.

Complexity

O(n).

Examples

// Sets the string to uppercase and prints it.
tgen::str::value val("abC");
std::cout << val.uppercase() << std::endl; // Prints "ABC".

Definition at line 3851 of file tgen.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const value & val )
friend

Prints the string to an output stream.

The string is printed with no end of line.

Examples

// Prints a string.
std::cout << tgen::str::value("aba") << std::endl; // Prints "aba".

Definition at line 3907 of file tgen.h.


The documentation for this struct was generated from the following files:
  • /home/runner/work/tgen_vs_jngen/tgen_vs_jngen/vendor/tgen/single_include/tgen.h
  • str.dox