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

Commit5711790

Browse files
author
jsquared21
committed
Edit method MyHashMap.getAll(key) for efficiency
1 parent081c371 commit5711790

File tree

2 files changed

+3
-3
lines changed

2 files changed

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

‎Exercise_27/Exercise_27_04/MyHashMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ public V get(K key) {
105105
publicjava.util.Set<V>getAll(Kkey) {
106106
java.util.Set<V>set =newjava.util.HashSet<>();
107107
intindex =hash(key.hashCode());
108-
inti =index -1;
109108

110-
while (i !=index) {
111-
if (table.get(index) !=null &&table.get(index).getKey() ==key) {
109+
while (table.get(index) !=null) {
110+
if (table.get(index).getKey().equals(key)) {
112111
set.add(table.get(index).getValue());
113112
}
113+
114114
index++;
115115
index %=capacity;
116116
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp