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

Commit8ac4506

Browse files
author
jsquared21
committed
Fix method MyHashMap.rehash()
1 parent48c58c7 commit8ac4506

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
115 Bytes
Binary file not shown.

‎Exercise_27/Exercise_27_04/MyHashMap.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,15 @@ private void removeEntries() {
223223

224224
/** Rehash the map */
225225
privatevoidrehash() {
226+
java.util.Set<Entry<K,V>>set =entrySet();
226227
capacity <<=1;// Same as *= 2. <= is more efficient
227-
for (inti =size +1;i <capacity;i++) {
228+
size =0;// Reset size
229+
table.clear();
230+
for (inti =0;i <capacity;i++)
228231
table.add(null);
232+
233+
for (Entry<K,V>entry :set) {
234+
put(entry.getKey(),entry.getValue());
229235
}
230236
}
231237

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp