-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashTable.h
More file actions
164 lines (160 loc) · 2.98 KB
/
Copy pathHashTable.h
File metadata and controls
164 lines (160 loc) · 2.98 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#pragma once
#include "Vector.h"
#include <list>
#include <functional>
using namespace std;
template <class T>
class HashTable {
Vector<list<T>> container;
list<T> aux_delete;
function<int(T)> funcionHash;
int cantidad_elems;
public:
HashTable(function<int(T)> funcionHash) :funcionHash(funcionHash)
{
int cap_ht = 1000;
/*container = Vector<list<T>>(cap_ht+10);*/
for (int i = 0; i < cap_ht; ++i)
{
container.pushBack(list<T>());
}
cantidad_elems = 0;
}
void add(T key)
{
container[funcionHash(key)].push_back(key);
cantidad_elems++;
}
bool buscar(function<bool(T)> condicion_find, int pos)
{
Vector<T> aux_find = Vector<T>(cantidad_elems);
if (!container[pos].empty())
{
for (T it : container[pos])
{
if (condicion_find(it)) aux_find.pushBack(it);
}
if (!aux_find.empty())
{
for (auto it : aux_find)
{
cout << it.toString() << "\n";
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
bool buscar2(function<bool(T)> condicion_find, int pos)
{
Vector<T> aux_find = Vector<T>(cantidad_elems);
if (!container[pos].empty())
{
for (T it : container[pos])
{
if (condicion_find(it)) aux_find.pushBack(it);
}
if (!aux_find.empty())
{
int cont = 1;
for (auto it : aux_find)
{
cout << cont << ". " << it.toString2() << "\n";
++cont;
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
T retornar_pos(function<bool(T)> condicion_find, int num, int pos)
{
Vector<T> aux = Vector<T>(cantidad_elems);
for (T it : container[pos])
{
if (condicion_find(it)) aux.pushBack(it);
}
int cont = 1;
for (T it : aux)
{
if (cont == num)
{
return it;
}
else
{
++cont;
}
}
}
void ordenarMergeSort(function<bool(T, T)> criterio)
{
serializacion();
Vector<T> aux_sort = Vector<T>(container.returnCantidad());
aux_sort.mergeSort(aux_sort.retornar_elems(), aux_sort.returnCantidad(), criterio);
/*for (auto it : aux_sort)
{
cout << it.toString() << "\n";
}*/
}
bool eliminar(function<bool(T)> condicion_delete, int pos, string nombre)
{
if (!container[pos].empty())
{
for (auto it : container[pos])
{
if (it.getNombre() != nombre) aux_delete.push_back(it);
}
container[pos] = aux_delete;
for (auto it : container[pos])
{
cout << it.toString() << "->" << "\n";
}
return true;
}
else
{
return false;
}
}
void serializacion()
{
Vector<T> aux_sort = Vector<T>(cantidad_elems);
for (int i = 0; i < container.size(); ++i)
{
for (auto it : container[i])
{
aux_sort.pushBack(it);
}
}
}
void display()
{
int tamano = container.size();
for (int i = 0; i < tamano; ++i)
{
cout << i << "->";
for (auto it : container[i])
{
cout << it.toString() << "->" << "\n";
}
cout << "\n";
}
}
Vector<list<T>> getContainer() { return container; }
int returnCantidad() { return cantidad_elems; }
};