Skip to content

Commit 413d4ff

Browse files
committed
Fix toList method using wrong predicate for filtering null and
Tombstones.
1 parent a889bf9 commit 413d4ff

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/dataStructures/hashSet/openAddressing/HashSet.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public int size() {
129129
*/
130130
public List<T> toList() {
131131
return Arrays.stream(this.buckets)
132-
.filter(element -> element != null || this.TOMBSTONE.equals(element))
132+
.filter(element -> element != null && !element.equals(this.TOMBSTONE))
133133
.collect(Collectors.toList());
134134
}
135135

@@ -158,8 +158,6 @@ private int hashFunction(T element) {
158158
/**
159159
* Given an element, returns the index of an empty (defined as null OR tombstone) bucket to insert the element at.
160160
* If the element is already present in the HashSet, return its index.
161-
* TODO If the ratio of the number of elements to the number of buckets (n / m) exceeds the load factor,
162-
* TODO trigger a resize. (currently throws a RunTimeException).
163161
*
164162
* @param element the given element to probe an empty bucket for.
165163
* @return the index of an empty bucket.
@@ -183,7 +181,6 @@ private int linearProbe(T element) {
183181
}
184182
currentBucketIndex = (currentBucketIndex + 1) % this.capacity();
185183
}
186-
resize(); // TODO implement resize operation.
187184
return ELEMENT_NOT_FOUND; // placeholder return value for now. Will never reach this line.
188185
}
189186

0 commit comments

Comments
 (0)