
Namespaces | |
namespace | bitpit::utils |
Namespace for generic utility functions. | |
Functions | |
template<typename T, typename Comparator = std::less<T>> | |
bool | bitpit::utils::addToOrderedVector (const T &value, std::vector< T > &list, Comparator comparator=Comparator()) |
std::size_t | bitpit::utils::countDigits (int n) |
template<class T> | |
void | bitpit::utils::eraseValue (std::vector< T > &, const T &) |
void | bitpit::utils::extractWithoutReplacement (int n, int m, std::vector< int > &list) |
unsigned long | bitpit::utils::factorial (unsigned long n) |
template<typename T, typename Comparator = std::less<T>> | |
std::vector< T >::const_iterator | bitpit::utils::findInOrderedVector (const T &value, const std::vector< T > &list, Comparator comparator=Comparator()) |
template<class T> | |
std::vector< T > | bitpit::utils::intersectionVector (const std::vector< T > &, const std::vector< T > &) |
template<typename T> | |
auto | bitpit::utils::is_iterable_impl (int) -> decltype(std::begin(std::declval< T & >()) !=std::end(std::declval< T & >()),++std::declval< decltype(std::begin(std::declval< T & >()))& >(), *std::begin(std::declval< T & >()), std::true_type{}) |
template<typename OrderContainer, typename DataContainer> | |
void | bitpit::utils::reorderContainer (OrderContainer &order, DataContainer &v, std::size_t size) |
template<typename T> | |
void | bitpit::utils::reorderVector (std::vector< size_t > &order, std::vector< T > &v, std::size_t size) |
template<typename Container, typename Index> | |
void | bitpit::utils::swapValue (Container &v, Index i, Index j) |
template<> | |
void | bitpit::utils::swapValue (std::vector< bool > &v, std::size_t i, std::size_t j) |
Detailed Description
Function Documentation
◆ addToOrderedVector()
bool bitpit::utils::addToOrderedVector | ( | const T & | value, |
std::vector< T > & | list, | ||
Comparator | comparator ) |
Adds an id to an ordered list of unique ids.
- Template Parameters
-
T is the type of elements contained in the list Comparator is the type of the binary function used for the comparison of the elements
- Parameters
-
value is the value to be added list is the ordered list comparator is a binary function that accepts two arguments (the first of the type pointed by ForwardIterator, and the second, always val), and returns a value convertible to bool. The value returned indicates whether the first argument is considered to go before the second. The function shall not modify any of its arguments. This can either be a function pointer or a function object.
- Returns
- Returns true is the id was added to the list, false otherwise.
Definition at line 54 of file commonUtils.tpp.
◆ countDigits()
std::size_t bitpit::utils::countDigits | ( | int | n | ) |
Count the number of digits of the given number.
- Parameters
-
[in] n is number whose digits should be counted
- Returns
- The number of digits of the specified number.
Definition at line 103 of file commonUtils.cpp.
◆ eraseValue()
void bitpit::utils::eraseValue | ( | std::vector< T > & | vec, |
const T & | value ) |
Remove a element with specified value from input std::vector.
- Parameters
-
[in,out] vec is the inptut vector set. On output stores the input vector deprived by the element with specified value [in] value is the value of element to be removed from the input vector
Definition at line 170 of file commonUtils.tpp.
◆ extractWithoutReplacement()
void bitpit::utils::extractWithoutReplacement | ( | int | n, |
int | m, | ||
std::vector< int > & | list ) |
Extract n integers in the interval [0,m] without replacement. if n = m+1, returns a random permutation of {0, 1, 2, ..., m}
- Parameters
-
[in] n is the number of extraction [in] m is the upper bound of extraction interval [in,out] list is a vector with size n, storing extracted values
Definition at line 67 of file commonUtils.cpp.
◆ factorial()
unsigned long bitpit::utils::factorial | ( | unsigned long | n | ) |
Compute the factorial of the specified number.
- Parameters
-
[in] n is the argument for which the factorial has to be evaluated
- Returns
- The factorial of the specified number.
Definition at line 126 of file commonUtils.cpp.
◆ findInOrderedVector()
std::vector< T >::const_iterator bitpit::utils::findInOrderedVector | ( | const T & | value, |
const std::vector< T > & | list, | ||
Comparator | comparator ) |
Search a value in an ordered list of unique ids.
- Template Parameters
-
T is the type of elements contained in the list Comparator is the type of the binary function used for the comparison of the elements
- Parameters
-
value is the value to be searched for list is the ordered list comparator is a binary function that accepts two arguments (the first of the type pointed by ForwardIterator, and the second, always val), and returns a value convertible to bool. The value returned indicates whether the first argument is considered to go before the second. The function shall not modify any of its arguments. This can either be a function pointer or a function object.
- Returns
- Returns true is the value is in the list, false otherwise.
Definition at line 90 of file commonUtils.tpp.
◆ intersectionVector()
std::vector< T > bitpit::utils::intersectionVector | ( | const std::vector< T > & | vec_1, |
const std::vector< T > & | vec_2 ) |
Compute intersection between two std::vectors.
- Parameters
-
[in] vec_1 is the 1st argument for intersection. [in] vec_2 is the 2nd argument for intersection.
- Returns
- Returns a vector storing the common elements of the input vectors.
Definition at line 188 of file commonUtils.tpp.
◆ is_iterable_impl()
auto bitpit::utils::is_iterable_impl | ( | int | ) | -> decltype(std::begin(std::declval< T & >()) !=std::end(std::declval< T & >()),++std::declval< decltype(std::begin(std::declval< T & >()))& >(), *std::begin(std::declval< T & >()), std::true_type{}) |
Check if a type is iterable
◆ reorderContainer()
void bitpit::utils::reorderContainer | ( | OrderContainer & | order, |
DataContainer & | v, | ||
std::size_t | size ) |
Order a container according to a reordering vector.
- Template Parameters
-
OrderContainer is the type of container that stores ordering information DataContainer is the type of container that stores the data
- Parameters
-
order is a reference to the reording container, on output the contents of the container will be destroyed v is a reference to the container that will be reordered size is the size of the container that will be reordered
Definition at line 130 of file commonUtils.tpp.
◆ reorderVector()
void bitpit::utils::reorderVector | ( | std::vector< size_t > & | order, |
std::vector< T > & | v, | ||
std::size_t | size ) |
Order a vector according to a reordering vector.
- Template Parameters
-
T is the type of data that needs to be reordered
- Parameters
-
order is a reference to the reording vector, on output the contents of the vector will be destroyed v is a reference to the vector that will be reordered size is the size of the vector that will be reordered
Definition at line 112 of file commonUtils.tpp.
◆ swapValue() [1/2]
void bitpit::utils::swapValue | ( | Container & | v, |
Index | i, | ||
Index | j ) |
Swap two values stored in the specified container.
- Template Parameters
-
Container is the type of container that stores the data Index is the type of the index that allows to identify a value in the container
- Parameters
-
v is a reference to the container i is the index of the first element that will be swapped j is the index of the second element that will be swapped
Definition at line 155 of file commonUtils.tpp.
◆ swapValue() [2/2]
void bitpit::utils::swapValue | ( | std::vector< bool > & | v, |
std::size_t | i, | ||
std::size_t | j ) |
Swap two values stored in the specified std::vector<bool> container.
- Parameters
-
v is a reference to the container i is the index of the first element that will be swapped j is the index of the second element that will be swapped
Definition at line 52 of file commonUtils.cpp.
