sonatype-lift[bot] commented on a change in pull request #453:
URL: https://github.com/apache/lucene/pull/453#discussion_r761116584



##########
File path: 
lucene/core/src/java/org/apache/lucene/util/packed/Packed64VHLongAndByte.java
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.util.packed;
+
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.BitUtil;
+import org.apache.lucene.util.RamUsageEstimator;
+
+import java.util.Arrays;
+
+/**
+ * Space optimized random access capable array of values with a fixed number 
of bits/value. Values
+ * are packed contiguously.
+ *
+ * <p>The implementation strives to perform as fast as possible under the 
constraint of contiguous
+ * bits, by avoiding expensive operations. This comes at the cost of code 
clarity.
+ *
+ * <p>Technical details: This implementation is a refinement of a 
non-branching version. The
+ * non-branching get and set methods meant that 2 or 4 atomics in the 
underlying array were always
+ * accessed, even for the cases where only 1 or 2 were needed. Even with 
caching, this had a
+ * detrimental effect on performance. Related to this issue, the old 
implementation used lookup
+ * tables for shifts and masks, which also proved to be a bit slower than 
calculating the shifts and
+ * masks on the fly. See https://issues.apache.org/jira/browse/LUCENE-4062 for 
details.
+ */
+class Packed64VHLongAndByte extends PackedInts.MutableImpl {
+  static final int BLOCK_SIZE = 64; // 32 = int, 64 = long
+  static final int BYTE_BITS = 3;
+  static final int BYTE_BLOCK_SIZE = 8;
+  static final int BYTE_BLOCK_MOD_MASK = BYTE_BLOCK_SIZE - 1; // x % BYTE_BLOCK
+
+  /** Values are stores contiguously in the blocks array. */
+  private final byte[] blocks;
+  /** A right-aligned mask of width BitsPerValue used by {@link #get(int)}. */
+  private final long maskRight;
+  /** Optimization: Saves one lookup in {@link #get(int)}. */
+  private final int bpvMinusBlockSize;
+
+  /**
+   * Creates an array with the internal structures adjusted for the given 
limits and initialized to
+   * 0.
+   *
+   * @param valueCount the number of elements.
+   * @param bitsPerValue the number of bits available for any given value.
+   */
+  public Packed64VHLongAndByte(int valueCount, int bitsPerValue) {
+    super(valueCount, bitsPerValue);
+    final PackedInts.Format format = PackedInts.Format.PACKED;
+    final long byteCount = format.byteCount(PackedInts.VERSION_CURRENT, 
valueCount, bitsPerValue);
+    if (bitsPerValue > 56) {
+      throw new IllegalArgumentException("Only bitsPerValue up to 56 allowed");
+    }
+    if (byteCount > ArrayUtil.MAX_ARRAY_LENGTH) {
+      throw new IllegalArgumentException("Too many values/bits to store");
+    }
+    this.blocks = new byte[(int) byteCount + Long.BYTES];
+    maskRight = ~0L << (BLOCK_SIZE - bitsPerValue) >>> (BLOCK_SIZE - 
bitsPerValue);
+    bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
+  }
+
+  /**
+   * @param index the position of the value.
+   * @return the value at the given index.
+   */
+  @Override
+  public long get(final int index) {
+    // The abstract index in a bit stream
+    final long majorBitPos = (long) index * bitsPerValue;
+    // The index in the backing byte-array
+    final int elementPos = (int) (majorBitPos >>> BYTE_BITS); // BYTE_BLOCK
+    // The number of bits already occupied from the previous position
+    final int maskOffset = (int) majorBitPos & BYTE_BLOCK_MOD_MASK;
+//    final int endBits = maskOffset + bpvMinusBlockSize;
+    // Read the main long
+    //final long packed = ((long) BitUtil.VH_LE_LONG.get(blocks, elementPos) 
>>> maskOffset) & maskRight;
+    return ((long) BitUtil.VH_LE_LONG.get(blocks, elementPos) >>> maskOffset) 
& maskRight;
+
+//    if (endBits <= 0) { // Single block
+//      return packed;
+//    }
+//    // compute next mask
+//    return packed | (blocks[elementPos + BYTE_BLOCK_SIZE] & ~(~0L << 
endBits)) << (BLOCK_SIZE - maskOffset);
+  }
+
+  @Override
+  public void set(final int index, final long value) {
+    // The abstract index in a contiguous bit stream
+    final long majorBitPos = (long) index * bitsPerValue;
+    // The index in the backing byte-array
+    final int elementPos = (int) (majorBitPos >>> BYTE_BITS); // / BYTE_BLOCK
+    // The number of bits already occupied from the previous position
+    final int maskOffset = (int) majorBitPos & BYTE_BLOCK_MOD_MASK;
+    final int endBits = maskOffset + bpvMinusBlockSize;
+    // Read the main long
+    final long packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+    BitUtil.VH_LE_LONG.set(blocks, elementPos, packed & ~(maskRight << 
maskOffset) | (value << maskOffset));

Review comment:
       *OperatorPrecedence:*  Use grouping parenthesis to make the operator 
precedence explicit 
[(details)](https://errorprone.info/bugpattern/OperatorPrecedence)
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with 
`help` or `ignore`)

##########
File path: 
lucene/core/src/java/org/apache/lucene/util/packed/Packed64VHLongLong.java
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.util.packed;
+
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.BitUtil;
+import org.apache.lucene.util.RamUsageEstimator;
+
+import java.sql.Array;
+import java.util.Arrays;
+
+/**
+ * Space optimized random access capable array of values with a fixed number 
of bits/value. Values
+ * are packed contiguously.
+ *
+ * <p>The implementation strives to perform as fast as possible under the 
constraint of contiguous
+ * bits, by avoiding expensive operations. This comes at the cost of code 
clarity.
+ *
+ * <p>Technical details: This implementation is a refinement of a 
non-branching version. The
+ * non-branching get and set methods meant that 2 or 4 atomics in the 
underlying array were always
+ * accessed, even for the cases where only 1 or 2 were needed. Even with 
caching, this had a
+ * detrimental effect on performance. Related to this issue, the old 
implementation used lookup
+ * tables for shifts and masks, which also proved to be a bit slower than 
calculating the shifts and
+ * masks on the fly. See https://issues.apache.org/jira/browse/LUCENE-4062 for 
details.
+ */
+class Packed64VHLongLong extends PackedInts.MutableImpl {
+    static final int BLOCK_SIZE = 64; // 32 = int, 64 = long
+    static final int BLOCK_BITS = 6; // The #bits representing BLOCK_SIZE
+    static final int MOD_MASK = BLOCK_SIZE - 1; // x % BLOCK_SIZE
+
+    /** Values are stores contiguously in the blocks array. */
+    private final byte[] blocks;
+    /** A right-aligned mask of width BitsPerValue used by {@link #get(int)}. 
*/
+    private final long maskRight;
+    /** Optimization: Saves one lookup in {@link #get(int)}. */
+    private final int bpvMinusBlockSize;
+
+    /**
+     * Creates an array with the internal structures adjusted for the given 
limits and initialized to
+     * 0.
+     *
+     * @param valueCount the number of elements.
+     * @param bitsPerValue the number of bits available for any given value.
+     */
+    public Packed64VHLongLong(int valueCount, int bitsPerValue) {
+        super(valueCount, bitsPerValue);
+        final PackedInts.Format format = PackedInts.Format.PACKED;
+        final long byteCount = format.byteCount(PackedInts.VERSION_CURRENT, 
valueCount, bitsPerValue);
+        if (byteCount > ArrayUtil.MAX_ARRAY_LENGTH) {
+            throw new IllegalArgumentException("Not yet supported");
+        }
+        this.blocks = new byte[(int) byteCount + 8];
+        maskRight = ~0L << (BLOCK_SIZE - bitsPerValue) >>> (BLOCK_SIZE - 
bitsPerValue);
+        bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
+    }
+
+    /**
+     * @param index the position of the value.
+     * @return the value at the given index.
+     */
+    @Override
+    public long get(final int index) {
+        // The abstract index in a bit stream
+        final long majorBitPos = (long) index * bitsPerValue;
+        // The index in the backing byte-array
+        final int elementPos = (int) (majorBitPos >>> BLOCK_BITS) * 8;
+        // read entry as a long
+        long packed;
+
+        // The number of value-bits in the second long
+        final long endBits = (majorBitPos & MOD_MASK) + bpvMinusBlockSize;
+
+        if (endBits <= 0) { // Single block
+            packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+            return (packed >>> -endBits) & maskRight;
+        }
+        // Two blocks
+        packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+        long next = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos + 8);
+        return ((packed << endBits) | (next >>> (BLOCK_SIZE - endBits)))
+                & maskRight;
+    }
+
+    @Override
+    public void set(final int index, final long value) {
+        // The abstract index in a contiguous bit stream
+        final long majorBitPos = (long) index * bitsPerValue;
+        // The index in the backing byte-array
+        final int elementPos = (int) (majorBitPos >>> BLOCK_BITS) * 8; // / 
BLOCK_SIZE
+        // The number of value-bits in the last block
+        final long endBits = (majorBitPos & MOD_MASK) + bpvMinusBlockSize;
+
+        long packed;
+        if (endBits <= 0) { // Single block
+            packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+            packed = packed & ~(maskRight << -endBits) | (value << -endBits);

Review comment:
       *OperatorPrecedence:*  Use grouping parenthesis to make the operator 
precedence explicit 
[(details)](https://errorprone.info/bugpattern/OperatorPrecedence)
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with 
`help` or `ignore`)

##########
File path: 
lucene/core/src/java/org/apache/lucene/util/packed/Packed64VHLongLong.java
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.util.packed;
+
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.BitUtil;
+import org.apache.lucene.util.RamUsageEstimator;
+
+import java.sql.Array;
+import java.util.Arrays;
+
+/**
+ * Space optimized random access capable array of values with a fixed number 
of bits/value. Values
+ * are packed contiguously.
+ *
+ * <p>The implementation strives to perform as fast as possible under the 
constraint of contiguous
+ * bits, by avoiding expensive operations. This comes at the cost of code 
clarity.
+ *
+ * <p>Technical details: This implementation is a refinement of a 
non-branching version. The
+ * non-branching get and set methods meant that 2 or 4 atomics in the 
underlying array were always
+ * accessed, even for the cases where only 1 or 2 were needed. Even with 
caching, this had a
+ * detrimental effect on performance. Related to this issue, the old 
implementation used lookup
+ * tables for shifts and masks, which also proved to be a bit slower than 
calculating the shifts and
+ * masks on the fly. See https://issues.apache.org/jira/browse/LUCENE-4062 for 
details.
+ */
+class Packed64VHLongLong extends PackedInts.MutableImpl {
+    static final int BLOCK_SIZE = 64; // 32 = int, 64 = long
+    static final int BLOCK_BITS = 6; // The #bits representing BLOCK_SIZE
+    static final int MOD_MASK = BLOCK_SIZE - 1; // x % BLOCK_SIZE
+
+    /** Values are stores contiguously in the blocks array. */
+    private final byte[] blocks;
+    /** A right-aligned mask of width BitsPerValue used by {@link #get(int)}. 
*/
+    private final long maskRight;
+    /** Optimization: Saves one lookup in {@link #get(int)}. */
+    private final int bpvMinusBlockSize;
+
+    /**
+     * Creates an array with the internal structures adjusted for the given 
limits and initialized to
+     * 0.
+     *
+     * @param valueCount the number of elements.
+     * @param bitsPerValue the number of bits available for any given value.
+     */
+    public Packed64VHLongLong(int valueCount, int bitsPerValue) {
+        super(valueCount, bitsPerValue);
+        final PackedInts.Format format = PackedInts.Format.PACKED;
+        final long byteCount = format.byteCount(PackedInts.VERSION_CURRENT, 
valueCount, bitsPerValue);
+        if (byteCount > ArrayUtil.MAX_ARRAY_LENGTH) {
+            throw new IllegalArgumentException("Not yet supported");
+        }
+        this.blocks = new byte[(int) byteCount + 8];
+        maskRight = ~0L << (BLOCK_SIZE - bitsPerValue) >>> (BLOCK_SIZE - 
bitsPerValue);
+        bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
+    }
+
+    /**
+     * @param index the position of the value.
+     * @return the value at the given index.
+     */
+    @Override
+    public long get(final int index) {
+        // The abstract index in a bit stream
+        final long majorBitPos = (long) index * bitsPerValue;
+        // The index in the backing byte-array
+        final int elementPos = (int) (majorBitPos >>> BLOCK_BITS) * 8;
+        // read entry as a long
+        long packed;
+
+        // The number of value-bits in the second long
+        final long endBits = (majorBitPos & MOD_MASK) + bpvMinusBlockSize;
+
+        if (endBits <= 0) { // Single block
+            packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+            return (packed >>> -endBits) & maskRight;
+        }
+        // Two blocks
+        packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+        long next = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos + 8);
+        return ((packed << endBits) | (next >>> (BLOCK_SIZE - endBits)))
+                & maskRight;
+    }
+
+    @Override
+    public void set(final int index, final long value) {
+        // The abstract index in a contiguous bit stream
+        final long majorBitPos = (long) index * bitsPerValue;
+        // The index in the backing byte-array
+        final int elementPos = (int) (majorBitPos >>> BLOCK_BITS) * 8; // / 
BLOCK_SIZE
+        // The number of value-bits in the last block
+        final long endBits = (majorBitPos & MOD_MASK) + bpvMinusBlockSize;
+
+        long packed;
+        if (endBits <= 0) { // Single block
+            packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+            packed = packed & ~(maskRight << -endBits) | (value << -endBits);
+            BitUtil.VH_LE_LONG.set(blocks, elementPos, packed);
+            return;
+        }
+        // Two blocks
+        packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+        long newPacked = packed & ~(maskRight >>> endBits) | (value >>> 
endBits);

Review comment:
       *OperatorPrecedence:*  Use grouping parenthesis to make the operator 
precedence explicit 
[(details)](https://errorprone.info/bugpattern/OperatorPrecedence)
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with 
`help` or `ignore`)

##########
File path: 
lucene/core/src/java/org/apache/lucene/util/packed/Packed64VHLongLong.java
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.util.packed;
+
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.BitUtil;
+import org.apache.lucene.util.RamUsageEstimator;
+
+import java.sql.Array;
+import java.util.Arrays;
+
+/**
+ * Space optimized random access capable array of values with a fixed number 
of bits/value. Values
+ * are packed contiguously.
+ *
+ * <p>The implementation strives to perform as fast as possible under the 
constraint of contiguous
+ * bits, by avoiding expensive operations. This comes at the cost of code 
clarity.
+ *
+ * <p>Technical details: This implementation is a refinement of a 
non-branching version. The
+ * non-branching get and set methods meant that 2 or 4 atomics in the 
underlying array were always
+ * accessed, even for the cases where only 1 or 2 were needed. Even with 
caching, this had a
+ * detrimental effect on performance. Related to this issue, the old 
implementation used lookup
+ * tables for shifts and masks, which also proved to be a bit slower than 
calculating the shifts and
+ * masks on the fly. See https://issues.apache.org/jira/browse/LUCENE-4062 for 
details.
+ */
+class Packed64VHLongLong extends PackedInts.MutableImpl {
+    static final int BLOCK_SIZE = 64; // 32 = int, 64 = long
+    static final int BLOCK_BITS = 6; // The #bits representing BLOCK_SIZE
+    static final int MOD_MASK = BLOCK_SIZE - 1; // x % BLOCK_SIZE
+
+    /** Values are stores contiguously in the blocks array. */
+    private final byte[] blocks;
+    /** A right-aligned mask of width BitsPerValue used by {@link #get(int)}. 
*/
+    private final long maskRight;
+    /** Optimization: Saves one lookup in {@link #get(int)}. */
+    private final int bpvMinusBlockSize;
+
+    /**
+     * Creates an array with the internal structures adjusted for the given 
limits and initialized to
+     * 0.
+     *
+     * @param valueCount the number of elements.
+     * @param bitsPerValue the number of bits available for any given value.
+     */
+    public Packed64VHLongLong(int valueCount, int bitsPerValue) {
+        super(valueCount, bitsPerValue);
+        final PackedInts.Format format = PackedInts.Format.PACKED;
+        final long byteCount = format.byteCount(PackedInts.VERSION_CURRENT, 
valueCount, bitsPerValue);
+        if (byteCount > ArrayUtil.MAX_ARRAY_LENGTH) {
+            throw new IllegalArgumentException("Not yet supported");
+        }
+        this.blocks = new byte[(int) byteCount + 8];
+        maskRight = ~0L << (BLOCK_SIZE - bitsPerValue) >>> (BLOCK_SIZE - 
bitsPerValue);
+        bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
+    }
+
+    /**
+     * @param index the position of the value.
+     * @return the value at the given index.
+     */
+    @Override
+    public long get(final int index) {
+        // The abstract index in a bit stream
+        final long majorBitPos = (long) index * bitsPerValue;
+        // The index in the backing byte-array
+        final int elementPos = (int) (majorBitPos >>> BLOCK_BITS) * 8;
+        // read entry as a long
+        long packed;
+
+        // The number of value-bits in the second long
+        final long endBits = (majorBitPos & MOD_MASK) + bpvMinusBlockSize;
+
+        if (endBits <= 0) { // Single block
+            packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+            return (packed >>> -endBits) & maskRight;
+        }
+        // Two blocks
+        packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+        long next = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos + 8);
+        return ((packed << endBits) | (next >>> (BLOCK_SIZE - endBits)))
+                & maskRight;
+    }
+
+    @Override
+    public void set(final int index, final long value) {
+        // The abstract index in a contiguous bit stream
+        final long majorBitPos = (long) index * bitsPerValue;
+        // The index in the backing byte-array
+        final int elementPos = (int) (majorBitPos >>> BLOCK_BITS) * 8; // / 
BLOCK_SIZE
+        // The number of value-bits in the last block
+        final long endBits = (majorBitPos & MOD_MASK) + bpvMinusBlockSize;
+
+        long packed;
+        if (endBits <= 0) { // Single block
+            packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+            packed = packed & ~(maskRight << -endBits) | (value << -endBits);
+            BitUtil.VH_LE_LONG.set(blocks, elementPos, packed);
+            return;
+        }
+        // Two blocks
+        packed = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos);
+        long newPacked = packed & ~(maskRight >>> endBits) | (value >>> 
endBits);
+        BitUtil.VH_LE_LONG.set(blocks, elementPos, newPacked);
+
+        long packed2 = (long) BitUtil.VH_LE_LONG.get(blocks, elementPos + 8);
+        long newPacked2 = packed2 & (~0L >>> endBits) | (value << (BLOCK_SIZE 
- endBits));

Review comment:
       *OperatorPrecedence:*  Use grouping parenthesis to make the operator 
precedence explicit 
[(details)](https://errorprone.info/bugpattern/OperatorPrecedence)
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with 
`help` or `ignore`)

##########
File path: 
lucene/core/src/java/org/apache/lucene/util/packed/Packed64VHLongAndByte.java
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.util.packed;
+
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.BitUtil;
+import org.apache.lucene.util.RamUsageEstimator;
+
+import java.util.Arrays;
+
+/**
+ * Space optimized random access capable array of values with a fixed number 
of bits/value. Values
+ * are packed contiguously.
+ *
+ * <p>The implementation strives to perform as fast as possible under the 
constraint of contiguous
+ * bits, by avoiding expensive operations. This comes at the cost of code 
clarity.
+ *
+ * <p>Technical details: This implementation is a refinement of a 
non-branching version. The
+ * non-branching get and set methods meant that 2 or 4 atomics in the 
underlying array were always
+ * accessed, even for the cases where only 1 or 2 were needed. Even with 
caching, this had a
+ * detrimental effect on performance. Related to this issue, the old 
implementation used lookup
+ * tables for shifts and masks, which also proved to be a bit slower than 
calculating the shifts and
+ * masks on the fly. See https://issues.apache.org/jira/browse/LUCENE-4062 for 
details.
+ */
+class Packed64VHLongAndByte extends PackedInts.MutableImpl {
+  static final int BLOCK_SIZE = 64; // 32 = int, 64 = long
+  static final int BYTE_BITS = 3;
+  static final int BYTE_BLOCK_SIZE = 8;
+  static final int BYTE_BLOCK_MOD_MASK = BYTE_BLOCK_SIZE - 1; // x % BYTE_BLOCK
+
+  /** Values are stores contiguously in the blocks array. */
+  private final byte[] blocks;
+  /** A right-aligned mask of width BitsPerValue used by {@link #get(int)}. */
+  private final long maskRight;
+  /** Optimization: Saves one lookup in {@link #get(int)}. */
+  private final int bpvMinusBlockSize;
+
+  /**
+   * Creates an array with the internal structures adjusted for the given 
limits and initialized to
+   * 0.
+   *
+   * @param valueCount the number of elements.
+   * @param bitsPerValue the number of bits available for any given value.
+   */
+  public Packed64VHLongAndByte(int valueCount, int bitsPerValue) {
+    super(valueCount, bitsPerValue);
+    final PackedInts.Format format = PackedInts.Format.PACKED;
+    final long byteCount = format.byteCount(PackedInts.VERSION_CURRENT, 
valueCount, bitsPerValue);
+    if (bitsPerValue > 56) {
+      throw new IllegalArgumentException("Only bitsPerValue up to 56 allowed");
+    }
+    if (byteCount > ArrayUtil.MAX_ARRAY_LENGTH) {
+      throw new IllegalArgumentException("Too many values/bits to store");
+    }
+    this.blocks = new byte[(int) byteCount + Long.BYTES];
+    maskRight = ~0L << (BLOCK_SIZE - bitsPerValue) >>> (BLOCK_SIZE - 
bitsPerValue);
+    bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
+  }
+
+  /**
+   * @param index the position of the value.
+   * @return the value at the given index.
+   */
+  @Override
+  public long get(final int index) {
+    // The abstract index in a bit stream
+    final long majorBitPos = (long) index * bitsPerValue;
+    // The index in the backing byte-array
+    final int elementPos = (int) (majorBitPos >>> BYTE_BITS); // BYTE_BLOCK
+    // The number of bits already occupied from the previous position
+    final int maskOffset = (int) majorBitPos & BYTE_BLOCK_MOD_MASK;
+//    final int endBits = maskOffset + bpvMinusBlockSize;
+    // Read the main long
+    //final long packed = ((long) BitUtil.VH_LE_LONG.get(blocks, elementPos) 
>>> maskOffset) & maskRight;
+    return ((long) BitUtil.VH_LE_LONG.get(blocks, elementPos) >>> maskOffset) 
& maskRight;
+
+//    if (endBits <= 0) { // Single block
+//      return packed;
+//    }
+//    // compute next mask
+//    return packed | (blocks[elementPos + BYTE_BLOCK_SIZE] & ~(~0L << 
endBits)) << (BLOCK_SIZE - maskOffset);
+  }
+
+  @Override
+  public void set(final int index, final long value) {
+    // The abstract index in a contiguous bit stream
+    final long majorBitPos = (long) index * bitsPerValue;
+    // The index in the backing byte-array
+    final int elementPos = (int) (majorBitPos >>> BYTE_BITS); // / BYTE_BLOCK
+    // The number of bits already occupied from the previous position
+    final int maskOffset = (int) majorBitPos & BYTE_BLOCK_MOD_MASK;
+    final int endBits = maskOffset + bpvMinusBlockSize;

Review comment:
       *UnusedVariable:*  The local variable 'endBits' is never read. 
[(details)](https://errorprone.info/bugpattern/UnusedVariable)
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with 
`help` or `ignore`)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to