Repository: incubator-drill
Updated Branches:
  refs/heads/master ab2795173 -> f948d710e


DRILL-826: Improve efficiency of BitVector when getting and setting


Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/f948d710
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/f948d710
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/f948d710

Branch: refs/heads/master
Commit: f948d710e9647cf3d0b7d3a8edfb968dd137056f
Parents: ab27951
Author: Steven Phillips <sphill...@maprtech.com>
Authored: Thu May 22 19:37:24 2014 -0700
Committer: Jacques Nadeau <jacq...@apache.org>
Committed: Thu May 22 21:00:03 2014 -0700

----------------------------------------------------------------------
 .../org/apache/drill/exec/vector/BitVector.java | 26 ++++++++++----------
 1 file changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/f948d710/exec/java-exec/src/main/java/org/apache/drill/exec/vector/BitVector.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/BitVector.java 
b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/BitVector.java
index 5952c6c..14324b0 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/BitVector.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/BitVector.java
@@ -238,12 +238,10 @@ public final class BitVector extends BaseDataValueVector 
implements FixedWidthVe
      * @return 1 if set, otherwise 0
      */
     public final int get(int index) {
-      // logger.debug("BIT GET: index: {}, byte: {}, mask: {}, masked byte: 
{}",
-      // index,
-      // data.getByte((int)Math.floor(index/8)),
-      // (int)Math.pow(2, (index % 8)),
-      // data.getByte((int)Math.floor(index/8)) & (int)Math.pow(2, (index % 
8)));
-      return ((data.getByte((int) Math.floor(index / 8)) & (int) Math.pow(2, 
(index % 8))) == 0) ? 0 : 1;
+      int byteIndex = index >> 3;
+      byte b = data.getByte(byteIndex);
+      int bitIndex = index & 7;
+      return Long.bitCount(b &  (1L << bitIndex));
     }
 
     public boolean isNull(int index){
@@ -294,15 +292,17 @@ public final class BitVector extends BaseDataValueVector 
implements FixedWidthVe
      *          value to set (either 1 or 0)
      */
     public final void set(int index, int value) {
-      byte currentByte = data.getByte((int) Math.floor(index / 8));
+      int byteIndex = index >> 3;
+      int bitIndex = index & 7;
+      byte currentByte = data.getByte(byteIndex);
+      byte bitMask = (byte) (1L << bitIndex);
       if (value != 0) {
-        // true
-        currentByte |= (byte) Math.pow(2, (index % 8));
-      } else if ((currentByte & (byte) Math.pow(2, (index % 8))) == (byte) 
Math.pow(2, (index % 8))) {
-        // false, and bit was previously set
-        currentByte -= (byte) Math.pow(2, (index % 8));
+        currentByte |= bitMask;
+      } else {
+        currentByte -= (bitMask & currentByte);
       }
-      data.setByte((int) Math.floor(index / 8), currentByte);
+
+      data.setByte(byteIndex, currentByte);
     }
 
     public final void set(int index, BitHolder holder) {

Reply via email to