hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject [1/4] hbase git commit: HBASE-12415 Add add(byte[][] arrays) to Bytes (Jean-Marc Spaggiari)
Date Sat, 02 May 2015 01:18:41 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 2f09b39f2 -> 4a0516deb
  refs/heads/branch-1.0 7a2e77244 -> de5b226b0
  refs/heads/branch-1.1 bbcc9c2bb -> 7cc85d367
  refs/heads/master a6027aedb -> 1c4b47f85


HBASE-12415 Add add(byte[][] arrays) to Bytes (Jean-Marc Spaggiari)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1c4b47f8
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1c4b47f8
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1c4b47f8

Branch: refs/heads/master
Commit: 1c4b47f856050796f491db3671349aec3220d237
Parents: a6027ae
Author: Andrew Purtell <apurtell@apache.org>
Authored: Fri May 1 18:12:36 2015 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Fri May 1 18:12:36 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/hadoop/hbase/util/Bytes.java  | 18 ++++++++++++++++++
 .../org/apache/hadoop/hbase/util/TestBytes.java   | 13 +++++++++++++
 2 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/1c4b47f8/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
index 0a30809..80bfe5f 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
@@ -1807,6 +1807,24 @@ public class Bytes implements Comparable<Bytes> {
   }
 
   /**
+   * @param arrays all the arrays to concatenate together.
+   * @return New array made from the concatenation of the given arrays.
+   */
+  public static byte [] add(final byte [][] arrays) {
+    int length = 0;
+    for (int i = 0; i < arrays.length; i++) {
+      length += arrays[i].length;
+    }
+    byte [] result = new byte[length];
+    int index = 0;
+    for (int i = 0; i < arrays.length; i++) {
+      System.arraycopy(arrays[i], 0, result, index, arrays[i].length);
+      index += arrays[i].length;
+    }
+    return result;
+  }
+
+  /**
    * @param a array
    * @param length amount of bytes to grab
    * @return First <code>length</code> bytes from <code>a</code>

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c4b47f8/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
index eb5e453..aa13223 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
@@ -49,6 +49,19 @@ public class TestBytes extends TestCase {
     assertNotNull(ee);
   }
 
+  public void testAdd () throws Exception {
+    byte[] a = {0,0,0,0,0,0,0,0,0,0};
+    byte[] b = {1,1,1,1,1,1,1,1,1,1,1};
+    byte[] c = {2,2,2,2,2,2,2,2,2,2,2,2};
+    byte[] d = {3,3,3,3,3,3,3,3,3,3,3,3,3};
+    byte[] result1 = Bytes.add (a, b, c);
+    byte[] result2 = Bytes.add (new byte[][] {a, b, c});
+    assertEquals(0, Bytes.compareTo(result1, result2));
+    byte[] result4 = Bytes.add (result1, d);
+    byte[] result5 = Bytes.add (new byte[][] {result1, d});
+    assertEquals(0, Bytes.compareTo(result1, result2));
+  }
+
   public void testSplit() throws Exception {
     byte [] lowest = Bytes.toBytes("AAA");
     byte [] middle = Bytes.toBytes("CCC");


Mime
View raw message