From 259a9b1e09492bec39a07d6ddffe904e910de4e1 Mon Sep 17 00:00:00 2001 From: binlab Date: Wed, 3 Dec 2025 23:33:00 +0100 Subject: [PATCH] final --- Makefile | 2 +- diccionariocuacs.cpp | 15 +++------------ diccionariocuacs.hpp | 2 -- main.cpp | 3 +-- tablahash.cpp | 12 ++---------- tablahash.hpp | 7 ++----- 6 files changed, 9 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index ea71114..47ccc77 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ GPP = /usr/bin/g++ -OPTS = -Wall -Wno-deprecated -g -std=c++17 +OPTS = -Wall -Wno-deprecated -O2 -std=c++17 a.out: diccionariocuacs.o cuac.o fecha.o tablahash.o nodo.o arbol.o $(GPP) $(OPTS) main.cpp tablahash.o cuac.o fecha.o diccionariocuacs.o nodo.o arbol.o diff --git a/diccionariocuacs.cpp b/diccionariocuacs.cpp index 71831e8..2a8799f 100644 --- a/diccionariocuacs.cpp +++ b/diccionariocuacs.cpp @@ -1,18 +1,13 @@ #include "diccionariocuacs.hpp" -DiccionarioCuacs::DiccionarioCuacs(int m) { - TablaHash th = TablaHash(m); - Arbol arbol = Arbol(); - this -> tabla = th; -} void DiccionarioCuacs::insertar(Cuac nuevo) { - Cuac* ref = tabla.insertar(nuevo); + Cuac* ref = tabla.insertar(nuevo); arbol.insertar(ref); } void DiccionarioCuacs::follow(string nombre){ cout << "follow " << nombre << endl; - tabla.consultar(nombre); + tabla.consultar(nombre); } void DiccionarioCuacs::last(int n) { @@ -29,9 +24,5 @@ void DiccionarioCuacs::date(Fecha f1, Fecha f2) { arbol.date(f1, f2); } int DiccionarioCuacs::elem() { - return tabla.elem(); -} - -DiccionarioCuacs::~DiccionarioCuacs() { - delete[] tabla.lista; + return tabla.elem(); } diff --git a/diccionariocuacs.hpp b/diccionariocuacs.hpp index ec788f6..6a98b3b 100644 --- a/diccionariocuacs.hpp +++ b/diccionariocuacs.hpp @@ -12,8 +12,6 @@ class DiccionarioCuacs { TablaHash tabla; Arbol arbol; public: - DiccionarioCuacs(int m); - ~DiccionarioCuacs(); void insertar(Cuac nuevo); void follow(string nombre); void last(int n); diff --git a/main.cpp b/main.cpp index 2411b6d..950b272 100644 --- a/main.cpp +++ b/main.cpp @@ -7,8 +7,7 @@ #include "tablahash.hpp" using namespace std; -// hay que redimensionar dinĂ¡micamente -DiccionarioCuacs dic = DiccionarioCuacs(1000); +DiccionarioCuacs dic; void procesar_pcuac() { Cuac nuevo; diff --git a/tablahash.cpp b/tablahash.cpp index 091d457..c4c0e1b 100644 --- a/tablahash.cpp +++ b/tablahash.cpp @@ -1,14 +1,6 @@ #include "tablahash.hpp" -TablaHash::TablaHash(int M) { - nElem = 0; - this -> M = M; - this -> lista = new list[M]; -} - TablaHash::TablaHash() { -} - -TablaHash::~TablaHash() { + nElem = 0; } Cuac* TablaHash::insertar(Cuac nuevo) { @@ -47,7 +39,7 @@ unsigned int TablaHash::h(string clave) { for (int i = 0; i < (int) clave.length(); i++) { res = 67 * res + clave[i]; } - return res % M; + return res % TH_TAM; } diff --git a/tablahash.hpp b/tablahash.hpp index 5f79ec6..92608c0 100644 --- a/tablahash.hpp +++ b/tablahash.hpp @@ -5,18 +5,15 @@ #include #include using namespace std; - +#define TH_TAM 997 class TablaHash { private: - friend class DiccionarioCuacs; int nElem; int M; - list *lista; + list lista[TH_TAM]; public: TablaHash(); - TablaHash(int M); - ~TablaHash(); Cuac* insertar(Cuac nuevo); void consultar(string nombre); unsigned int h(string clave);