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

Commit5f1aaac

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

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed
-37 Bytes
Binary file not shown.

‎Exercise_27/Exercise_27_01/MyHashMap.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,15 @@ public java.util.Set<MyMap.Entry<K,V>> entrySet() {
8888
@Override/** Return the value that matches the specified key */
8989
publicVget(Kkey) {
9090
intindex =hash(key.hashCode());
91-
inti =index -1;// One cycle of the arraylist
9291

93-
// While index is empty or a collision occurs check the next index
94-
while (index !=i && (table.get(index) ==null ||
95-
table.get(index).getKey() !=key)) {
92+
while(table.get(index) !=null) {
93+
if (table.get(index).getKey() ==key) {
94+
returntable.get(index).getValue();
95+
}
9696
index++;
9797
index %=capacity;
9898
}
9999

100-
if (table.get(index).getKey() ==key) {
101-
returntable.get(index).getValue();
102-
}
103-
104100
returnnull;
105101
}
106102

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp