Ver Mensaje Individual
  #35 (permalink)  
Antiguo 07/05/2017, 13:09
Avatar de detective_jd
detective_jd
 
Fecha de Ingreso: abril-2011
Ubicación: Salto
Mensajes: 437
Antigüedad: 13 años
Puntos: 6
Respuesta: Implementar TablaHash

Hola CalgaryCorpus, lo de las pruebas hice distintas en varios archivos cómo me dijiste además de deshacerme de firstIndex, pero en el dilema de que no me doy cuenta cómo mejorar los recorridos, sinceramente:

Código Java:
Ver original
  1. private abstract class HashIterator<E> implements Iterator<E> {
  2.         private int index = 0;
  3.         private Entry<K,V> currEntry = null;
  4.         private Entry<K,V> nextEntry = null;
  5.         /**
  6.          * Construye una nueva iteración hash
  7.          */
  8.         @SuppressWarnings("empty-statement")
  9.         HashIterator() {
  10.             index = 0;
  11.             for(; index< size; index++){
  12.                 if(table[index]!= null){
  13.                     nextEntry = table[index];
  14.                     break;
  15.                 }
  16.             }
  17.         }
  18.         /**
  19.          * Verifica si hay una siguiente entrada
  20.          *
  21.          * @return boolean -> verdadero o falso
  22.          */
  23.         @Override
  24.         public boolean hasNext() {
  25.             return nextEntry != null;
  26.         }
  27.         /**
  28.          * Obtiene la entrada próxima, y también es una función
  29.          * sobreexplotada para los recorridos ;)
  30.          *
  31.          * @return Entry<K,V> -> entrada clave/valor
  32.          */
  33.         @SuppressWarnings("empty-statement")
  34.         public Entry<K,V> nextEntry() {
  35.             currEntry = nextEntry;
  36.             nextEntry = table[index];
  37.             index++;            
  38.             if (index <= size && table[index] != null) {
  39.                 nextEntry = table[index];              
  40.             } else {
  41.                 nextEntry = null;
  42.                 for (;index < size; index++){
  43.                     if (table[index] != null){
  44.                         nextEntry = table[index];
  45.                     }
  46.                 }
  47.             }
  48.             return currEntry;
  49.         }
  50.     }

Espero sus respuestas y saludos.