Commit 634b0f7a authored by Jorand Jean-baptiste's avatar Jorand Jean-baptiste
Browse files

refactorisation code avec template

parent f875ff86
Loading
Loading
Loading
Loading
+4
Changes for .gitignore: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
Utils/convert
Adaptation/main
Adaptation/bin
AdaprationParallel/main
AdaprationParallel/bin
Pack/
 No newline at end of file
−2635

File deleted.

Preview size limit exceeded, changes collapsed.

−2
Changes for Adaptation/include/statsgen.h: 0 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -38,8 +38,6 @@ private:
	void analyse_charset(std::wstring &, const Policy &);

	void updateMinMax(const Policy &);
	void readResult(int, std::wstring, int &);
	void readResult(int, int, int &);

	// Filters

+64 −4
Changes for Adaptation/include/utils.h: 64 added lines, 4 removed lines.
Original line number Diff line number Diff line
#include <map>
#include <iostream>
using namespace std;



template<typename K, typename V>
using UnorderedMapIterator = typename std::unordered_map<K, V>::const_iterator;

template<typename K, typename V>
using MapIterator = typename std::map<K, V>::const_iterator;


template<typename A> 
std::multimap<int, A> flip_map(const std::map<A, int> & src) {
    std::multimap<int, A> dst;
multimap<int, A> flip_map(const std::unordered_map<A, int> & src) {
    multimap<int, A> dst;

    std::map<A, int>::const_iterator it;
    for(it = src.begin(); it != src.end(); ++it)
    for(UnorderedMapIterator<A, int> it = src.begin(); it != src.end(); ++it)
        dst.insert(std::pair<int, A>(it->second, it->first));

    return dst;
}




template<typename Type>
void readResult(int res, Type carac, int & count, const int & total_counter, const int & hiderare) {
    float percentage;
    percentage = (float) (100*res) / total_counter;

    if (percentage >= hiderare) {
        wstring value = to_wstring(percentage);
        value = value.substr(0,5);

        wcout << setw(40) << right << carac << ":  " 
            << setw(5) << right << value << "%" 
            << setw(5) << right << "(" << res << ")" << endl;

        count++;
    }
}





template<typename Type>
void showMap(const unordered_map<Type, int> & stats, const int & top, const int & total_counter, const int & hiderare, int & count) {
	count = 0;
    multimap<int, Type> reverse = flip_map<Type>(stats);
    
    MapIterator<int, Type> it;
	for(it = reverse.end(); it != reverse.begin(); it--) {
        if (it == reverse.end()) continue;

        readResult<Type>(it->first, it->second, count, total_counter, hiderare);
        if (top != -1 && count == top) break;
    }

    if (count != top) {
        readResult<Type>(it->first, it->second, count, total_counter, hiderare);
    }
}








+7 −6
Changes for Adaptation/makefile: 7 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -2,27 +2,28 @@ CXX = g++
CXXFLAGS = -pedantic -Wall -std=c++11 -Wextra -I./include
SRC	 = src/
INC	 = include/
BIN	 = bin/



.PHONY 	 = main clean


all: main clean
all: main


main: main.o statsgen.o
	$(CXX) $(CXXFLAGS) $^ -o $@
main: $(BIN)main.o $(BIN)statsgen.o
	$(CXX) $^ $(CXXFLAGS) -o $@



main.o: $(SRC)main.cpp $(INC)statsgen.h
$(BIN)main.o: $(SRC)main.cpp $(INC)statsgen.h
	$(CXX) $(CXXFLAGS) $(SRC)main.cpp -c -o $@

statsgen.o: $(SRC)statsgen.cpp $(INC)statsgen.h
$(BIN)statsgen.o: $(SRC)statsgen.cpp $(INC)statsgen.h
	$(CXX) $(CXXFLAGS) $(SRC)statsgen.cpp -c -o $@



clean:
	rm *.o
 No newline at end of file
	rm $(BIN)/*.o
 No newline at end of file
Loading