Top Description Inners Fields Constructors Methods
io.netty.util.internal.shaded.org.jctools.maps

public Class NonBlockingSetInt

extends AbstractSet<Integer>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Static Imports
io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess.UNSAFE, .UnsafeAccess.fieldOffset

A multi-threaded bit-vector set, implemented as an array of primitive 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.

Author
Cliff Click
Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class

Field Summary

Modifier and TypeField and Description
private transient NonBlockingSetInt.NBSI
private static final long
private static final long

Constructor Summary

AccessConstructor and Description
public
NonBlockingSetInt()

Create a new empty bit-vector

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if i was added to the set.
add
(final Integer
element to be added to this set
i
)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Add i to the set.
public boolean

Returns:

true if i was added to the set.
add
(final int
element to be added to this set
i
)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Add i to the set.
private final boolean
public void
public boolean

Returns:

true if i was in the set.
contains
(final Object
element whose presence in this set is to be tested
o
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Test if o is in the set.
public boolean

Returns:

true if i was int the set.
contains
(final int i)

Test if i is in the set.

public Iterator<Integer>
public int
length()

Approx largest element in set; at least as big (but max might be smaller).

private void
public boolean

Returns:

true if i was removed to the set.
remove
(final Object
object to be removed from this set, if present
o
)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Remove o from the set.
public boolean

Returns:

true if i was added to the set.
remove
(final int i)

Remove i from the set.

public int

Returns:

count of elements.
size
()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Current count of elements in the set.
private void
Inherited from java.util.AbstractSet:
equalshashCoderemoveAll

Field Detail

_nbsiback to summary
private transient NonBlockingSetInt.NBSI _nbsi
_nbsi_offsetback to summary
private static final long _nbsi_offset
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

NonBlockingSetIntback to summary
public NonBlockingSetInt()

Create a new empty bit-vector

Method Detail

addback to summary
public boolean add(final Integer i)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Add i to the set. Uppercase Integer version of add, requires auto-unboxing. When possible use the int version of add(int) for efficiency.

Parameters
i:Integer

Doc from java.util.Set.add.

element to be added to this set

Returns:boolean

true if i was added to the set.

Exceptions
IllegalArgumentException:
if i is negative.
addback to summary
public boolean add(final int i)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Add i to the set. This is the lower-case 'int' version of add - no autoboxing. Negative values throw IllegalArgumentException.

Parameters
i:int

Doc from java.util.Set.add.

element to be added to this set

Returns:boolean

true if i was added to the set.

Exceptions
IllegalArgumentException:
if i is negative.
CAS_nbsiback to summary
private final boolean CAS_nbsi(NonBlockingSetInt.NBSI old, NonBlockingSetInt.NBSI nnn)
clearback to summary
public void clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.Set.clear, java.util.Collection.clear.

Empty the bitvector.

containsback to summary
public boolean contains(final Object o)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Test if 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.

Parameters
o:Object

Doc from java.util.Set.contains.

element whose presence in this set is to be tested

Returns:boolean

true if i was in the set.

containsback to summary
public boolean contains(final int i)

Test if i is in the set. This is the lower-case 'int' version of contains - no autoboxing.

Returns:boolean

true if i was int the set.

iteratorback to summary
public Iterator<Integer> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Standard Java Iterator. Not very efficient because it auto-boxes the returned values.

Returns:Iterator<Integer>

Doc from java.util.Set.iterator.

an iterator over the elements in this set

lengthback to summary
public int length()

Approx largest element in set; at least as big (but max might be smaller).

readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
removeback to summary
public boolean remove(final Object o)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Remove 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.

Parameters
o:Object

Doc from java.util.Set.remove.

object to be removed from this set, if present

Returns:boolean

true if i was removed to the set.

removeback to summary
public boolean remove(final int i)

Remove i from the set. This is the fast lower-case 'int' version of remove - no autoboxing.

Returns:boolean

true if i was added to the set.

sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

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.

Returns:int

count of elements.

writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException
io.netty.util.internal.shaded.org.jctools.maps back to summary

private Class NonBlockingSetInt.iter

extends Object
implements Iterator<Integer>
Class Inheritance
  • java.lang.Object
  • io.netty.util.internal.shaded.org.jctools.maps.NonBlockingSetInt.iter
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv NonBlockingSetInt.NBSI
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv
iter()

Method Summary

Modifier and TypeMethod and Description
private void
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public Integer
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_idxback to summary
pack-priv int _idx
_nbsi2back to summary
pack-priv NonBlockingSetInt.NBSI _nbsi2
_prevback to summary
pack-priv int _prev

Constructor Detail

iterback to summary
pack-priv iter()

Method Detail

advanceback to summary
private void advance()
hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

nextback to summary
public Integer next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Integer

the next element in the iteration

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

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 forEachRemaining method.

io.netty.util.internal.shaded.org.jctools.maps back to summary

private final Class NonBlockingSetInt.NBSI

extends Object
Class Inheritance
  • java.lang.Object
  • io.netty.util.internal.shaded.org.jctools.maps.NonBlockingSetInt.NBSI

Field Summary

Modifier and TypeField and Description
private final long[]
private final transient AtomicInteger
private final transient AtomicInteger
private static final int
private static final int
private final NonBlockingSetInt.NBSI
private NonBlockingSetInt.NBSI
private static final long
private final transient NonBlockingSetInt
private final transient ConcurrentAutoTable
private final transient int

Constructor Summary

AccessConstructor and Description
private
NBSI(int max_elem, ConcurrentAutoTable ctr, NonBlockingSetInt nonb)

Method Summary

Modifier and TypeMethod and Description
public boolean
add(final int i)

private final boolean
CAS(int idx, long old, long nnn)

private final boolean
public boolean
contains(final int i)

private NonBlockingSetInt.NBSI
private NonBlockingSetInt.NBSI
private NonBlockingSetInt.NBSI
private static final long
mask(int i)

private void
print(int d, String msg)

private void
print(int d)

private static long
rawIndex(final long[] ary, final int idx)

public boolean
remove(final int i)

public int
size()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_bitsback to summary
private final long[] _bits
_copyDoneback to summary
private final transient AtomicInteger _copyDone
_copyIdxback to summary
private final transient AtomicInteger _copyIdx
_Lbaseback to summary
private static final int _Lbase
_Lscaleback to summary
private static final int _Lscale
_nbsi64back to summary
private final NonBlockingSetInt.NBSI _nbsi64
_newback to summary
private NonBlockingSetInt.NBSI _new
_new_offsetback to summary
private static final long _new_offset
_non_blocking_set_intback to summary
private final transient NonBlockingSetInt _non_blocking_set_int
_sizeback to summary
private final transient ConcurrentAutoTable _size
_sum_bits_lengthback to summary
private final transient int _sum_bits_length

Constructor Detail

NBSIback to summary
private NBSI(int max_elem, ConcurrentAutoTable ctr, NonBlockingSetInt nonb)

Method Detail

addback to summary
public boolean add(final int i)
CASback to summary
private final boolean CAS(int idx, long old, long nnn)
CAS_newback to summary
private final boolean CAS_new(NonBlockingSetInt.NBSI nnn)
containsback to summary
public boolean contains(final int i)
help_copyback to summary
private NonBlockingSetInt.NBSI help_copy()
help_copy_implback to summary
private NonBlockingSetInt.NBSI help_copy_impl(int i)
install_larger_new_bitsback to summary
private NonBlockingSetInt.NBSI install_larger_new_bits(final int i)
maskback to summary
private static final long mask(int i)
printback to summary
private void print(int d, String msg)
printback to summary
private void print(int d)
rawIndexback to summary
private static long rawIndex(final long[] ary, final int idx)
removeback to summary
public boolean remove(final int i)
sizeback to summary
public int size()