Skip to content

Commit 4878136

Browse files
committed
Change access modifier of capacity method to public
1 parent c263f00 commit 4878136

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/dataStructures/hashSet/openAddressing/HashSet.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* List<T> toList() returns a List representation of this HashSet. O(n).
2020
* int size() gets the number of elements (cardinality) in this HashSet. O(1).
2121
* boolean isEmpty() checks if the HashSet is empty. O(1).
22+
* int capacity() returns the capacity of this HashSet. O(1).
2223
*
2324
* @param <T> the type of objects that are contained within this HashSet. T must override
2425
* Object::equals and Object::hashCode for the methods add, remove, and contains to be well-defined.
@@ -152,6 +153,16 @@ public List<T> toList() {
152153
.collect(Collectors.toList());
153154
}
154155

156+
/**
157+
* Returns the number of buckets of this HashSet. Equivalently, returns the maximum number of elements that can
158+
* be stored in this HashSet.
159+
*
160+
* @return the number of buckets of this HashSet.
161+
*/
162+
public int capacity() {
163+
return this.buckets.length; // returns the number of buckets.
164+
}
165+
155166
/**
156167
* Hashes the specified element to determine the bucket index for placement within the array.
157168
* The hash function calculates the index by performing the following steps:
@@ -267,16 +278,6 @@ private boolean isTombstoneBucket(int bucketIndex) {
267278
return this.TOMBSTONE.equals(this.buckets[bucketIndex]);
268279
}
269280

270-
/**
271-
* Returns the number of buckets of this HashSet. Equivalently, returns the maximum number of elements that can
272-
* be stored in this HashSet.
273-
*
274-
* @return the number of buckets of this HashSet.
275-
*/
276-
private int capacity() {
277-
return this.buckets.length; // returns the number of buckets.
278-
}
279-
280281
/**
281282
* If the load factor is exceeded, the capacity is increased by doubling it (possibly triggered after an add operation),
282283
* or if the load factor falls below 1/4 (arbitrary) of the capacity (and the capacity is larger than the minimum capacity), the

0 commit comments

Comments
 (0)