Implementacion
 
home
explicación
TDA
atributos
diagrama
Implementacion
creditos
bibliografia
 
 
    import java.util.*; 

    public class HashTable 
    { 

        String elemento1; 
        String elemento2; 
        float llave; 

         public HashTable(String e1, String e2, float acceso) 
         { 
         elemento1 = new String(e1); 
         elemento2 = new String(e2); 
         llave = new acceso; 
         } 

         public String toString() 
         { 
         return("Elemento: " + e1 + 
         "\nElemento2: " + e2 + 
         "\nLlave: " + acceso) 
         }  

    } 

    Aqui observaremos otras implementaciones para la tabla Hash

    Convertir Cadenas a Enteros 

     public static int hash( String key, int tableSize)  
     
    int hashVal = 0;  
    for (int i = 0; i< key.length(); i++)  
    hashVal = hashVal * 37 + key.charAt(i);  
    hashVal %= m;  
    if (hashVal < 0) hashVal += m;  
    return hashVal;  
     

    Buscar en una tabla Hash o de Dispersión 

    public final Hashable find( Hashable x ) throws ItemNotFound {  
    int currentPos = findPos( x );  
    assertFound( currentPos, "ProbingHashTable find" );  
    return array[ currentPos ].element;  
     

    Insertar en una tabla Hash 

    public final void insert( Hashable x )  
     
    int currentPos = findPos( x );  
    array[ currentPos ] = new HashEntry( x, true );  
    if( ++currentSize < array.length / 2 )  
    return;  
    // Aqui va el codigo de dispersión  
    HashEntry [ ] oldArray = array;  
    // Create a new double-sized, empty table  
    allocateArray( nextPrime( 2 * oldArray.length ) );  
    currentSize = 0;  
    // Copia la tabla  
    for( int i = 0; i < oldArray.length; i++ )  
    if( oldArray[ i ] != null && oldArray[ i ].isActive )  
    insert( oldArray[ i ].element );  
    return;  
     

    Remover de una tabla Hash 

    public final void remove( Hashable x ) throws ItemNotFound  
     
    int currentPos = findPos( x );  
    assertFound( currentPos, "ProbingHashTable remove" );  
    array[ currentPos ].isActive = false;  

 
 
[home] [explicación] [TDA] [atributos] [diagrama] [Implementacion] [creditos] [bibliografia