public class NonBlockingSetInt extends AbstractSet<Integer> implements Serializable
longs. All operations are non-blocking and multi-threaded safe.
contains(int) calls are roughly the same speed as a {load, mask}
sequence. add(int) and remove(int) calls are a tad more
expensive than a {load, mask, store} sequence because they must use a CAS.
The bit-vector is auto-sizing.
General note of caution: The Set API allows the use of Integer
with silent autoboxing - which can be very expensive if many calls are
being made. Since autoboxing is silent you may not be aware that this is
going on. The built-in API takes lower-case ints and is much more
efficient.
Space: space is used in proportion to the largest element, as opposed to the number of elements (as is the case with hash-table based Set implementations). Space is approximately (largest_element/8 + 64) bytes. The implementation is a simple bit-vector using CAS for update.
| Constructor and Description |
|---|
NonBlockingSetInt()
Create a new empty bit-vector
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(int i)
Add
i to the set. |
boolean |
add(Integer i)
Add
i to the set. |
void |
clear()
Empty the bitvector.
|
boolean |
contains(int i)
Test if
i is in the set. |
boolean |
contains(Object o)
Test if
o is in the set. |
Iterator<Integer> |
iterator()
Standard Java
Iterator. |
int |
length()
Approx largest element in set; at least as big (but max might be smaller).
|
void |
print()
Verbose printout of internal structure for debugging.
|
boolean |
remove(int i)
Remove
i from the set. |
boolean |
remove(Object o)
Remove
o from the set. |
int |
size()
Current count of elements in the set.
|
equals, hashCode, removeAlladdAll, containsAll, isEmpty, retainAll, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddAll, containsAll, isEmpty, retainAll, spliterator, toArray, toArrayparallelStream, removeIf, streampublic boolean add(Integer i)
i to the set. Uppercase Integer version of add,
requires auto-unboxing. When possible use the int version of
add(int) for efficiency.add in interface Collection<Integer>add in interface Set<Integer>add in class AbstractCollection<Integer>IllegalArgumentException - if i is negative.public boolean contains(Object o)
o is in the set. This is the uppercase Integer
version of contains, requires a type-check and auto-unboxing. When
possible use the int version of contains(int) for
efficiency.contains in interface Collection<Integer>contains in interface Set<Integer>contains in class AbstractCollection<Integer>public boolean remove(Object o)
o from the set. This is the uppercase Integer
version of remove, requires a type-check and auto-unboxing. When
possible use the int version of remove(int) for
efficiency.remove in interface Collection<Integer>remove in interface Set<Integer>remove in class AbstractCollection<Integer>public boolean add(int i)
i to the set. This is the lower-case 'int' version
of add(java.lang.Integer) - no autoboxing. Negative values throw
IllegalArgumentException.IllegalArgumentException - if i is negative.public boolean contains(int i)
i is in the set. This is the lower-case 'int'
version of contains(java.lang.Object) - no autoboxing.public boolean remove(int i)
i from the set. This is the fast lower-case 'int'
version of remove(java.lang.Object) - no autoboxing.public int size()
size in interface Collection<Integer>size in interface Set<Integer>size in class AbstractCollection<Integer>public int length()
public void clear()
clear in interface Collection<Integer>clear in interface Set<Integer>clear in class AbstractCollection<Integer>public void print()
Copyright © 2013–2018. All rights reserved.