Ejemplo n.º 1
0
def rehashing_tc(tabla, tamanio, funcHash=None):
    nueva_tabla = t.crear_tabla(tamanio)
    if funcHash != None:
        for i in range(len(tabla)):
            elemento = tabla[i]
            if (elemento is not None):
                agregar_tc(nueva_tabla, funcHash, elemento)

    return nueva_tabla
Ejemplo n.º 2
0
def mensaje(ab):
    tabla1 = crear_tabla(200)
    mensaje_final = ""
    #print(len(ab))
    a = 0
    x = int(len(ab) / 5)
    while a < x:
        caracter = ""
        for e in range(a, a + 5):
            caracter += ab[e]
        #print(caracter)
        valor = buscar_ta(tabla1, bernstein_palabra, Caracter("", caracter),
                          "codificacion")
        if valor is None:
            cifrado = decodificar(caracter)
            dato = Caracter(caracter, cifrado)
            agregar_ta(tabla1, bernstein_palabra, dato, "caracter")
        else:
            cifrado = valor.info.codificacion
        mensaje_final += cifrado
        a += 5
    print(mensaje_final)
Ejemplo n.º 3
0
    def __str__(self):

        return self.palabra.capitalize(
        ) + ". Significado : " + self.significado.capitalize()


# a b c d e f g h i j   k  l m   n  o  p q   r  s  t  u  v  w  x  y  z
# 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

palabra1 = Palabra("a", "letra")
palabra2 = Palabra("b", "letra")
palabra3 = Palabra("aa", "letra")
palabra4 = Palabra("aaa", "letra")

diccionario = crear_tabla(26)
diccionario2 = crear_tabla(26)
'''
a = hash_diccionario(palabra1,diccionario)
b = hash_diccionario(palabra2,diccionario)
c = hash_diccionario(palabra3,diccionario)
d = hash_diccionario(palabra4,diccionario)

print(a)
print(b)
print(c)
print(d)
'''
agregar_ta(diccionario2, hash_diccionario, palabra1, "palabra")
agregar_ta(diccionario2, hash_diccionario, palabra2, "palabra")
agregar_ta(diccionario2, hash_diccionario, palabra3, "palabra")
Ejemplo n.º 4
0
        return self.codigo + " " + self.nombre + " " + self.modalidad + " " + str(
            self.horas)


class Docentes(object):
    def __init__(self, nombre, catedra):
        self.nombre = nombre
        self.catedra = catedra

    def __str__(self):
        return self.nombre + " " + self.catedra


# nombre, modalidad, horas, codigo

tabla_catedra = crear_tabla(50)

catedra = Catedra("Algoritmos y estructura de datos", "Anual", 10, "ADC_12345")
agregar_tc(tabla_catedra, bernstein_catedra, catedra)

cont = 0
for e in tabla_catedra:
    print(cont, " ", e)
    cont += 1

profesores = Lista()
insertar(profesores, "Walter")
insertar(profesores, "Ricardo")

posicion = buscar_tc_catedra(tabla_catedra, bernstein_catedra,
                             Catedra("", "", 0, "ADC_12345"))
Ejemplo n.º 5
0

class Personaje():
    def __init__(self, nombre):
        self.nombre = nombre

    def __str__(self):
        return self.nombre


nombres = [
    'Darth Vader', 'Chewbacca', 'Maestro Yoda', 'R2D2', 'Obi-Wan Keobi',
    'Han Solo', 'Beru Lars', 'Leia Organa', 'Poe Dameron', 'Luke Skywalker'
]

tabla = crear_tabla(10)

for i in range(len(nombres)):
    dato = Personaje(nombres[i])
    agregar_tc(tabla, bernstein_SW, dato)
    # porcentaje usado en tabla
    porc_tabla = (cantidad_tc(tabla) * 100) / len(tabla)
    if porc_tabla > 75:
        print(
            'La tabla supero el 75% de su memoria. Necesitamos hacer un Rehashing.'
        )
        print('Haciendo Rehashing...')
        tabla_aux = crear_tabla(len(tabla) * 2)
        for dato in tabla:
            if dato is not None:
                agregar_tc(tabla_aux, bernstein_SW, dato)
Ejemplo n.º 6
0
from tda_tabla_hash import crear_tabla, agregar_ta, bernstein_troopers, hash_division_troopers, bernstein_palabra, hash_division, hash_cifrado
from random import choice, randint
from tda_lista import barrido
from tda_tabla_hash import buscar_ta, Palabra, bernstein_catedra
from tda_tabla_hash import agregar_tc, buscar_tc, quitar_tc

tabla = crear_tabla(50)


class Catedra(object):
    def __init__(self, codigo, nombre, modlidad, horas):
        self.codigo = codigo
        self.nombre = nombre
        self.modalidad = modlidad
        self.horas = horas
        self.docentes = []

    def __str__(self):
        return self.codigo + ' ' + self.nombre + ' ' + str(self.docentes)


catedra = Catedra('ALG_34211', 'algoritmos y estructuras de datos', 'anual', 4)
agregar_tc(tabla, bernstein_catedra, catedra)
catedra = Catedra('ALG_34212', 'programacion orientada a objetos', 'anual', 5)
agregar_tc(tabla, bernstein_catedra, catedra)
catedra = Catedra('ALG_34213', 'fundamentos de programacion', 'anual', 5)
agregar_tc(tabla, bernstein_catedra, catedra)
catedra = Catedra('ALG_34323', 'progrmacion avanzada', 'cuatrimestral', 4)
agregar_tc(tabla, bernstein_catedra, catedra)

posicion = buscar_tc(tabla, bernstein_catedra, Catedra('ALG_34211', '', '', 0))
Ejemplo n.º 7
0
from tda_tabla_hash import agregar_ta, agregar_ta_pokemon, agregar_tc, buscar_tc, crear_tabla, bernstein_pokemon, bernstein


class Pokemon(object):
    def __init__(self, nombre, nivel, tipo1, tipo2, numero):
        self.tipo1 = tipo1
        self.tipo2 = tipo2
        self.numero = numero
        self.nombre = nombre
        self.nivel = nivel

    def __str__(self):
        return self.tipo1 + " " + self.tipo2 + " " + str(self.numero)


tipos = crear_tabla(15)

pokemon1 = Pokemon("Charizard", 100, "electrico", "fuego", 1)

print(bernstein("Fuego", tipos))

agregar_tc(tipos, bernstein_pokemon, pokemon1)

print(tipos)
Ejemplo n.º 8
0
from tda_tabla_hash import crear_tabla, agregar_tc, hash_diccionario2, cantidad_elementos_tc


def porcentaje(tot, n):
    result = (n * 100) / tot
    return int(result)


personajes = crear_tabla(26)

starwars = [
    "achewy", "bR2d2", "cLuke", "dleia", "eObiwan", "fchewy", "gR2d2", "hLuke",
    "ileia", "jObiwan", "kchewy", "lR2d2", "mLuke", "nleia", "oObiwan",
    "pchewy", "qR2d2", "rLuke", "sleia", "tObiwan"
]

for e in starwars:
    agregar_tc(personajes, hash_diccionario2, e)
    porc = porcentaje(len(personajes), cantidad_elementos_tc(personajes))
    if (porc > 75):
        aux = personajes
        a = int(len(personajes) + (len(personajes) / 2))
        personajes = crear_tabla(a)
        for a in aux:
            if a:
                agregar_tc(personajes, hash_diccionario2, a)

print(porc)

print(len(personajes))
print(personajes)
def bernstein_libro(dato, tabla):
    """Función hash de Bernstein para cadenas."""
    h = 0
    for caracter in dato.titulo:
        h = h * 33 + ord(caracter)
    return h % len(tabla)


class Libro(object):
    def __init__(self, titulo, editorial, paginas):
        self.titulo = titulo
        self.editorial = editorial
        self.paginas = paginas


tablaLibros = t.crear_tabla(9)

#C
lib1 = Libro("asd", "tyuiow", 158)
t.agregar_ta(tablaLibros, bernstein_libro, lib1, 'titulo')
lib2 = Libro("asdw", "iow", 256)
t.agregar_ta(tablaLibros, bernstein_libro, lib2, 'titulo')
lib3 = Libro("aasdw", "tyow", 514)
t.agregar_ta(tablaLibros, bernstein_libro, lib3, 'titulo')
t.agregar_ta(tablaLibros, bernstein_libro, Libro("wdwdp", "qwert", 355),
             'titulo')
t.agregar_ta(tablaLibros, bernstein_libro, Libro("xcvbn", "qwerecxt", 3658),
             'titulo')
t.agregar_ta(tablaLibros, bernstein_libro, Libro("jksdl", "qwdwweert", 220),
             'titulo')
t.agregar_ta(tablaLibros, bernstein_libro, Libro("asdwd", "qwert", 360),
Ejemplo n.º 10
0
def mostrar_tabla_clase(tabla):
    res = ""       
    for f in tabla:
        if f:
            aux = f.inicio
            while aux:
                print(aux.info.mensaje)
                print(decodificar(aux.info.mensaje))
                asci = int(decodificar(aux.info.mensaje))
                print(chr(asci))
                res += chr(asci)
                aux = aux.sig
    print( res)

mensaje = "Salvad al droid, porfavor."
code = crear_tabla(len(mensaje))
encode = crear_tabla(len(mensaje) * 6)         
encode2 = crear_tabla(len(mensaje) * 6)


#guardar_mensaje(mensaje,code,encode)
guardar_mensaje_clase(mensaje,encode2)

#mostrar_tabla(encode)
mostrar_tabla_clase(encode2)


#print(code)
#print(" ")
#print(decode)
Ejemplo n.º 11
0
from tda_tabla_hash import crear_tabla, agregar_ta, hash_guia
from tda_lista import barrido


class Telefono(object):
    def __init__(self, telefono, apellido, nombre, direccion):
        self.telefono = telefono
        self.apellido = apellido
        self.nombre = nombre
        self.direccion = direccion

    def __str__(self):
        return self.apellido + " " + self.nombre + ". Direccion: " + self.direccion + ". Telefono: " + str(
            self.telefono)


guia = crear_tabla(10)

telefono1 = Telefono(562385, "Fort", "Ricardo", "Maiameee")
telefono2 = Telefono(572385, "Saitama", "Sensei", "One Punch")

print(hash_guia(telefono1, guia))

agregar_ta(guia, hash_guia, telefono1, "telefono")
agregar_ta(guia, hash_guia, telefono2, "telefono")

posicion = hash_guia(telefono1, guia)

if guia[posicion]:
    barrido(guia[posicion])
Ejemplo n.º 12
0
from tda_tabla_hash import crear_tabla, buscar_ta, agregar_ta, hash_cifrado, bernstein_palabra
from tda_lista import barrido

class Palabra(object):
    
    def __init__(self,palabra,significado):
        self.palabra = palabra
        self.significado = significado
        
    def __str__(self):
        return self.palabra + " " + self.significado
        
tabla1 = crear_tabla(10)

tabla2 = crear_tabla(10)

# Desifrar usando un diccionario
def desifrar(dato):
    diccionario = {"#?&" : "0","abc": "1","def": "2","ghi": "3","jkl": "4","mnñ": "5","opq": "6","rst": "7","uvw": "8","xyz": "9"}    
    cadena = ''
    for i in range(0,len(dato),3):
        cadena += diccionario[dato[i:i+3]]
        #print(dato[i:i+3])
    # print (chr(int(cadena)))
    return chr(int(cadena))
    
def cifrar(dato):
    valor = str(ord(dato))
    # 65 6 
    valor_cifrado = ["#?&","abc","def","ghi","jkl","mnñ","opq","rst","uvw","xyz"]
    
Ejemplo n.º 13
0
from tda_tabla_hash import crear_tabla, agregar_ta, bernstein, cantidad_elementos_ta, hash_division


def decodificar(binario):
    t = len(binario) + 1
    a = binario[2:t]
    b = int(a, 2)
    return b


mensaje = "!@#%^&*"
print("tamanio del mensaje, ", len(mensaje))
mensajes = crear_tabla(10)

mensajes_decodificados = crear_tabla(10)

for e in mensaje:
    print(e)
    a = ord(e)
    print(a)
    b = bin(a)
    print(b)
    agregar_ta(mensajes, bernstein, b)

print(mensajes)

for e in mensajes:
    if e:
        aux = e.inicio
        while aux:
            print(aux.info)
Ejemplo n.º 14
0
from tda_tabla_hash import crear_tabla, agregar_tc, hash_contactos, buscar_tc


class contacto(object):
    def __init__(self, nombreyapellido, email):
        self.nombreyapellido = nombreyapellido
        self.email = email

    def __str__(self):
        return self.nombreyapellido + " " + self.email


contactos = crear_tabla(10)

contacto1 = contacto("Jeremy Rock", "*****@*****.**")

agregar_tc(contactos, hash_contactos, contacto1)

posicion = buscar_tc(contactos, hash_contactos, contacto1)

print(contactos)

if contactos[posicion]:
    print(contactos[posicion])
Ejemplo n.º 15
0
from tda_tabla_hash import crear_tabla, agregar_ta, bernstein_troopers, hash_division_troopers, bernstein, hash_division
from random import choice, randint
from tda_lista import barrido

letras = ['FL', 'TF', 'TK', 'CT', 'FN', 'FO']

tabla_legion = crear_tabla(10)
tabla_codigos = crear_tabla(1000)


class Stormtrooper(object):
    def __init__(self, legion, codigo):
        self.legion = legion
        self.codigo = codigo

    def __str__(self):
        return self.legion + ' ' + str(self.codigo)


for i in range(1, 2000):
    legion = choice(letras)
    codigo = randint(1000, 9999)
    trooper = Stormtrooper(legion, codigo)
    agregar_ta(tabla_legion, bernstein_troopers, trooper, 'legion')
    agregar_ta(tabla_codigos, hash_division_troopers, trooper, 'codigo')

posicion = bernstein('FN', tabla_legion)
if (tabla_legion[posicion]):
    barrido(tabla_legion[posicion])
print()
posicion = bernstein('CT', tabla_legion)