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

Commit2e8e9b6

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

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed
-17 Bytes
Binary file not shown.

‎Exercise_27/Exercise_27_02/MyHashMap.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,16 @@ public java.util.Set<MyMap.Entry<K, V>> entrySet() {
8989
@Override/** Return the value that matches the specified key */
9090
publicVget(Kkey) {
9191
intindex =hash(key.hashCode());
92-
inti =index -1;// One cycle of the arraylist
9392
intj =0;
94-
95-
while (index !=i && (table.get(index) ==null ||
96-
table.get(index).getKey() !=key)) {
93+
94+
while (table.get(index) !=null) {
95+
if (table.get(index).getKey().equals(key)) {
96+
returntable.get(index).getValue();
97+
}
9798
index +=Math.pow(j++,2);
9899
index %=capacity;
99100
}
100101

101-
if (table.get(index).getKey() ==key)
102-
returntable.get(index).getValue();
103-
104102
returnnull;
105103
}
106104

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp