diff --git a/codes/java/chapter_hashing/hash_map_open_addressing.java b/codes/java/chapter_hashing/hash_map_open_addressing.java index b20d6779b8..47f974295d 100644 --- a/codes/java/chapter_hashing/hash_map_open_addressing.java +++ b/codes/java/chapter_hashing/hash_map_open_addressing.java @@ -53,6 +53,9 @@ private int findBucket(int key) { } // 计算桶索引,越过尾部则返回头部 index = (index + 1) % capacity; + if (index == firstTombstone) { + break; + } } // 若 key 不存在,则返回添加点的索引 return firstTombstone == -1 ? index : firstTombstone;