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

Commita2c6869

Browse files
author
jsquared21
committed
Edit method MyHashMap.get(key) for efficiency
1 parent2870c6d commita2c6869

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed
22 Bytes
Binary file not shown.

‎Exercise_27/Exercise_27_03/MyHashMap.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ public V get(K key) {
9292
intindex =hash1;
9393
intj =0;
9494

95-
while (table.get(index) ==null) {
95+
while (table.get(index) !=null) {
96+
if (table.get(index).getKey().equals(key)) {
97+
returntable.get(index).getValue();
98+
}
99+
96100
// Secondary hash: (k + j * h'(key)) % N
97101
index =hash1 +j++ *hash2(hash1);
98102
index %=capacity;
99103
}
100104

101-
if (table.get(index).getKey() ==key) {
102-
returntable.get(index).getValue();
103-
}
104-
105105
returnnull;
106106
}
107107

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp