Skip to content

Commit

Permalink
null value to put() explicitly disallowed
Browse files Browse the repository at this point in the history
  • Loading branch information
jbellis committed Jan 2, 2024
1 parent a8422d6 commit e06f227
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
import java.util.stream.IntStream;

/**
* A map (but not a Map) of int -> T where the int keys are dense and start at zero,
* A map (but not a Map) of int -> T where the int keys are dense-ish and start at zero,
* but the size of the map is not known in advance. This provides fast, concurrent
* updates and minimizes contention when the map is resized.
* <p>
* Once added via put(), the value associated with a key may be overwritten, but not removed.
* "Dense-ish" means that space is allocated for all keys from 0 to the highest key, but
* it is valid to have gaps in the keys. The value associated with "gap" keys is null.
*/
public class DenseIntMap<T> {
private volatile AtomicReferenceArray<T> objects;
Expand All @@ -47,6 +48,10 @@ public DenseIntMap(int initialSize) {
* @param key ordinal
*/
public void put(int key, T value) {
if (value == null) {
throw new IllegalArgumentException("put() value cannot be null -- use remove() instead");
}

ensureCapacity(key);
long stamp;
boolean isInsert = false;
Expand Down

0 comments on commit e06f227

Please sign in to comment.