Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc73855d

Browse files
author
jsquared21
committed
Edit method MyHashMap.put(key, value) for efficiency
1 parenta2c6869 commitc73855d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed
3 Bytes
Binary file not shown.

‎Exercise_27/Exercise_27_03/MyHashMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public V get(K key) {
9696
if (table.get(index).getKey().equals(key)) {
9797
returntable.get(index).getValue();
9898
}
99-
99+
100100
// Secondary hash: (k + j * h'(key)) % N
101101
index =hash1 +j++ *hash2(hash1);
102102
index %=capacity;
@@ -129,8 +129,8 @@ public V put(K key, V value) {
129129
intj =0;
130130

131131
while (table.get(index) !=null) {
132-
//Add a new entry (key, value)
133-
if (table.get(index).getKey() ==key) {
132+
//The key is already in the map
133+
if (table.get(index).getKey().equals(key)) {
134134
Entry<K,V>entry =table.get(index);
135135
VoldValue =entry.getValue();
136136
// Replace old value with new value

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp