AuxMethods namespace
namespace AuxMethods It was created to organize a set of auxiliary functions and methods that can be used in various parts of a software project Functions: Random number generation, Reading files, Data sorting and processing (includes methods for sorting dictionaries by their values and for working with spaces in strings) TO DO: list the other functions
Contents
- Reference
Functions
- void setRandSeed(std::uint_fast32_t seed)
- setRandSeed Sets the grain to generate pseudorandom numbers
- auto getRandSeed() -> std::uint_fast32_t
- getRandSeed Returns the current grain for generating pseudo-random numbers
- auto getRandInt(int32_t lower, int32_t upper, bool inclusively = false) -> int32_t
- getRandInt Returns a random integer in the specified range
- auto getRandDouble(double lower, double upper) -> double
- getRandDouble Returns a random floating point number in the specified range
- auto readAllFile(const std::string& filename) -> std::string
- readAllFile Reads the contents of the file and returns it as a string
- auto getRandomIntList(size_t i_n, int32_t i_minNumber, int32_t i_maxNumber, bool repite = false) -> std::vector<int32_t>
- getRandomIntList Generates a list of random integers in a given range with certain restrictions on the number of elements and the presence of repetitions
-
template<typename Key, typename Value>auto sortDictByValue(const std::map<Key, Value>& i_dict, bool up = true) -> std::vector<std::pair<Key, Value>>
- sortDictByValue Sorting the associative container by values and returning sorted key-value pairs as a vector.
-
template<typename T>auto transpose(const std::vector<std::vector<T>>& matrix) -> std::vector<std::vector<T>>
- auto transpose(const std::vector<std::vector<GraphVertexBase*>>& matrix) -> template std::vector<std::vector<GraphVertexBase*>>
- auto sortDictByValue(const std::map<int32_t, int32_t>& i_dict, bool up) -> template std::vector<std::pair<int32_t, int32_t>>
- auto sortDictByValue(const std::map<int32_t, double>& i_dict, bool up) -> template std::vector<std::pair<int32_t, double>>
- auto sortDictByValue(const std::map<std::string, int32_t>& i_dict, bool up) -> template std::vector<std::pair<std::string, int32_t>>
- auto removeSpaces(const std::string& i_s) -> std::string
- removeSpaces Removes spaces, tabs, and newline characters from a string
- auto skipSpaces(const std::string& i_s, size_t i_start = 0) -> size_t
- skipSpaces Skips whitespace characters in the string starting from the specified position.
- auto intToStringWithZeroes(uint32_t i_num, size_t i_totalDigits) -> std::string
Function documentation
void CG_Gen:: AuxMethods:: setRandSeed(std::uint_fast32_t seed)
setRandSeed Sets the grain to generate pseudorandom numbers
| Parameters | |
|---|---|
| seed | A grain for generating random numbers. Must be a positive integer. |
std::uint_fast32_t CG_Gen:: AuxMethods:: getRandSeed()
getRandSeed Returns the current grain for generating pseudo-random numbers
| Returns | Grain for generating random numbers |
|---|
int32_t CG_Gen:: AuxMethods:: getRandInt(int32_t lower,
int32_t upper,
bool inclusively = false)
getRandInt Returns a random integer in the specified range
| Parameters | |
|---|---|
| lower | The lower limit of the range |
| upper | The upper limit of the range |
| inclusively | Indicates whether the upper limit of the range is included in the possible values |
| Returns | A random integer in the specified range |
double CG_Gen:: AuxMethods:: getRandDouble(double lower,
double upper)
getRandDouble Returns a random floating point number in the specified range
| Parameters | |
|---|---|
| lower | The lower limit of the range |
| upper | The upper limit of the range |
| Returns | A random floating point number in the specified range |
std::string CG_Gen:: AuxMethods:: readAllFile(const std::string& filename)
readAllFile Reads the contents of the file and returns it as a string
| Parameters | |
|---|---|
| filename | The name of the file to read |
| Returns | The contents of the file as a string |
std::runtime_error} if the file cannot be opened
std::vector<int32_t> CG_Gen:: AuxMethods:: getRandomIntList(size_t i_n,
int32_t i_minNumber,
int32_t i_maxNumber,
bool repite = false)
getRandomIntList Generates a list of random integers in a given range with certain restrictions on the number of elements and the presence of repetitions
| Parameters | |
|---|---|
| i_n | An integer indicating the desired size of the list |
| i_minNumber | The lower limit of the range for generating random numbers |
| i_maxNumber | The upper limit of the range for generating random numbers |
| repite | A flag indicating whether the repetition of numbers in the list is allowed (true - allowed, false - not allowed). Default - false |
| Returns | a vector<uint32_t> of random numbers according to the specified parameters |
template<typename Key, typename Value>
std::vector<std::pair<Key, Value>> CG_Gen:: AuxMethods:: sortDictByValue(const std::map<Key, Value>& i_dict,
bool up = true)
sortDictByValue Sorting the associative container by values and returning sorted key-value pairs as a vector.
| Template parameters | |
|---|---|
| Key | The key type of the associative container |
| Value | The value type of the associative container |
| Parameters | |
| i_dict | A constant reference to an associative container that needs to be sorted by values |
| up | If true, the sorting takes place in ascending order, otherwise in descending order |
| Returns | A vector of key-value pairs containing dictionary elements sorted by values |
Sorting can be performed both in ascending and descending order of values
template<typename T>
std::vector<std::vector<T>> CG_Gen:: AuxMethods:: transpose(const std::vector<std::vector<T>>& matrix)
template std::vector<std::vector<GraphVertexBase*>> CG_Gen:: AuxMethods:: transpose(const std::vector<std::vector<GraphVertexBase*>>& matrix)
template std::vector<std::pair<int32_t, int32_t>> CG_Gen:: AuxMethods:: sortDictByValue(const std::map<int32_t, int32_t>& i_dict,
bool up)
template std::vector<std::pair<int32_t, double>> CG_Gen:: AuxMethods:: sortDictByValue(const std::map<int32_t, double>& i_dict,
bool up)
template std::vector<std::pair<std::string, int32_t>> CG_Gen:: AuxMethods:: sortDictByValue(const std::map<std::string, int32_t>& i_dict,
bool up)
std::string CG_Gen:: AuxMethods:: removeSpaces(const std::string& i_s)
removeSpaces Removes spaces, tabs, and newline characters from a string
| Parameters | |
|---|---|
| i_s | The string to remove the whitespace characters from |
| Returns | A string without spaces |
size_t CG_Gen:: AuxMethods:: skipSpaces(const std::string& i_s,
size_t i_start = 0)
skipSpaces Skips whitespace characters in the string starting from the specified position.
| Parameters | |
|---|---|
| i_s | The line in which to skip the whitespace characters |
| i_start | The starting position from which to start searching for whitespace characters. |
| Returns | The index of the first character that is not whitespace, or the length of the string if it contains only whitespace. |
By default - 0
std::string CG_Gen:: AuxMethods:: intToStringWithZeroes(uint32_t i_num,
size_t i_totalDigits)