use of com.aerospike.client.Value.StringValue in project aerospike-client-java by aerospike.
the class TestOperateHll method operateSimilarity.
@Test
public void operateSimilarity() {
double[] overlaps = new double[] { 0.0001, 0.001, 0.01, 0.1, 0.5 };
for (double overlap : overlaps) {
long expectedIntersectCount = (long) (nEntries * overlap);
ArrayList<Value> common = new ArrayList<Value>();
for (int i = 0; i < expectedIntersectCount; i++) {
common.add(new StringValue("common" + i));
}
ArrayList<List<Value>> vals = new ArrayList<List<Value>>();
long uniqueEntriesPerNode = (nEntries - expectedIntersectCount) / 3;
for (int i = 0; i < keys.length; i++) {
ArrayList<Value> subVals = new ArrayList<Value>();
for (int j = 0; j < uniqueEntriesPerNode; j++) {
subVals.add(new StringValue("key" + i + " " + j));
}
vals.add(subVals);
}
for (ArrayList<Integer> desc : legalDescriptions) {
int nIndexBits = desc.get(0);
int nMinhashBits = desc.get(1);
if (nMinhashBits == 0) {
continue;
}
assertSimilarityOp(overlap, common, vals, nIndexBits, nMinhashBits);
}
}
}
use of com.aerospike.client.Value.StringValue in project aerospike-client-java by aerospike.
the class TestOperateHll method operateFold.
@Test
public void operateFold() {
List<Value> vals0 = new ArrayList<Value>();
List<Value> vals1 = new ArrayList<Value>();
for (int i = 0; i < nEntries / 2; i++) {
vals0.add(new StringValue("key " + i));
}
for (int i = nEntries / 2; i < nEntries; i++) {
vals1.add(new StringValue("key " + i));
}
for (int nIndexBits = 4; nIndexBits < maxNIndexBits; nIndexBits++) {
assertFold(vals0, vals1, nIndexBits);
}
}
use of com.aerospike.client.Value.StringValue in project aerospike-client-java by aerospike.
the class TestOperateHll method operateGetUnion.
@Test
public void operateGetUnion() {
int nIndexBits = 14;
long expectedUnionCount = 0;
ArrayList<List<Value>> vals = new ArrayList<List<Value>>();
List<HLLValue> hlls = new ArrayList<HLLValue>();
for (int i = 0; i < keys.length; i++) {
ArrayList<Value> subVals = new ArrayList<Value>();
for (int j = 0; j < nEntries / 3; j++) {
subVals.add(new StringValue("key" + i + " " + j));
}
Record record = assertSuccess("init other keys", keys[i], Operation.delete(), HLLOperation.add(HLLPolicy.Default, binName, subVals, nIndexBits), Operation.get(binName));
List<?> resultList = record.getList(binName);
hlls.add((HLLValue) resultList.get(1));
expectedUnionCount += subVals.size();
vals.add(subVals);
}
// Keep record around win binName is removed.
assertSuccess("other bin", key, Operation.delete(), HLLOperation.init(HLLPolicy.Default, binName + "other", nIndexBits), HLLOperation.add(HLLPolicy.Default, binName, vals.get(0), nIndexBits));
Record record = assertSuccess("union and unionCount", key, HLLOperation.getUnion(binName, hlls), HLLOperation.getUnionCount(binName, hlls));
List<?> resultList = record.getList(binName);
long unionCount = (Long) resultList.get(1);
assertHLLCount("verify union count", nIndexBits, unionCount, expectedUnionCount);
HLLValue unionHll = (HLLValue) resultList.get(0);
record = assertSuccess("", key, Operation.put(new Bin(binName, unionHll)), HLLOperation.getCount(binName));
resultList = record.getList(binName);
long unionCount2 = (Long) resultList.get(1);
assertEquals("unions equal", unionCount, unionCount2);
}
use of com.aerospike.client.Value.StringValue in project aerospike-client-java by aerospike.
the class TestOperateHll method createData.
@BeforeClass
public static void createData() {
for (int i = 0; i < nEntries; i++) {
entries.add(new StringValue("key " + i));
}
for (int nIndexBits = minNIndexBits; nIndexBits <= maxNIndexBits; nIndexBits += 4) {
int nCombinedBits = maxNMinhashBits + nIndexBits;
int maxAllowedNMinhashBits = maxNMinhashBits;
if (nCombinedBits > 64) {
maxAllowedNMinhashBits -= nCombinedBits - 64;
}
int midNMinhashBits = (maxAllowedNMinhashBits + nIndexBits) / 2;
ArrayList<Integer> legalZero = new ArrayList<Integer>();
ArrayList<Integer> legalMin = new ArrayList<Integer>();
ArrayList<Integer> legalMid = new ArrayList<Integer>();
ArrayList<Integer> legalMax = new ArrayList<Integer>();
legalNIndexBits.add(nIndexBits);
legalZero.add(nIndexBits);
legalMin.add(nIndexBits);
legalMid.add(nIndexBits);
legalMax.add(nIndexBits);
legalZero.add(0);
legalMin.add(minNMinhashBits);
legalMid.add(midNMinhashBits);
legalMax.add(maxAllowedNMinhashBits);
legalDescriptions.add(legalZero);
legalDescriptions.add(legalMin);
legalDescriptions.add(legalMid);
legalDescriptions.add(legalMax);
}
for (int indexBits = minNIndexBits - 1; indexBits <= maxNIndexBits + 5; indexBits += 4) {
if (indexBits < minNIndexBits || indexBits > maxNIndexBits) {
ArrayList<Integer> illegalZero = new ArrayList<Integer>();
ArrayList<Integer> illegalMin = new ArrayList<Integer>();
ArrayList<Integer> illegalMax = new ArrayList<Integer>();
illegalZero.add(indexBits);
illegalMin.add(indexBits);
illegalMax.add(indexBits);
illegalZero.add(0);
illegalMin.add(minNMinhashBits - 1);
illegalMax.add(maxNMinhashBits);
illegalDescriptions.add(illegalZero);
illegalDescriptions.add(illegalMin);
illegalDescriptions.add(illegalMax);
} else {
ArrayList<Integer> illegalMin = new ArrayList<Integer>();
ArrayList<Integer> illegalMax = new ArrayList<Integer>();
ArrayList<Integer> illegalMax1 = new ArrayList<Integer>();
illegalMin.add(indexBits);
illegalMax.add(indexBits);
illegalMin.add(minNMinhashBits - 1);
illegalMax.add(maxNMinhashBits + 1);
illegalDescriptions.add(illegalMin);
illegalDescriptions.add(illegalMax);
if (indexBits + maxNMinhashBits > 64) {
illegalMax1.add(indexBits);
illegalMax1.add(1 + maxNMinhashBits - (64 - (indexBits + maxNMinhashBits)));
illegalDescriptions.add(illegalMax1);
}
}
}
}
use of com.aerospike.client.Value.StringValue in project aerospike-client-java by aerospike.
the class TestOperateHll method operateSetUnion.
@Test
public void operateSetUnion() {
ArrayList<List<Value>> vals = new ArrayList<List<Value>>();
for (int i = 0; i < keys.length; i++) {
ArrayList<Value> subVals = new ArrayList<Value>();
for (int j = 0; j < nEntries / 3; j++) {
subVals.add(new StringValue("key" + i + " " + j));
}
vals.add(subVals);
}
for (Integer nIndexBits : legalNIndexBits) {
assertSetUnion(vals, nIndexBits, false, false);
assertSetUnion(vals, nIndexBits, false, true);
assertSetUnion(vals, nIndexBits, true, false);
assertSetUnion(vals, nIndexBits, true, true);
}
}
Aggregations