From e164847df4022baa09532df8f975255fb1507ab3 Mon Sep 17 00:00:00 2001 From: niugiaogiao Date: Sat, 1 Apr 2023 12:30:00 +0800 Subject: [PATCH 1/2] Change algorithm --- .../search/core/earlybird/index/util/SearchSortUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/com/twitter/search/core/earlybird/index/util/SearchSortUtils.java b/src/java/com/twitter/search/core/earlybird/index/util/SearchSortUtils.java index c17565784..444100c3b 100644 --- a/src/java/com/twitter/search/core/earlybird/index/util/SearchSortUtils.java +++ b/src/java/com/twitter/search/core/earlybird/index/util/SearchSortUtils.java @@ -21,7 +21,7 @@ public abstract class SearchSortUtils { int high = end; Preconditions.checkState(comparator.compare(low, key) <= comparator.compare(high, key)); while (low <= high) { - int mid = (low + high) >>> 1; + int mid = (low & high) + ((low ^ high) >>> 1); int result = comparator.compare(mid, key); if (result < 0) { low = mid + 1; From e2774d59aaf5c00cdf69c36c0edbb026946d5378 Mon Sep 17 00:00:00 2001 From: niugiaogiao Date: Sat, 1 Apr 2023 13:05:24 +0800 Subject: [PATCH 2/2] Change Comment --- .../earlybird/index/inverted/IntBlockPool.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/java/com/twitter/search/core/earlybird/index/inverted/IntBlockPool.java b/src/java/com/twitter/search/core/earlybird/index/inverted/IntBlockPool.java index bf85c8765..5a0e63252 100644 --- a/src/java/com/twitter/search/core/earlybird/index/inverted/IntBlockPool.java +++ b/src/java/com/twitter/search/core/earlybird/index/inverted/IntBlockPool.java @@ -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.Flushable; -// Modeled after TwitterCharBlockPool, with a lot of simplification. +/** + * Modeled after TwitterCharBlockPool, with a lot of simplification. + */ public class IntBlockPool implements Flushable { private static final SearchLongGauge INT_BLOCK_POOL_MAX_LENGTH = SearchLongGauge.export("twitter_int_block_pool_max_size"); @@ -109,12 +111,16 @@ public class IntBlockPool implements Flushable { return (currBlockIndex << BLOCK_SHIFT) + currBlockOffset - 1; } - // Returns number of ints in this blocks + /** + * Returns number of ints in this blocks + */ public int length() { 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) { return getBlock(index)[getOffsetInBlock(index)]; } @@ -132,7 +138,9 @@ public class IntBlockPool implements Flushable { 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) { final int blockIndex = index >>> BLOCK_SHIFT; final int offset = index & BLOCK_MASK;