mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-12-22 10:11:52 +01:00
Merge e2774d59aa
into 72eda9a24f
This commit is contained in:
commit
aacb9fb548
@ -11,7 +11,9 @@ import com.twitter.search.common.util.io.flushable.DataSerializer;
|
|||||||
import com.twitter.search.common.util.io.flushable.FlushInfo;
|
import com.twitter.search.common.util.io.flushable.FlushInfo;
|
||||||
import com.twitter.search.common.util.io.flushable.Flushable;
|
import com.twitter.search.common.util.io.flushable.Flushable;
|
||||||
|
|
||||||
// Modeled after TwitterCharBlockPool, with a lot of simplification.
|
/**
|
||||||
|
* Modeled after TwitterCharBlockPool, with a lot of simplification.
|
||||||
|
*/
|
||||||
public class IntBlockPool implements Flushable {
|
public class IntBlockPool implements Flushable {
|
||||||
private static final SearchLongGauge INT_BLOCK_POOL_MAX_LENGTH =
|
private static final SearchLongGauge INT_BLOCK_POOL_MAX_LENGTH =
|
||||||
SearchLongGauge.export("twitter_int_block_pool_max_size");
|
SearchLongGauge.export("twitter_int_block_pool_max_size");
|
||||||
@ -109,12 +111,16 @@ public class IntBlockPool implements Flushable {
|
|||||||
return (currBlockIndex << BLOCK_SHIFT) + currBlockOffset - 1;
|
return (currBlockIndex << BLOCK_SHIFT) + currBlockOffset - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns number of ints in this blocks
|
/**
|
||||||
|
* Returns number of ints in this blocks
|
||||||
|
*/
|
||||||
public int length() {
|
public int length() {
|
||||||
return currBlockOffset + currBlockIndex * BLOCK_SIZE;
|
return currBlockOffset + currBlockIndex * BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets an int from the specified index.
|
/**
|
||||||
|
* Gets an int from the specified index.
|
||||||
|
*/
|
||||||
public final int get(int index) {
|
public final int get(int index) {
|
||||||
return getBlock(index)[getOffsetInBlock(index)];
|
return getBlock(index)[getOffsetInBlock(index)];
|
||||||
}
|
}
|
||||||
@ -132,7 +138,9 @@ public class IntBlockPool implements Flushable {
|
|||||||
return pool.blocks[blockIndex];
|
return pool.blocks[blockIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets an int value at the specified index.
|
/**
|
||||||
|
* Sets an int value at the specified index.
|
||||||
|
*/
|
||||||
public void set(int index, int value) {
|
public void set(int index, int value) {
|
||||||
final int blockIndex = index >>> BLOCK_SHIFT;
|
final int blockIndex = index >>> BLOCK_SHIFT;
|
||||||
final int offset = index & BLOCK_MASK;
|
final int offset = index & BLOCK_MASK;
|
||||||
|
@ -21,7 +21,7 @@ public abstract class SearchSortUtils {
|
|||||||
int high = end;
|
int high = end;
|
||||||
Preconditions.checkState(comparator.compare(low, key) <= comparator.compare(high, key));
|
Preconditions.checkState(comparator.compare(low, key) <= comparator.compare(high, key));
|
||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
int mid = (low + high) >>> 1;
|
int mid = (low & high) + ((low ^ high) >>> 1);
|
||||||
int result = comparator.compare(mid, key);
|
int result = comparator.compare(mid, key);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
low = mid + 1;
|
low = mid + 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user