Updated by adding VLong-related files
git-svn-id: https://hyracks.googlecode.com/svn/branches/fullstack_genomix@2856 123451ca-8445-de46-9d55-352943316053
diff --git a/genomix/genomix-core/src/main/java/edu/uci/ics/genomix/data/normalizers/VLongNormalizedKeyComputerFactory.java b/genomix/genomix-core/src/main/java/edu/uci/ics/genomix/data/normalizers/VLongNormalizedKeyComputerFactory.java
new file mode 100644
index 0000000..f3a3e72
--- /dev/null
+++ b/genomix/genomix-core/src/main/java/edu/uci/ics/genomix/data/normalizers/VLongNormalizedKeyComputerFactory.java
@@ -0,0 +1,62 @@
+package edu.uci.ics.genomix.data.normalizers;
+
+import edu.uci.ics.hyracks.api.dataflow.value.INormalizedKeyComputer;
+import edu.uci.ics.hyracks.api.dataflow.value.INormalizedKeyComputerFactory;
+
+public class VLongNormalizedKeyComputerFactory implements INormalizedKeyComputerFactory {
+ private static final long serialVersionUID = 8735044913496854551L;
+
+ @Override
+ public INormalizedKeyComputer createNormalizedKeyComputer() {
+ return new INormalizedKeyComputer() {
+ private static final int POSTIVE_LONG_MASK = (3 << 30);
+ private static final int NON_NEGATIVE_INT_MASK = (2 << 30);
+ private static final int NEGATIVE_LONG_MASK = (0 << 30);
+
+
+ private long getLong(byte[] bytes, int offset) {
+ int l = (int)Math.ceil((double)bytes[offset]/4.0);
+ int n = (l<8)?l:8;
+
+ long r = 0;
+ for(int i = 0 ; i < n ; i++){
+ r <<= 8;
+ r += (long) (bytes[offset + 1] & 0xff);
+ }
+
+ return r;
+ }
+
+
+ @Override
+ public int normalize(byte[] bytes, int start, int length) {
+ long value = getLong(bytes, start);
+
+ int highValue = (int) (value >> 32);
+ if (highValue > 0) {
+ /** * larger than Integer.MAX */
+ int highNmk = getKey(highValue);
+ highNmk >>= 2;
+ highNmk |= POSTIVE_LONG_MASK;
+ return highNmk;
+ } else if (highValue == 0) {
+ /** * smaller than Integer.MAX but >=0 */
+ int lowNmk = (int) value;
+ lowNmk >>= 2;
+ lowNmk |= NON_NEGATIVE_INT_MASK;
+ return lowNmk;
+ } else {
+ /** * less than 0: have not optimized for that */
+ int highNmk = getKey(highValue);
+ highNmk >>= 2;
+ highNmk |= NEGATIVE_LONG_MASK;
+ return highNmk;
+ }
+ }
+
+ private int getKey(int value) {
+ return value ^ Integer.MIN_VALUE;
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git a/genomix/genomix-core/src/main/java/edu/uci/ics/genomix/data/std/accessors/VLongBinaryHashFunctionFamily.java b/genomix/genomix-core/src/main/java/edu/uci/ics/genomix/data/std/accessors/VLongBinaryHashFunctionFamily.java
new file mode 100644
index 0000000..2cd66e9
--- /dev/null
+++ b/genomix/genomix-core/src/main/java/edu/uci/ics/genomix/data/std/accessors/VLongBinaryHashFunctionFamily.java
@@ -0,0 +1,31 @@
+package edu.uci.ics.genomix.data.std.accessors;
+
+import edu.uci.ics.genomix.data.std.primitive.VLongPointable;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryHashFunction;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryHashFunctionFamily;
+import edu.uci.ics.hyracks.data.std.api.IHashable;
+
+public class VLongBinaryHashFunctionFamily implements
+ IBinaryHashFunctionFamily {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public IBinaryHashFunction createBinaryHashFunction(final int seed) {
+
+ return new IBinaryHashFunction() {
+ private VLongPointable p = new VLongPointable();
+
+ @Override
+ public int hash(byte[] bytes, int offset, int length) {
+ if (length + offset >= bytes.length)
+ throw new IllegalStateException("out of bound");
+ p.set(bytes, offset, length);
+ int hash = Math.abs(((IHashable) p).hash() * (seed + 1));
+ if (hash < 0) {
+ hash = Math.abs(hash + 1);
+ }
+ return hash;
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git a/genomix/genomix-core/src/main/java/edu/uci/ics/genomix/data/std/primitive/VLongPointable.java b/genomix/genomix-core/src/main/java/edu/uci/ics/genomix/data/std/primitive/VLongPointable.java
new file mode 100644
index 0000000..65978d7
--- /dev/null
+++ b/genomix/genomix-core/src/main/java/edu/uci/ics/genomix/data/std/primitive/VLongPointable.java
@@ -0,0 +1,141 @@
+package edu.uci.ics.genomix.data.std.primitive;
+
+import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
+import edu.uci.ics.hyracks.data.std.api.AbstractPointable;
+import edu.uci.ics.hyracks.data.std.api.IComparable;
+import edu.uci.ics.hyracks.data.std.api.IHashable;
+import edu.uci.ics.hyracks.data.std.api.INumeric;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.api.IPointableFactory;
+
+public final class VLongPointable extends AbstractPointable implements IHashable, IComparable, INumeric {
+ static private int max = 65535;
+ public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean isFixedLength() {
+ return false;
+ }
+
+ @Override
+ public int getFixedLength() {
+ return -1;
+ }
+ };
+
+ public static final IPointableFactory FACTORY = new IPointableFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public IPointable createPointable() {
+ return new VLongPointable();
+ }
+
+ @Override
+ public ITypeTraits getTypeTraits() {
+ return TYPE_TRAITS;
+ }
+ };
+
+
+
+ public static long getLong(byte[] bytes, int start) {
+ int l = (int)Math.ceil((double)bytes[start]/4.0);
+ int n = (l<8)?l:8;
+
+ long r = 0;
+ for(int i = 0 ; i < n ; i++){
+ r <<= 8;
+ r += (long) (bytes[start + 1] & 0xff);
+ }
+
+ return r;
+ }
+
+ public long getLong() {
+ return getLong(bytes, start);
+ }
+
+ public byte[] postIncrement() {
+ int i = start + 1;
+ int l = (int)Math.ceil(bytes[start]/4);
+ while(i <= start+l){
+ bytes[i] += 1;
+ if(bytes[i] != 0){
+ break;
+ }
+ }
+ return bytes;
+ }
+
+ @Override
+ public int compareTo(IPointable pointer) {
+ return compareTo(pointer.getByteArray(), pointer.getStartOffset(), pointer.getLength());
+ }
+
+ @Override
+ public int compareTo(byte[] bytes, int start, int length) {
+
+ int be = this.start;
+ int n = (this.bytes[be] < bytes[start])? this.bytes[be] : bytes[start];
+ int l = (int)Math.ceil(n/4);
+ for(int i = 0 ; i <= l ; i++){
+ if(this.bytes[i]<bytes[i]){
+ return -1;
+ }
+ else if(this.bytes[i]>bytes[i]){
+ return 1;
+ }
+
+ }
+
+ return (this.bytes[be] < bytes[start])? -1 : ((this.bytes[be] > bytes[start])?1:0);
+ }
+
+ @Override
+ public int hash() {//BKDRHash
+ int seed = 131; // 31 131 1313 13131 131313 etc..
+ int hash = 0;
+ int l = (int)Math.ceil((double)bytes[start]/4.0);
+ for(int i = start + 1 ; i <= start + l ; i++)
+ {
+ hash = hash * seed + bytes[i];
+ }
+ return (hash & 0x7FFFFFFF);
+ }
+
+ @Override
+ public byte byteValue() {
+ return (byte) bytes[start+1];
+ }
+
+ @Override
+ public short shortValue() {
+
+ return (short) ((bytes[start+2] & 0xff) << 8 + bytes[start+1] & 0xff);
+ }
+
+ @Override
+ public int intValue() {
+ return (int) ( (bytes[start + 4] & 0xff) << 24 + (bytes[start + 3] & 0xff) <<16 +
+ (bytes[start + 2] & 0xff) << 8 + bytes[start + 1] & 0xff);
+ }
+
+
+
+ @Override
+ public long longValue() {
+ return getLong();
+ }
+
+ @Override
+ public float floatValue() {
+ return getLong();
+ }
+
+ @Override
+ public double doubleValue() {
+ return getLong();
+ }
+}