Código Java:
Ver original
// System.out.println("hashcode -> " + hash(key.hashCode())); int hash = (key == null) ? 0 : hash(key.hashCode()); int index = hash & (table.length-1); // System.out.println("pase -> " + index); return index; } int h; return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16); } HashEntry<K,V> e = table[findEntry(key)]; return (e != null && key.equals(e.key)) ? e : null; } public V put(K key, V value) { if(key == null){ return null; } Entry<K,V> e = this.getEntry(key); if(e != null){ return table[findEntry(key)].setValue(value); } else if(size == table.length){ } table[findEntry(key)] = new HashEntry(key,value); size++; return null; } /*-----------------------------------------------------------*/ protected class HashEntry<K,V> implements Entry<K,V> { protected K key; protected V value; public HashEntry(K k, V v) { key = k; value = v; } @Override public V getValue() { return value; } @Override public K getKey() { return key; } @Override public V setValue(V val) { V oldValue = value; value = val; return oldValue; } @Override public int hashCode() { return Objects.hashCode(key) ^ Objects.hashCode(value); } @Override if(obj instanceof HashEntry){ HashEntry<K, V> ent = (HashEntry<K, V>) obj; return Objects.equals(key, ent.key) && Objects.equals(value, ent.value); } else { return false; } } @Override return "(key: " + key + ", value: " + value + ")"; } }
Calculo que mi problema está en cómo tengo el hashCode y la función hash pero no le he encontrado la vuelta, por favor denme una mano con esto.
Espero sus respuestas y saludos.