From 65180392b3c48f1abfaadffeff7e37002553334f Mon Sep 17 00:00:00 2001
From: cirnoooo123 <1601169949@qq.com>
Date: Wed, 19 Apr 2023 22:18:46 +0800
Subject: [PATCH] implement SecretUnion
---
data/pom.xml | 11 ++
.../openhufu/data/storage/ArrayDataSet.java | 6 +-
.../openhufu/data/storage/RandomDataSet.java | 171 ++++++++++++++++
.../openhufu/data/storage/DataSetTest.java | 44 +++++
.../com/hufudb/openhufu/mpc/ProtocolType.java | 4 +-
.../openhufu/mpc/union/SecretUnion.java | 187 ++++++++++++++++++
.../mpc/secretUnion/SecretUnionTest.java | 182 +++++++++++++++++
pom.xml | 7 +
8 files changed, 609 insertions(+), 3 deletions(-)
create mode 100644 data/src/main/java/com/hufudb/openhufu/data/storage/RandomDataSet.java
create mode 100644 mpc/src/main/java/com/hufudb/openhufu/mpc/union/SecretUnion.java
create mode 100644 mpc/src/test/java/com/hufudb/openhufu/mpc/secretUnion/SecretUnionTest.java
diff --git a/data/pom.xml b/data/pom.xml
index 9b3d8ed8..6ccecce3 100644
--- a/data/pom.xml
+++ b/data/pom.xml
@@ -46,6 +46,17 @@
org.locationtech.jts
jts-core
+
+ org.apache.commons
+ commons-math3
+ compile
+
+
+ com.hufudb.openhufu
+ openhufu-common
+ ${project.version}
+ compile
+
diff --git a/data/src/main/java/com/hufudb/openhufu/data/storage/ArrayDataSet.java b/data/src/main/java/com/hufudb/openhufu/data/storage/ArrayDataSet.java
index 81fcd7ed..5b458970 100644
--- a/data/src/main/java/com/hufudb/openhufu/data/storage/ArrayDataSet.java
+++ b/data/src/main/java/com/hufudb/openhufu/data/storage/ArrayDataSet.java
@@ -9,7 +9,7 @@ public class ArrayDataSet implements MaterializedDataSet {
final List rows;
final int rowCount;
- ArrayDataSet(Schema schema, List rows) {
+ public ArrayDataSet(Schema schema, List rows) {
this.schema = schema;
this.rows = rows;
this.rowCount = rows.size();
@@ -50,6 +50,10 @@ public int rowCount() {
return rowCount;
}
+ public List getRows() {
+ return rows;
+ }
+
class Iterator implements DataSetIterator {
int pointer;
diff --git a/data/src/main/java/com/hufudb/openhufu/data/storage/RandomDataSet.java b/data/src/main/java/com/hufudb/openhufu/data/storage/RandomDataSet.java
new file mode 100644
index 00000000..9012f320
--- /dev/null
+++ b/data/src/main/java/com/hufudb/openhufu/data/storage/RandomDataSet.java
@@ -0,0 +1,171 @@
+package com.hufudb.openhufu.data.storage;
+
+import com.hufudb.openhufu.common.exception.ErrorCode;
+import com.hufudb.openhufu.common.exception.OpenHuFuException;
+import com.hufudb.openhufu.data.schema.Schema;
+import com.hufudb.openhufu.proto.OpenHuFuData;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.math3.distribution.LaplaceDistribution;
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.GeometryFactory;
+import org.locationtech.jts.geom.Point;
+
+import java.util.*;
+import java.util.function.Function;
+
+public class RandomDataSet {
+ public final static GeometryFactory geoFactory = new GeometryFactory();
+ private final static double RANDOM_SET_SCALE = 0.5;
+ private final static double EPS = 1.0;
+ public final static int RANDOM_SET_OFFSET = 10;
+ private final static LaplaceDistribution lap = new LaplaceDistribution(0, 1 / EPS);
+ private final static Random random = new Random();
+ private final Schema schema;
+ private final DataSet source;
+ private final List originRows;
+ private final int originSize;
+ private final int resultSize;
+ private final List randomRows;
+ private final Map