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.
Modifier and Type | Class and Description |
---|---|
private class | |
private static class |
Modifier and Type | Field and Description |
---|---|
private transient NonBlockingSetInt. | |
private static final long | |
private static final long |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true if i was added to the set.element to be added to this set i)Overrides java. Implements java. i to the set.
|
public boolean | Returns: true if i was added to the set.element to be added to this set i)Overrides java. Implements java. i to the set.
|
private final boolean | |
public void | clear()
Overrides java. Implements java. |
public boolean | Returns: true if i was in the set.element whose presence in this set is to be tested o)Overrides java. Implements java. o is in the set.
|
public boolean | |
public Iterator | iterator()
Implements abstract java. Implements java. Iterator .
|
public int | |
public void | |
private void | |
public boolean | Returns: true if i was removed to the set.object to be removed from this set, if present o)Overrides java. Implements java. o from the set.
|
public boolean | |
public int | Returns: count of elements.Implements abstract java. Implements java. |
private void |
_nbsi | back to summary |
---|---|
private transient NonBlockingSetInt. |
_nbsi_offset | back to summary |
---|---|
private static final long _nbsi_offset |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID |
NonBlockingSetInt | back to summary |
---|---|
public NonBlockingSetInt() Create a new empty bit-vector |
add | back to summary |
---|---|
public boolean add(final Integer i) Overrides java. Implements java. Add
|
add | back to summary |
---|---|
public boolean add(final int i) Overrides java. Implements java. Add
|
CAS_nbsi | back to summary |
---|---|
private final boolean CAS_nbsi(NonBlockingSetInt. |
clear | back to summary |
---|---|
public void clear() Overrides java. Implements java. Empty the bitvector. |
contains | back to summary |
---|---|
public boolean contains(final Object o) Overrides java. Implements java. Test if
|
contains | back to summary |
---|---|
public boolean contains(final int i) Test if
|
iterator | back to summary |
---|---|
public Iterator Implements abstract java. Implements java. Standard Java
|
length | back to summary |
---|---|
public int length() Approx largest element in set; at least as big (but max might be smaller). |
back to summary | |
---|---|
public void print() Verbose printout of internal structure for debugging. |
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException |
remove | back to summary |
---|---|
public boolean remove(final Object o) Overrides java. Implements java. Remove
|
remove | back to summary |
---|---|
public boolean remove(final int i) Remove
|
size | back to summary |
---|---|
public int size() Implements abstract java. Implements java. Current count of elements in the set. Due to concurrent racing updates, the size is only ever approximate. Updates due to the calling thread are immediately visible to calling thread.
|
writeObject | back to summary |
---|---|
private void writeObject(ObjectOutputStream s) throws IOException |
Modifier and Type | Field and Description |
---|---|
pack-priv int | |
pack-priv NonBlockingSetInt. | |
pack-priv int |
Access | Constructor and Description |
---|---|
pack-priv |
Modifier and Type | Method and Description |
---|---|
private void | |
public boolean | |
public Integer | |
public void | remove()
Overrides default java. |
_idx | back to summary |
---|---|
pack-priv int _idx |
_nbsi2 | back to summary |
---|---|
pack-priv NonBlockingSetInt. |
_prev | back to summary |
---|---|
pack-priv int _prev |
iter | back to summary |
---|---|
pack-priv iter() |
advance | back to summary |
---|---|
private void advance() |
hasNext | back to summary |
---|---|
public boolean hasNext() Implements java. Doc from java. Returns
|
next | back to summary |
---|---|
public Integer next() Implements java. Doc from java. Returns the next element in the iteration.
|
remove | back to summary |
---|---|
public void remove() Overrides default java. Doc from java. Removes from the underlying collection the last element returned
by this iterator (optional operation). This method can be called
only once per call to The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.
The behavior of an iterator is unspecified if this method is called
after a call to the |
Modifier and Type | Field and Description |
---|---|
private final long[] | |
private final transient AtomicInteger | |
private final transient AtomicInteger | |
private static final int | |
private static final int | |
private final NonBlockingSetInt. | |
private NonBlockingSetInt. | |
private static final long | |
private final transient NonBlockingSetInt | |
private final transient ConcurrentAutoTable | |
private final transient int |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public boolean | |
private final boolean | |
private final boolean | |
public boolean | |
private NonBlockingSetInt. | |
private NonBlockingSetInt. | |
private NonBlockingSetInt. | |
private static final long | |
private void | |
private void | |
private static long | |
public boolean | |
public int |
_bits | back to summary |
---|---|
private final long[] _bits |
_copyDone | back to summary |
---|---|
private final transient AtomicInteger _copyDone |
_copyIdx | back to summary |
---|---|
private final transient AtomicInteger _copyIdx |
_Lbase | back to summary |
---|---|
private static final int _Lbase |
_Lscale | back to summary |
---|---|
private static final int _Lscale |
_nbsi64 | back to summary |
---|---|
private final NonBlockingSetInt. |
_new | back to summary |
---|---|
private NonBlockingSetInt. |
_new_offset | back to summary |
---|---|
private static final long _new_offset |
_non_blocking_set_int | back to summary |
---|---|
private final transient NonBlockingSetInt _non_blocking_set_int |
_size | back to summary |
---|---|
private final transient ConcurrentAutoTable _size |
_sum_bits_length | back to summary |
---|---|
private final transient int _sum_bits_length |
NBSI | back to summary |
---|---|
private NBSI(int max_elem, ConcurrentAutoTable ctr, NonBlockingSetInt nonb) |
add | back to summary |
---|---|
public boolean add(final int i) |
CAS | back to summary |
---|---|
private final boolean CAS(int idx, long old, long nnn) |
CAS_new | back to summary |
---|---|
private final boolean CAS_new(NonBlockingSetInt. |
contains | back to summary |
---|---|
public boolean contains(final int i) |
help_copy | back to summary |
---|---|
private NonBlockingSetInt. |
help_copy_impl | back to summary |
---|---|
private NonBlockingSetInt. |
install_larger_new_bits | back to summary |
---|---|
private NonBlockingSetInt. |
mask | back to summary |
---|---|
private static final long mask(int i) |
back to summary | |
---|---|
private void print(int d, String msg) |
back to summary | |
---|---|
private void print(int d) |
rawIndex | back to summary |
---|---|
private static long rawIndex(final long[] ary, final int idx) |
remove | back to summary |
---|---|
public boolean remove(final int i) |
size | back to summary |
---|---|
public int size() |