use of java.util.concurrent.atomic.AtomicLongArray in project intellij-community by JetBrains.
the class ConcurrentBitSet method equals.
/**
* Compares this object against the specified object.
* The result is {@code true} if and only if the argument is
* not {@code null} and is a {@code ConcurrentBitSet} object that has
* exactly the same set of bits set to {@code true} as this bit
* set. That is, for every nonnegative {@code int} index {@code k},
* <pre>((ConcurrentBitSet)obj).get(k) == this.get(k)</pre>
* must be true. The current sizes of the two bit sets are not compared.
*
* @param obj the object to compare with
* @return {@code true} if the objects are the same;
* {@code false} otherwise
* @see #size()
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof ConcurrentBitSet)) {
return false;
}
if (this == obj) {
return true;
}
ConcurrentBitSet set = (ConcurrentBitSet) obj;
for (int i = 0; i < arrays.length(); i++) {
AtomicLongArray array1 = arrays.get(i);
AtomicLongArray array2 = set.arrays.get(i);
if (array1 == null && array2 == null)
continue;
int size = array1 == null ? array2.length() : array1.length();
for (int k = 0; k < size; k++) {
long word1 = array1 == null ? 0 : array1.get(k);
long word2 = array2 == null ? 0 : array2.get(k);
if (word1 != word2)
return false;
}
}
return true;
}
use of java.util.concurrent.atomic.AtomicLongArray in project intellij-community by JetBrains.
the class ConcurrentBitSet method getOrCreateArray.
@NotNull
private AtomicLongArray getOrCreateArray(int bitIndex) {
int arrayIndex = arrayIndex(bitIndex);
AtomicLongArray array;
// while loop is here because of clear() method
while ((array = arrays.get(arrayIndex)) == null) {
arrays.compareAndSet(arrayIndex, null, new AtomicLongArray(1 << arrayIndex));
}
return array;
}
use of java.util.concurrent.atomic.AtomicLongArray in project intellij-community by JetBrains.
the class ConcurrentBitSet method changeWord.
long changeWord(int bitIndex, @NotNull TLongFunction change) {
if (bitIndex < 0) {
throw new IndexOutOfBoundsException("bitIndex < 0: " + bitIndex);
}
AtomicLongArray array = getOrCreateArray(bitIndex);
int wordIndexInArray = wordIndexInArray(bitIndex);
long word;
long newWord;
do {
word = array.get(wordIndexInArray);
newWord = change.execute(word);
} while (!array.compareAndSet(wordIndexInArray, word, newWord));
return word;
}
use of java.util.concurrent.atomic.AtomicLongArray in project guava by google.
the class AtomicDoubleArray method readObject.
/**
* Reconstitutes the instance from a stream (that is, deserializes it).
*/
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
s.defaultReadObject();
// Read in array length and allocate array
int length = s.readInt();
this.longs = new AtomicLongArray(length);
// Read in all elements in the proper order.
for (int i = 0; i < length; i++) {
set(i, s.readDouble());
}
}
use of java.util.concurrent.atomic.AtomicLongArray in project guava by hceylan.
the class AtomicDoubleArray method readObject.
/**
* Reconstitutes the instance from a stream (that is, deserializes it).
*/
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
s.defaultReadObject();
// Read in array length and allocate array
int length = s.readInt();
this.longs = new AtomicLongArray(length);
// Read in all elements in the proper order.
for (int i = 0; i < length; i++) {
set(i, s.readDouble());
}
}
Aggregations