This commit is contained in:
Alexey Kudravtsev
2015-04-09 14:38:55 +03:00
parent 9b17070a0c
commit 5d1063adaa
2 changed files with 11 additions and 8 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,11 +37,14 @@ public class ConcurrentPackedBitsArray {
chunksPerWord = 64 / bitsPerChunk;
}
// returns chunk bits
/**
* returns {@link #bitsPerChunk} bits stored at the offset "id"
* The returned bits are LSB, other (64-bitsPerChunk) higher bits are undefined
*/
public long get(int id) {
int bitIndex = id/chunksPerWord * 64 + (id%chunksPerWord)*bitsPerChunk;
long word = bits.getWord(bitIndex) >> bitIndex;
return word & mask;
return word;
}
// stores chunk atomically, returns previous chunk
@@ -58,7 +61,7 @@ public class ConcurrentPackedBitsArray {
}
}) >> bitIndex;
return prevChunk & mask;
return prevChunk;
}
public void clear() {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +22,11 @@ public class ConcurrentPackedBitArrayTest extends TestCase {
ConcurrentPackedBitsArray bitSet = new ConcurrentPackedBitsArray(4);
int N = 3000;
for (int i=0; i<N;i++) {
assertEquals(0, bitSet.get(i));
assertEquals(0, bitSet.get(i) & 0xf);
bitSet.set(i, 0xa);
assertEquals(0xa, bitSet.get(i));
assertEquals(0xa, bitSet.get(i) & 0xf);
bitSet.set(i, 0x2);
assertEquals(0x2, bitSet.get(i));
assertEquals(0x2, bitSet.get(i) & 0xf);
}
try {