forked from istng/SO-TP1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConcurrentHashMap.hpp
120 lines (81 loc) · 3.15 KB
/
ConcurrentHashMap.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef CONCURRENT_HASH_MAP_H__
#define CONCURRENT_HASH_MAP_H__
#include <atomic>
#include "ListaAtomica.hpp"
#include "pthread.h"
#include <fstream>
#include <list>
#include <vector>
#include <iostream>
using namespace std;
typedef pair<string,unsigned int> Elem;
class ConcurrentHashMap {
private:
/* Info que le pasamos a un thread para calcular el maximo */
struct infoThread {
infoThread(): siguiente(nullptr),max(nullptr),context(nullptr) {}
atomic<int>* siguiente;
atomic<Elem* > * max;
ConcurrentHashMap* context;
};
pthread_mutex_t _locks[26];
int hash(string s){
return s[0] % 97;
}
public:
/* Lo hacemos publico por que en los test acceden */
Lista<pair<string,unsigned int> >* tabla[26];
/***************** Constructor *****************/
ConcurrentHashMap();
/**********Constructor por copia ***************/
ConcurrentHashMap (const ConcurrentHashMap& other);
/***********************************************/
ConcurrentHashMap& operator= (const ConcurrentHashMap& other);
/*************** Destructor ********************/
~ConcurrentHashMap();
/****************** addAndInc ******************/
void addAndInc(string key);
/****************** memeber ********************/
bool member(string key);
/***********************************************/
static void* maxThrWrapper(void * args);
void * maxThr(void * args);
/****************** maximum ********************/
pair<string,unsigned int> maximum(unsigned int nt);
/**************Función para imprimir hashmap ***/
void print_tabla();
};
/******************************** versión no concurrente ***************************/
ConcurrentHashMap count_words(string archivo);
/****************************Funciones Ej 2.3 **************************************/
void * count_words_threads(void * args);
ConcurrentHashMap count_words(list<string>archs);
/********************* Estructura y funciones para Ej 2.4 ***************************/
struct infoFile {
infoFile(): siguiente(nullptr), words(nullptr),context(nullptr) {}
atomic<int>* siguiente;
vector<string> *words;
ConcurrentHashMap* context;
};
void * count_words_nthreads(void * args);
ConcurrentHashMap count_words(unsigned int n, list<string>archs);
/********************* Estructuras y funciones para Ej 2.5 ***************************/
struct infoFileVector {
infoFileVector(): siguiente(nullptr), words(nullptr),hashMaps(nullptr) {}
atomic<int>* siguiente;
vector<string> *words;
vector<ConcurrentHashMap>* hashMaps;
};
struct infoFileFind {
infoFileFind(): row(nullptr), hashMaps(nullptr), hashMapGral(nullptr) {}
atomic<int>* row;
vector<ConcurrentHashMap>* hashMaps;
ConcurrentHashMap* hashMapGral;
};
void * count_words_nthreads_2(void * args);
void * count_row(void * args);
pair<string, unsigned int>maximum(unsigned int p_archivos,unsigned int p_maximos, list<string>archs);
/*************************************************************************************/
pair<string, unsigned int>maximum2(unsigned int p_archivos,unsigned int p_maximos, list<string>archs);
pair<string, unsigned int>maximum3(unsigned int p_archivos,unsigned int p_maximos, list<string>archs);
#endif /* LISTA_ATOMICA_H__ */