-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-1.cpp
136 lines (99 loc) · 3.01 KB
/
test-1.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <iostream>
#include "ConcurrentHashMap.hpp"
#include <unistd.h>
using namespace std;
void *add(void* h){
ConcurrentHashMap* ch = (ConcurrentHashMap*) h ;
usleep(rand() % 10000);
ch->addAndInc("gola");
return NULL;
}
void *add1(void* h){
ConcurrentHashMap* ch = (ConcurrentHashMap*) h ;
//cout << ch->member("hola2");
usleep(rand() % 10000);
ch->addAndInc("hola");
return NULL;
}
void *add2(void* h){
ConcurrentHashMap* ch = (ConcurrentHashMap*) h ;
//cout << ch->member("hola3");
usleep(rand() % 10000);
ch->addAndInc("lola");
return NULL;
}
void *add3(void* h){
ConcurrentHashMap* ch = (ConcurrentHashMap*) h ;
//c//out << ch->member("hola4");
usleep(rand() % 10000);
ch->addAndInc("coca");
return NULL;
}
int main(void) {
ConcurrentHashMap h;
ConcurrentHashMap h2;
pthread_t threads[200]; int tid;
for (tid = 0; tid < 50; tid++) {
pthread_create(&threads[tid],NULL,add,&h);
pthread_create(&threads[50+tid],NULL,add1,&h);
pthread_create(&threads[100+tid],NULL,add2,&h2);
pthread_create(&threads[150+tid],NULL,add3,&h2);
}
h.print_tabla();
h2.print_tabla();
pair<string,unsigned int> s = h.maximum(10);
cout << "<" << s.first << " , " << s.second << ">" << endl;
pair<string,unsigned int> s2 = h2.maximum(10);
cout << "<" << s2.first << " , " << s2.second << ">" << endl;
h.print_tabla();
h2.print_tabla();
s = h.maximum(10);
s2 = h.maximum(10);
cout << "<" << s.first << " , " << s.second << ">" << endl;
cout << "<" << s2.first << " , " << s2.second << ">" << endl;
for (tid = 0; tid < 200; tid++) {
pthread_join(threads[tid],NULL);
}
h.print_tabla();
h2.print_tabla();
cout << "--------------- Creando nueva tabla para testear Count_words(list<string>)-----------" << endl;
ConcurrentHashMap palabras;
list<string> l;
l.push_back("file1");
l.push_back("file2");
l.push_back("file3");
l.push_back("file4");
palabras = count_words(l);
int i;
for (i = 0; i < 26; i++) {
for (auto it = palabras.tabla[i]->CrearIt(); it.HaySiguiente(); it.Avanzar()) {
auto t = it.Siguiente();
cout << t.first << " " << t.second << endl;
}
}
pair<string,unsigned int> max = palabras.maximum(26);
cout << "<" << max.first << " , " << max.second << ">" << endl;
cout << "-----------------Creando nueva tabla para testear Count_words(n, list<string>)-----------" << endl;
ConcurrentHashMap words;
list<string> l2;
l2.push_back("file1");
l2.push_back("file2");
l2.push_back("file3");
l2.push_back("file4");
unsigned int k = 2;
words = count_words(k,l2);
for (i = 0; i < 26; i++) {
for (auto it = words.tabla[i]->CrearIt(); it.HaySiguiente(); it.Avanzar()) {
auto t = it.Siguiente();
cout << t.first << " " << t.second << endl;
}
}
pair<string , unsigned int > m = maximum(2,2,l2);
cout << "<" << m.first << " " << m.second << ">" << endl;
ConcurrentHashMap vacio;
ConcurrentHashMap h3 = vacio;
h3.print_tabla();
h3 = palabras;
h3.print_tabla();
return 0;
}