Explorar o código

tuple class added

Boyoung- %!s(int64=9) %!d(string=hai) anos
pai
achega
e58e168ee7

+ 26 - 26
src/oram/Metadata.java

@@ -35,7 +35,7 @@ public class Metadata {
 	private int[] nBits;
 	private int[] lBits;
 	private int[] aBits;
-	
+
 	private int[] nBytes;
 	private int[] lBytes;
 	private int[] aBytes;
@@ -47,7 +47,7 @@ public class Metadata {
 	private long[] treeOffsets;
 
 	private long forestBytes;
-	
+
 	public Metadata() {
 		setup(CONFIG_FILE);
 	}
@@ -167,7 +167,7 @@ public class Metadata {
 		System.out.println();
 	}
 
-	public void write(String filename){
+	public void write(String filename) {
 		Yaml yaml = new Yaml();
 		FileWriter writer = null;
 		try {
@@ -187,94 +187,94 @@ public class Metadata {
 		yaml.dump(configMap, writer);
 	}
 
-	public void write(){
+	public void write() {
 		write(CONFIG_FILE);
 	}
-	
+
 	public int getTau() {
 		return tau;
 	}
-	
+
 	public int getTwoTauPow() {
 		return twoTauPow;
 	}
-	
+
 	public int getAddrBits() {
 		return addrBits;
 	}
-	
+
 	public int getW() {
 		return w;
 	}
-	
+
 	public int getDBytes() {
 		return dBytes;
 	}
-	
+
 	public int getTempStashSize() {
 		return tempStashSize;
 	}
-	
+
 	public int getNumTrees() {
 		return numTrees;
 	}
-	
+
 	public int getH() {
 		return h;
 	}
-	
+
 	public long getMaxNumRecords() {
 		return maxNumRecords;
 	}
-	
+
 	public long getNumInsertRecords() {
 		return numInsertRecords;
 	}
-	
+
 	public int getNBitsOfTree(int i) {
 		return nBits[i];
 	}
-	
+
 	public int getLBitsOfTree(int i) {
 		return lBits[i];
 	}
-	
+
 	public int getABitsOfTree(int i) {
 		return aBits[i];
 	}
-	
+
 	public int getNBytesOfTree(int i) {
 		return nBytes[i];
 	}
-	
+
 	public int getLBytesOfTree(int i) {
 		return lBytes[i];
 	}
-	
+
 	public int getABytesOfTree(int i) {
 		return aBytes[i];
 	}
-	
+
 	public int getTupleBytesOfTree(int i) {
 		return tupleBytes[i];
 	}
-	
+
 	public int getStashSizeOfTree(int i) {
 		return stashSizes[i];
 	}
-	
+
 	public long getNumBucketsOfTree(int i) {
 		return numBuckets[i];
 	}
-	
+
 	public long getTreeBytesOfTree(int i) {
 		return treeBytes[i];
 	}
-	
+
 	public long getTreeOffsetOfTree(int i) {
 		return treeOffsets[i];
 	}
-	
+
 	public long getForestBytes() {
 		return forestBytes;
 	}

+ 57 - 0
src/oram/Tuple.java

@@ -0,0 +1,57 @@
+package oram;
+
+import java.math.BigInteger;
+
+public class Tuple {
+	private byte[] F;
+	private byte[] N;
+	private byte[] L;
+	private byte[] A;
+
+	public Tuple(byte[] f, byte[] n, byte[] l, byte[] a) {
+		F = f.clone();
+		N = n.clone();
+		L = l.clone();
+		A = a.clone();
+	}
+
+	public byte[] getF() {
+		return F;
+	}
+
+	public byte[] getN() {
+		return N;
+	}
+
+	public byte[] getL() {
+		return L;
+	}
+
+	public byte[] getA() {
+		return A;
+	}
+
+	public byte[] toByteArray() {
+		byte[] tuple = new byte[F.length + N.length + L.length + A.length];
+		int offset = 0;
+		System.arraycopy(F, 0, tuple, offset, F.length);
+		offset += F.length;
+		System.arraycopy(N, 0, tuple, offset, N.length);
+		offset += N.length;
+		System.arraycopy(L, 0, tuple, offset, L.length);
+		offset += L.length;
+		System.arraycopy(A, 0, tuple, offset, A.length);
+		return tuple;
+	}
+
+	@Override
+	public String toString() {
+		String str = "Tuple: ";
+		str += ("F=" + new BigInteger(1, getF()).toString(2) + ", ");
+		str += ("N=" + new BigInteger(1, getN()).toString(2) + ", ");
+		str += ("L=" + new BigInteger(1, getL()).toString(2) + ", ");
+		str += ("A=" + new BigInteger(1, getA()).toString(2));
+		return str;
+	}
+
+}

+ 15 - 0
test/misc/HelloWorld.java

@@ -0,0 +1,15 @@
+package misc;
+
+import java.math.BigInteger;
+
+public class HelloWorld {
+
+	public static void main(String[] args) {
+		System.out.println("HelloWorld!");
+
+		byte[] tmp = new byte[0];
+		BigInteger bi = new BigInteger(1, tmp);
+		System.out.println(bi.toByteArray().length);
+	}
+
+}

+ 2 - 2
test/oram/TestMetadata.java

@@ -3,8 +3,8 @@ package oram;
 public class TestMetadata {
 
 	public static void main(String[] args) {
-		Metadata md = new Metadata();		
-		md.write("config/copy.yaml");		
+		Metadata md = new Metadata();
+		md.write("config/copy.yaml");
 		Metadata md2 = new Metadata("config/copy.yaml");
 		md2.write("config/copy2.yaml");
 	}

+ 24 - 0
test/oram/TestTuple.java

@@ -0,0 +1,24 @@
+package oram;
+
+import java.math.BigInteger;
+
+public class TestTuple {
+
+	public static void main(String[] args) {
+		byte[] F = new byte[] { 1 };
+		byte[] N = new byte[] { 2 };
+		byte[] L = new byte[] { 3 };
+		byte[] A = new byte[] { 4 };
+		Tuple tuple = new Tuple(F, N, L, A);
+		System.out.println(tuple);
+		System.out.println(new BigInteger(1, tuple.toByteArray()).toString(2));
+
+		F = new byte[0];
+		N = new byte[0];
+		L = new byte[0];
+		tuple = new Tuple(F, N, L, A);
+		System.out.println(tuple);
+		System.out.println(new BigInteger(1, tuple.toByteArray()).toString(2));
+	}
+
+}

+ 0 - 9
test/ui/HelloWorld.java

@@ -1,9 +0,0 @@
-package ui;
-
-public class HelloWorld {
-
-	public static void main(String[] args) {
-		System.out.println("HelloWorld!");
-	}
-
-}