Commit 510ba8a6 authored by Mathieu Valois's avatar Mathieu Valois
Browse files

Merge branch 'clean_code' into dev

parents 0c0369f0 9bf7a285
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -76,20 +76,19 @@ struct Statistics {
 * @param hiderare: flag to hide statistics under 1%
 */
template<typename Type>
void readResult(const uint64_t& occ, const Type& mask, const uint64_t& total_counter, const int& hiderare) {
    if(occ == 0) return;
    std::ostringstream ss;
std::ostream& readResult(std::ostream& os, const uint64_t& occ, const Type& mask, const uint64_t& total_counter, const int& hiderare) {
    if(occ == 0) return os;
    float perc = percentage(occ, total_counter);

    if (perc >= hiderare) {
        ss << perc;
        std::string value(ss.str());
        std::string value = std::to_string(perc);
        value = value.substr(0,5);

        std::cout << std::setw(40) << std::right << mask << ":  "
        os<< std::setw(40) << std::right << mask << ":  "
            << std::setw(5) << std::right << value << "%"
            << std::setw(5) << std::right << "(" << occ << ")" << std::endl;
            << std::setw(5) << std::right << "(" << occ << ")";
    }
    return os;
}

/**
@@ -101,23 +100,24 @@ void readResult(const uint64_t& occ, const Type& mask, const uint64_t& total_cou
 * @param count: number of shown results
 */
template<typename Type>
void showMap(const std::unordered_map<Type, uint64_t> & stats, const int & top, const uint64_t & total_counter, const int & hiderare) {
std::ostream& showMap(std::ostream& os, const std::unordered_map<Type, uint64_t> & stats, const int & top, const uint64_t & total_counter, const int & hiderare) {
	int count = 0;
	std::multimap<uint64_t, Type, std::greater<uint64_t>> reverse = flip_map<Type>(stats);
	std::pair<uint64_t, Type> it;
	for(std::pair<uint64_t, Type> it : reverse) {
		readResult<Type>(it.first, it.second, total_counter, hiderare);
		readResult<Type>(os, it.first, it.second, total_counter, hiderare) << std::endl;
		count++;
		if (top != -1 && count == top) break;
	}

	if (count != top) {
		readResult<Type>(it.first, it.second, total_counter, hiderare);
		readResult<Type>(os, it.first, it.second, total_counter, hiderare) << std::endl;
	}
	return os;
}

std::ostream& operator<<(std::ostream& os, const Statistics& results);

#pragma omp declare reduction(dataSum: Statistics : omp_out += omp_in ) initializer(omp_priv(omp_orig))
#pragma omp declare reduction(+: Statistics : omp_out += omp_in ) initializer(omp_priv(omp_orig))

#endif // STATISTICS_H
 No newline at end of file
+13 −13
Original line number Diff line number Diff line
@@ -91,26 +91,34 @@ std::ostream& operator<<(std::ostream& os, const Statistics& results){
void Statistics::show(std::ostream& os, const Settings& settings) const {
	os << *this << endl;
	os << endl << "Statistics relative to length: " << endl;
	showMap(length, settings.top, total_counter, settings.hiderare);
	showMap(os, length, settings.top, total_counter, settings.hiderare) << endl;

	os << endl << "Statistics relative to charsets: " << endl;
	showMap(charactersets, -1, total_counter, settings.hiderare);
	showMap(os, charactersets, -1, total_counter, settings.hiderare) << endl;


	os << endl << "Statistics relative to simplemasks: " << endl;
	showMap(simplemasks, settings.top, total_counter, settings.hiderare);
	showMap(os, simplemasks, settings.top, total_counter, settings.hiderare) << endl;

	if (settings.limitSimplemask > 0) {
		os << endl;
		auto r = simplemasks.find("othermasks");
		if(r != simplemasks.end()){
			readResult(r->second, r->first, total_counter, settings.hiderare);
			readResult(os, r->second, r->first, total_counter, settings.hiderare) << endl;
		}
	}


	os << endl << "Statistics relative to advancedmask: " << endl;
	showMap(advancedmasks, settings.top, total_counter, settings.hiderare);
	showMap(os, advancedmasks, settings.top, total_counter, settings.hiderare) << endl;

	if (settings.limitAdvancedmask > 0) {
		os << endl;
		auto r = advancedmasks.find("othermasks");
		if(r != advancedmasks.end()){
			readResult(os, r->second, r->first, total_counter, settings.hiderare) << endl;
		}
	}

	if (! settings.outfile_name.empty()){
		locale::global(locale("C"));
@@ -122,12 +130,4 @@ void Statistics::show(std::ostream& os, const Settings& settings) const {
		}
		outfile_stream.close();
	}

	if (settings.limitAdvancedmask > 0) {
		os << endl;
		auto r = advancedmasks.find("othermasks");
		if(r != advancedmasks.end()){
			readResult(r->second, r->first, total_counter, settings.hiderare);
		}
	}
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ int Statsgen::generate_stats() {
	}

	started = true;
#pragma omp parallel reduction(dataSum:results)
#pragma omp parallel reduction(+:results)
	{
#pragma omp single
		{