Improvements
Implemented generic type on VecOps class
This commit is contained in:
parent
0120b04126
commit
2af8345ba8
|
@ -145,7 +145,7 @@ bool HashOps::insertUsedHash( QSqlQuery& query, const QString& db_name, const st
|
|||
{
|
||||
bool successful = true;
|
||||
try {
|
||||
if( ! VecOps::contains( this->hashes.at( web_server_id ), hash ) ) {
|
||||
if( ! VecOps<std::string>::contains( this->hashes.at( web_server_id ), hash ) ) {
|
||||
this->hashes.at( web_server_id ).push_back( hash );
|
||||
// insert tnto the database
|
||||
QString stmt = QString("INSERT INTO %1 ( hash ) VALUES ( '%2' );")
|
||||
|
|
|
@ -163,7 +163,7 @@ void IOutils::randomLines(const std::string& path, std::vector<std::string>& lin
|
|||
for( int i=0 ; i<n_lines ; i++ ) {
|
||||
while (true) {
|
||||
index = rand() % max;
|
||||
if ( VecOps::contains( picked_indexes, index ) ) {
|
||||
if ( VecOps<int>::contains( picked_indexes, index ) ) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -180,7 +180,7 @@ void IOutils::randomLines(const std::string& path, std::vector<std::string>& lin
|
|||
}
|
||||
// add the first and last lines, to double check for file integrity
|
||||
for ( const int& index : std::vector<int>({0,max-1}) ) {
|
||||
if ( ! VecOps::contains( picked_indexes, index ) ) {
|
||||
if ( ! VecOps<int>::contains( picked_indexes, index ) ) {
|
||||
line = aux_lines.at( index );
|
||||
if ( strip_lines ) {
|
||||
line = StringOps::strip( line );
|
||||
|
|
|
@ -2,16 +2,18 @@
|
|||
#include "vectors.h"
|
||||
|
||||
|
||||
VecOps::VecOps()
|
||||
template <typename T>
|
||||
VecOps<T>::VecOps()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
const bool VecOps::contains( const std::vector<int>& list, const int& flag )
|
||||
template <typename T>
|
||||
const bool VecOps<T>::contains(const std::vector<T>& list, const T& flag )
|
||||
{
|
||||
bool result = false;
|
||||
for ( const int& item : list ) {
|
||||
for ( const T& item : list ) {
|
||||
if ( item == flag ) {
|
||||
result = true;
|
||||
break;
|
||||
|
@ -21,14 +23,5 @@ const bool VecOps::contains( const std::vector<int>& list, const int& flag )
|
|||
}
|
||||
|
||||
|
||||
const bool VecOps::contains( const std::vector<std::string>& list, const std::string& flag )
|
||||
{
|
||||
bool result = false;
|
||||
for ( const std::string& item : list ) {
|
||||
if ( item == flag ) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
template class VecOps<int>;
|
||||
template class VecOps<std::string>;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
/*!
|
||||
Utilities for the vectors
|
||||
*/
|
||||
template <typename T>
|
||||
class VecOps
|
||||
{
|
||||
public:
|
||||
|
@ -20,16 +21,7 @@ public:
|
|||
\param flag The element to search for
|
||||
\return Whether the list does contain the flag or not
|
||||
*/
|
||||
static const bool contains( const std::vector<int>& list, const int& flag );
|
||||
|
||||
//! Checks if a vector of strings contains an element
|
||||
/*!
|
||||
\overload static const bool contains( const std::vector<int>& list, const int& flag )
|
||||
\param list The target vector
|
||||
\param flag The element to search for
|
||||
\return Whether the list does contain the flag or not
|
||||
*/
|
||||
static const bool contains( const std::vector<std::string>& list, const std::string& flag );
|
||||
static const bool contains( const std::vector<T>& list, const T& flag );
|
||||
};
|
||||
|
||||
#endif // VECOPS_H
|
||||
|
|
Loading…
Reference in a new issue