File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
src/com/deepak/data/structures/Arrays Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -54,13 +54,15 @@ public void put(K key, V value) {
5454 /* Find the hash of the key and bucket it belongs to */
5555 int hash = key .hashCode ();
5656 int bucket = getBucket (hash );
57- /* Loop through each entry of the associative array
57+ Entry <K , V > entry = table [bucket ];
58+ /* Loop through the entry of the associative array
5859 * and check if it's just a value update or a new key, value */
59- for (Entry <K , V > entry : table ) {
60- if (entry != null && entry .getKey ().equals (key )) {
61- entry .value = value ;
60+ while (entry != null ) {
61+ if (entry .getHash () == hash && entry .getKey ().equals (key )) {
6262 isNewEntry = false ;
63+ entry .value = value ;
6364 }
65+ entry = entry .next ;
6466 }
6567 /* Create a new entry and push to array */
6668 if (isNewEntry ) {
You can’t perform that action at this time.
0 commit comments