Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix the bug of PForDeltaDocIdSet does not all PForDelta.compressionOn…

…eBlockOpt() and adding New Tests to cover all test cases that the old p4d covers
  • Loading branch information...
commit dd4aeba47b382e47892aafee5ff2c189238380dd 1 parent 73dede5
Hao Yan authored
8 src/main/java/com/kamikaze/docidset/compression/PForDeltaWithBase.java
View
@@ -42,20 +42,20 @@ public int estimateCompSize(int[] inputBlock, int bits, int blockSize) throws Il
@Override
public CompResult compressOneBlock(int[] inputBlock, int bits, int blockSize, boolean flag) throws IllegalArgumentException {
- return compressOneBlock(inputBlock, bits, blockSize);
+ return compressOneBlock(inputBlock, blockSize);
}
/**
* Compress an integer array
*
* @param inputBlock the integer input array
- * @param bits the value of b in the PForDelta algorithm
* @param blockSize the block size which is 256 by default
* @return CompResult which contains the compressed size in number of bits and the reference to the compressed data
* @throws IllegalArgumentException
*/
- public CompResult compressOneBlock(int[] inputBlock, int bits, int blockSize) throws IllegalArgumentException {
- int[] compBlock = PForDelta.compressOneBlock(inputBlock, bits, blockSize);
+ public CompResult compressOneBlock(int[] inputBlock, int blockSize) throws IllegalArgumentException {
+
+ int[] compBlock = PForDelta.compressOneBlockOpt(inputBlock, blockSize);
CompResult res = new CompResult();
res.setCompressedSize(compBlock.length<<5);
res.setCompressedBlock(compBlock);
20 src/main/java/com/kamikaze/docidset/impl/PForDeltaDocIdSet.java
View
@@ -14,6 +14,7 @@
import com.kamikaze.docidset.utils.CompResult;
import com.kamikaze.docidset.utils.IntArray;
import com.kamikaze.docidset.utils.PForDeltaIntSegmentArray;
+import com.kamikaze.pfordelta.PForDelta;
/**
* This class implements the DocId set which is built on top of the optimized PForDelta algorithm (PForDeltaWithBase)
@@ -415,9 +416,9 @@ public void flush(int docId)
* Compress one block of integers using PForDelta
*
*/
- private CompResult PForDeltaCompressOneBlock(int[] srcData, int b)
+ private CompResult PForDeltaCompressOneBlock(int[] srcData)
{
- CompResult compRes = compBlockWithBase.compressOneBlock(srcData, b, _blockSize);
+ CompResult compRes = compBlockWithBase.compressOneBlock(srcData, _blockSize);
return compRes;
}
@@ -590,20 +591,9 @@ private CompResult PForDeltaCompressCurrentBlock()
int tmpB = currentB;
preProcessBlock(currentNoCompBlock, sizeOfCurrentNoCompBlock);
- int optSize = PForDeltaEstimateCompSize(currentNoCompBlock, tmpB);
-
- for (int i = 1; i < POSSIBLE_B.length; ++i)
- {
- tmpB = POSSIBLE_B[i];
- int curSize = PForDeltaEstimateCompSize(currentNoCompBlock, tmpB);
- if(curSize < optSize)
- {
- currentB = tmpB;
- optSize = curSize;
- }
- }
+
// return the compressed data achieved from the best b
- CompResult finalRes = PForDeltaCompressOneBlock(currentNoCompBlock, currentB);
+ CompResult finalRes = PForDeltaCompressOneBlock(currentNoCompBlock);
return finalRes;
}
8 src/main/java/com/kamikaze/docidset/utils/DocSetFactory.java
View
@@ -84,8 +84,8 @@ public static DocSet getDocSetInstance(int min, int max, int count, FOCUS hint)
return new OBSDocIdSet(max-min+1);
else
- //return new PForDeltaDocIdSet();
- return new P4DDocIdSet();
+ return new PForDeltaDocIdSet();
+ // return new P4DDocIdSet();
// All cases in consideration
case OPTIMAL:
@@ -94,8 +94,8 @@ public static DocSet getDocSetInstance(int min, int max, int count, FOCUS hint)
if(count < AbstractDocSet.DEFAULT_BATCH_SIZE)
return new IntArrayDocIdSet(count);
else
- //return new PForDeltaDocIdSet();
- return new P4DDocIdSet();
+ return new PForDeltaDocIdSet();
+ //return new P4DDocIdSet();
}
else if((((max-min)>>>LONG_SHIFT)+1)*2*INT_SIZE > count * INT_SIZE)
return new IntArrayDocIdSet(count);
8 src/main/java/com/kamikaze/pfordelta/Simple16.java
View
@@ -51,7 +51,8 @@
*/
public static final int s16Compress(int[] out, int outOffset, int[] in, int inOffset, int n, int blockSize)
{
- int numIdx, j, num, bits;
+ int numIdx=0, j=0, num=0, bits=0;
+ try{
for (numIdx = 0; numIdx < S16_NUMSIZE; numIdx++)
{
out[outOffset] = numIdx<<S16_BITSSIZE;
@@ -69,6 +70,11 @@ public static final int s16Compress(int[] out, int outOffset, int[] in, int inOf
return num;
}
}
+ }catch(Exception e)
+ {
+ System.out.println("s16Compress: " + "numIdx:" + numIdx + ",j:" + j + ",num:" + num + ",bits: " + bits);
+ e.printStackTrace();
+ }
return -1;
}
19 src/test/java/com/kamikaze/test/PForDeltaMultiThreadedAccessTest.java
View
@@ -11,25 +11,6 @@
import com.kamikaze.docidset.api.StatefulDSIterator;
import com.kamikaze.docidset.impl.PForDeltaDocIdSet;
-//public class PForDeltaMultiThreadedAccessTest {
-// public static void main(String[] args)
-// {
-// PForDeltaMultiThreadedAccessTest1 t1= new PForDeltaMultiThreadedAccessTest1();
-// try{
-// t1.testSkipPerformance();
-// t1.testMultiThreadedFind();
-// }
-// catch(IOException eio)
-// {
-// eio.printStackTrace();
-// }
-// catch(InterruptedException ei)
-// {
-// ei.printStackTrace();
-// }
-// }
-//}
-
// testing multiple threads: all threads share the same PForDeltaDocId set, and each thread has its own iterator iterating on it (only read operations).
public class PForDeltaMultiThreadedAccessTest {
int _length = 10;
6 ...t/java/com/kamikaze/test/TestBooleanDocIdSet.java → ...m/kamikaze/test/PForDeltaTestBooleanDocIdSet.java
View
@@ -16,9 +16,9 @@
import com.kamikaze.docidset.impl.NotDocIdSet;
import com.kamikaze.docidset.impl.OrDocIdSet;
-public class TestBooleanDocIdSet extends TestCase {
+public class PForDeltaTestBooleanDocIdSet extends TestCase {
@Test
- public void _testOrDocIdSet() throws Exception
+ public void testOrDocIdSet() throws Exception
{
System.out.println("Running testOrDocIdSet() Test case...");
DocIdSet[] DocList;
@@ -68,7 +68,7 @@ public void testNotDocIdSet() throws Exception
}
@Test
- public void _testAndDocIdSet() throws Exception
+ public void testAndDocIdSet() throws Exception
{
System.out.println("Running testOrDocIdSet() Test case...");
DocIdSet[] DocList;
10 ...est/java/com/kamikaze/test/TestDocSetFactory.java → ...com/kamikaze/test/PForDeltaTestDocSetFactory.java
View
@@ -7,13 +7,13 @@
import com.kamikaze.docidset.utils.DocSetFactory;
import com.kamikaze.docidset.utils.DocSetFactory.FOCUS;
-public class TestDocSetFactory {
+public class PForDeltaTestDocSetFactory {
private static int batch = 128;
private static String serial = "SerialDocSet";
- public TestDocSetFactory() {
+ public PForDeltaTestDocSetFactory() {
}
@@ -32,7 +32,7 @@ public void testDocSetFactory() {
assertEquals(set.getClass().getName(), "com.kamikaze.docidset.impl.IntArrayDocIdSet");
set = DocSetFactory.getDocSetInstance(min, max, count, FOCUS.SPACE);
- assertEquals(set.getClass().getName(), "com.kamikaze.docidset.impl.P4DDocIdSet");
+ assertEquals(set.getClass().getName(), "com.kamikaze.docidset.impl.PForDeltaDocIdSet");
//assertEquals(set.getClass().getName(), "com.kamikaze.docidset.impl.PForDeltaDocIdSet");
set = DocSetFactory.getDocSetInstance(min, max, count, FOCUS.OPTIMAL);
assertEquals(set.getClass().getName(), "com.kamikaze.docidset.impl.IntArrayDocIdSet");
@@ -46,7 +46,7 @@ public void testDocSetFactory() {
count *=10000;
set = DocSetFactory.getDocSetInstance(min, max, count, FOCUS.OPTIMAL);
- assertEquals(set.getClass().getName(), "com.kamikaze.docidset.impl.P4DDocIdSet");
+ assertEquals(set.getClass().getName(), "com.kamikaze.docidset.impl.PForDeltaDocIdSet");
// count *=10000;
// set = DocSetFactory.getDocSetInstance(min, max, count, FOCUS.OPTIMAL);
@@ -67,7 +67,7 @@ public void testDocSetFactory() {
count /= 10000000;
set = DocSetFactory.getDocSetInstance(min, max, count, FOCUS.SPACE);
- assertEquals(set.getClass().getName(), "com.kamikaze.docidset.impl.P4DDocIdSet");
+ assertEquals(set.getClass().getName(), "com.kamikaze.docidset.impl.PForDeltaDocIdSet");
// set = DocSetFactory.getDocSetInstance(min, max, count, FOCUS.SPACE);
// assertEquals(set.getClass().getName(), "com.kamikaze.docidset.impl.PForDeltaDocIdSet");
124 src/test/java/com/kamikaze/test/PForDeltaTestDocSetSerialization.java
View
@@ -0,0 +1,124 @@
+package com.kamikaze.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.lucene.search.DocIdSet;
+import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.util.OpenBitSet;
+import org.junit.Test;
+
+import com.kamikaze.docidset.api.DocSet;
+import com.kamikaze.docidset.api.StatefulDSIterator;
+import com.kamikaze.docidset.bitset.MyOpenBitSet;
+import com.kamikaze.docidset.impl.AndDocIdSet;
+import com.kamikaze.docidset.impl.IntArrayDocIdSet;
+import com.kamikaze.docidset.impl.NotDocIdSet;
+import com.kamikaze.docidset.impl.OBSDocIdSet;
+import com.kamikaze.docidset.impl.OrDocIdSet;
+import com.kamikaze.docidset.impl.PForDeltaDocIdSet;
+
+public class PForDeltaTestDocSetSerialization {
+
+ private static int batch = 128;
+
+ private static String serial = "src/test/test-data/SerialDocSet";
+
+ public PForDeltaTestDocSetSerialization() {
+
+ }
+
+
+ @Test
+ public void testNotDocSetSerialization() throws Exception {
+
+ System.out.println("");
+ System.out.println("Running NotDocIdSet Serialization Test case...");
+ System.out.println("----------------------------");
+
+ Random random = new Random();
+
+ int randomizer = 0;
+ int b = 0;
+ int length = 1000;
+ int max = 5400;
+
+ Set<Integer> intSet = new TreeSet<Integer>();
+ PForDeltaDocIdSet docSet = new PForDeltaDocIdSet(batch);
+ randomizer = 0;
+
+ for (int i = 1; i < 1000 + 1; i++) {
+
+ int bVal[] = new int[33];
+ for (int k = 0; k < batch; k++) {
+ b = randomizer + (int) (random.nextDouble() * 1000);
+ intSet.add(b);
+
+ }
+
+ randomizer += 1000;
+ }
+ for (Integer c : intSet) {
+ docSet.addDoc(c);
+ }
+
+ DocIdSet not = new NotDocIdSet(docSet, max);
+
+ try {
+ File f = new File(serial);
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
+ oos.writeObject(not);
+ oos.flush();
+ oos.close();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ NotDocIdSet not2 = null;
+
+ try {
+ InputStream f = new FileInputStream(new File(serial));
+ ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(f));
+ not2 = (NotDocIdSet) (ois.readObject());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ org.apache.lucene.search.DocIdSetIterator noit = not.iterator();
+ org.apache.lucene.search.DocIdSetIterator noit2 = not2.iterator();
+
+ try {
+ int docid;
+ while ((docid=noit.nextDoc())!=DocIdSetIterator.NO_MORE_DOCS) {
+ int docid2 = noit2.nextDoc();
+ assertFalse(intSet.contains(docid));
+ assertEquals(docid, docid2);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ }
+
+
+}
75 src/test/java/com/kamikaze/test/TestDocSets.java → .../java/com/kamikaze/test/PForDeltaTestDocSets.java
View
@@ -24,16 +24,18 @@
import com.kamikaze.docidset.impl.NotDocIdSet;
import com.kamikaze.docidset.impl.OBSDocIdSet;
import com.kamikaze.docidset.impl.OrDocIdSet;
-import com.kamikaze.docidset.impl.P4DDocIdSet;
+import com.kamikaze.docidset.impl.PForDeltaDocIdSet;
+import com.kamikaze.docidset.impl.PForDeltaDocIdSet;
+import com.kamikaze.docidset.impl.PForDeltaDocIdSet;
import com.kamikaze.docidset.utils.DocSetFactory;
import com.kamikaze.docidset.utils.DocSetFactory.FOCUS;
-public class TestDocSets {
+public class PForDeltaTestDocSets {
private static final FOCUS SPACE = null;
private static int batch = 128;
- public TestDocSets() {
+ public PForDeltaTestDocSets() {
}
@@ -349,13 +351,13 @@ public void testWideDocSkips() throws Exception {
}
_testWideDocSkips("Testing skips on IntArrayDocIdSet", pset6);
- P4DDocIdSet pset7 = new P4DDocIdSet();
+ PForDeltaDocIdSet pset7 = new PForDeltaDocIdSet();
orit = orSet.iterator();
while((docid = orit.nextDoc())!=DocIdSetIterator.NO_MORE_DOCS)
{
pset7.addDoc(docid);
}
- _testWideDocSkips("Testing skips on P4DDocIdSet", pset7);
+ _testWideDocSkips("Testing skips on PForDeltaDocIdSet", pset7);
OBSDocIdSet pset8 = new OBSDocIdSet(2000);
orit = orSet.iterator();
@@ -443,9 +445,9 @@ public void testAndDocIdSetSkipSanity() throws Exception{
2978, 2981, 2984, 2994, 2997 };
int set3[] = { 2994, 2997 };
- P4DDocIdSet pset1 = new P4DDocIdSet(batch);
+ PForDeltaDocIdSet pset1 = new PForDeltaDocIdSet(batch);
OpenBitSet pset2 = new OpenBitSet();
- P4DDocIdSet pset3 = new P4DDocIdSet(batch);
+ PForDeltaDocIdSet pset3 = new PForDeltaDocIdSet(batch);
for (int i = 0; i < set1.length; i++) {
pset1.addDoc(set1[i]);
@@ -501,14 +503,29 @@ public void testAndDocIdSetSkipSanity() throws Exception{
-
+ private int[] convertSetToUniqueSet(int[] input)
+ {
+ Set<Integer> uniqueSet = new TreeSet<Integer>();
+ for(int i=0; i<input.length; i++)
+ {
+ uniqueSet.add(input[i]);
+ }
+ Iterator<Integer> iter = uniqueSet.iterator();
+ int[] output = new int[uniqueSet.size()];
+ int k=0;
+ while(iter.hasNext())
+ {
+ output[k++] = iter.next();
+ }
+ return output;
+ }
@Test
public void testCombinationSanity()throws Exception {
System.out.println("");
int[] set1 = { 4, 19, 21, 35, 36, 43, 43, 73, 85, 104, 105, 106, 112, 118,
- 119, 138, 141, 145, 146, 146, 196, 200, 202, 217, 219, 220, 221, 239,
+ 119, 138, 141, 145, 146, 147, 196, 200, 202, 217, 219, 220, 221, 239,
242, 243, 261, 276, 280, 281, 295, 297, 306, 309, 319, 324, 359, 375,
376, 387, 398, 401, 406, 438, 442, 450, 450, 462, 469, 475, 495, 499,
505, 505, 513, 513, 526, 529, 569, 584, 589, 590, 609, 614, 633, 635,
@@ -551,6 +568,12 @@ public void testCombinationSanity()throws Exception {
int[] set5 = { 4, 1999 };
int[] set6 = { 2000 };
+ set1 = convertSetToUniqueSet(set1);
+ set2 = convertSetToUniqueSet(set2);
+ set3 = convertSetToUniqueSet(set3);
+ set4 = convertSetToUniqueSet(set4);
+
+
OpenBitSet ps1 = new OpenBitSet();
// Build open bit set
@@ -569,7 +592,7 @@ public void testCombinationSanity()throws Exception {
for (int i = 0; i < set3.length; i++)
ps3.set(set3[i]);
- P4DDocIdSet ps4 = new P4DDocIdSet(128);
+ PForDeltaDocIdSet ps4 = new PForDeltaDocIdSet(128);
// Build open bit set
for (int i = 0; i < set4.length; i++)
@@ -581,7 +604,7 @@ public void testCombinationSanity()throws Exception {
for (int i = 0; i < set5.length; i++)
ps5.set(set5[i]);
- P4DDocIdSet ps6 = new P4DDocIdSet(128);
+ PForDeltaDocIdSet ps6 = new PForDeltaDocIdSet(128);
ps6.addDoc(2000);
ArrayList<DocIdSet> sets = new ArrayList<DocIdSet>();
@@ -1242,7 +1265,7 @@ public void testDenseConstructionTime()
}
System.out.println("Time for OpenBitSet construction:"+(System.nanoTime()-time)+" ns");
time = System.nanoTime();
- P4DDocIdSet docSet3 = new P4DDocIdSet();
+ PForDeltaDocIdSet docSet3 = new PForDeltaDocIdSet();
for(int i=0;i<20000000;i++)
{
docSet3.addDoc(i+test);
@@ -1284,7 +1307,7 @@ public void testDenseConstructionTime()
// System.out.println("Time for"+(20000/5)+ " OBSDocSet Find:"+(System.nanoTime()-time)+" ns");
//
// time = System.nanoTime();
-// P4DDocIdSet docSet3 = new P4DDocIdSet();
+// PForDeltaDocIdSet docSet3 = new PForDeltaDocIdSet();
// for(int i=0;i<20000;i++)
// {
// docSet3.addDoc(i+5);
@@ -1300,14 +1323,14 @@ public void testDenseConstructionTime()
// }
@Test
- public void testFindOnP4D()
+ public void testFindOnP4D() throws IOException
{
System.out.println("");
System.out.println("Running testFindOnP4D...");
System.out.println("----------------------------");
- P4DDocIdSet docSet3 = new P4DDocIdSet();
+ PForDeltaDocIdSet docSet3 = new PForDeltaDocIdSet();
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i=0;i<20000;i+=5)
{
@@ -1323,7 +1346,7 @@ public void testFindOnP4D()
}
list.clear();
- docSet3 = new P4DDocIdSet();
+ docSet3 = new PForDeltaDocIdSet();
for(int i=0;i<20000;i+=6)
{
list.add(i);
@@ -1338,7 +1361,7 @@ public void testFindOnP4D()
list.clear();
- docSet3 = new P4DDocIdSet();
+ docSet3 = new PForDeltaDocIdSet();
assertFalse(docSet3.find(34));
for(int i=1;i<257;i++)
{
@@ -1361,7 +1384,7 @@ public void testFindOnP4D()
list.clear();
- docSet3 = new P4DDocIdSet();
+ docSet3 = new PForDeltaDocIdSet();
assertFalse(docSet3.find(34));
for(int i=1;i<33;i++)
{
@@ -1554,7 +1577,7 @@ public void testWideCombinationCase2() throws IOException {
for (int i = 0; i < set8.length; i++)
ps8.set(set8[i]);
- P4DDocIdSet ps9 = new P4DDocIdSet(128);
+ PForDeltaDocIdSet ps9 = new PForDeltaDocIdSet(128);
for (int i = 0; i < set9.length; i++)
ps9.addDoc(set9[i]);
@@ -1607,36 +1630,36 @@ public void testWideCombinationCase2() throws IOException {
}
+
@Test
public void testP4DDocIdSetNoExceptionCompressionRatio()
{
boolean failed = false;
System.out.println("");
- System.out.println("Running P4DeltaDocSet No Exception Compression Ratio test");
+ System.out.println("Running PForDeltaDocSet No Exception Compression Ratio test");
System.out.println("----------------------------");
final int max = 10000;
-
+ int c=0;
+ int counter =0;
for(int j = 0; j < 31; j++)
{
try
{
- P4DDocIdSet set = new P4DDocIdSet(batch);
+ PForDeltaDocIdSet set = new PForDeltaDocIdSet(batch);
long time = System.nanoTime();
- int counter=0;
- for(int c = 0; c >= 0 && counter < max; c += (1 << j))
+ for(c = 0; c >= 0 && counter < max; c += (1 << j))
{
set.addDoc(c);
counter++;
}
set.optimize();
//System.out.println("Time to construct:"+(System.nanoTime() - time)+" ns");
- System.out.println("Delta:" + (1 << j) + " numOfItems:" + counter + " Blob Size:"+set.totalBlobSize());
}
catch(Exception ex)
{
- System.out.println("Delta:" + (1 << j) + " Failed");
+ System.out.println("c: " + c + ", counter: " + counter + "Delta:" + (1 << j) + " Failed");
failed = true;
}
}
15 src/test/java/com/kamikaze/test/TestKamikaze.java → ...java/com/kamikaze/test/PForDeltaTestKamikaze.java
View
@@ -1,5 +1,6 @@
package com.kamikaze.test;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -15,11 +16,11 @@
import com.kamikaze.docidset.api.DocSet;
import com.kamikaze.docidset.impl.AndDocIdSet;
import com.kamikaze.docidset.impl.OrDocIdSet;
-import com.kamikaze.docidset.impl.P4DDocIdSet;
+import com.kamikaze.docidset.impl.PForDeltaDocIdSet;
import com.kamikaze.docidset.utils.DocSetFactory;
-public class TestKamikaze extends TestCase
+public class PForDeltaTestKamikaze extends TestCase
{
public void testMultipleIntersections() throws Exception
@@ -108,7 +109,7 @@ public void testForOutOfBounds() throws Exception
seen.add(nextDoc);
}
Collections.sort(nums);
- DocSet docs = new P4DDocIdSet();
+ DocSet docs = new PForDeltaDocIdSet();
boolean saw403 = false;
for (Integer integer : nums)
{
@@ -126,8 +127,8 @@ public void testPartialEmptyAnd() throws IOException
System.out.println("Running Partial Empty And Test case...");
System.out.println("-------------------------------------------");
- DocSet ds1 = new P4DDocIdSet();
- DocSet ds2 = new P4DDocIdSet();
+ DocSet ds1 = new PForDeltaDocIdSet();
+ DocSet ds2 = new PForDeltaDocIdSet();
ds2.addDoc(42);
ds2.addDoc(43);
ds2.addDoc(44);
@@ -136,8 +137,8 @@ public void testPartialEmptyAnd() throws IOException
docs.add(ds1);
docs.add(ds2);
OrDocIdSet orlist1 = new OrDocIdSet(docs);
- DocSet ds3 = new P4DDocIdSet();
- DocSet ds4 = new P4DDocIdSet();
+ DocSet ds3 = new PForDeltaDocIdSet();
+ DocSet ds4 = new PForDeltaDocIdSet();
ds4.addDoc(42);
ds4.addDoc(43);
ds4.addDoc(44);
142 ...a/com/kamikaze/test/TestParameterizedDocSets.java → ...ikaze/test/PForDeltaTestParameterizedDocSets.java
View
@@ -8,10 +8,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
+import java.util.Set;
import java.util.TreeSet;
import org.apache.lucene.search.DocIdSet;
@@ -28,9 +30,11 @@
import com.kamikaze.docidset.impl.NotDocIdSet;
import com.kamikaze.docidset.impl.OBSDocIdSet;
import com.kamikaze.docidset.impl.P4DDocIdSet;
+import com.kamikaze.docidset.impl.PForDeltaDocIdSet;
+import com.kamikaze.docidset.impl.PForDeltaDocIdSet;
@RunWith(Parameterized.class)
-public class TestParameterizedDocSets {
+public class PForDeltaTestParameterizedDocSets {
private static final int batch = 256;
@@ -40,7 +44,7 @@
private int _max = -1;
- public TestParameterizedDocSets(int length, int max) {
+ public PForDeltaTestParameterizedDocSets(int length, int max) {
super();
@@ -61,7 +65,6 @@ public static List data() {
-
@Test
public void testAnnounce()
{
@@ -103,13 +106,19 @@ public void testOBSDocIdSetIterateSanity() throws IOException {
for (int k = 0; k < batch; k++) {
list1.add(list.get(k));
- set.addDoc(list.get(k));
+
}
// System.out.println("At :" + i +" "+(randomizer-1000) +" " +
// randomizer);
}
+ Iterator<Integer> iter = list1.iterator();
+ while(iter.hasNext())
+ {
+ set.addDoc(iter.next());
+ }
+
totalCompressionTime = System.nanoTime() - now;
// System.out.println("Total compression time :"+totalCompressionTime+":
// for"+((double)batch*length)/1000000+" M numbers");
@@ -127,10 +136,8 @@ public void testOBSDocIdSetIterateSanity() throws IOException {
totalDecompressionTime = System.nanoTime() - now;
-
-
}
-
+
@Test
public void testOBSDocIdSetSkipSanity() {
double booster = ((_max*1.0)/(1000f*_length));
@@ -265,7 +272,6 @@ public void testOBSDocIdSetPerformance() throws IOException {
}
-
@Test
public void testIntArrayDocIdSetSkipSanity() {
@@ -408,12 +414,12 @@ public void testIntArrayDocIdSetIteratePerformance() {
}
@Test
- public void testP4DDocIdSetIteratePerformance() {
+ public void testPForDeltaDocIdSetIteratePerformance() throws IOException {
double booster = ((_max*1.0)/(1000f*_length));
- P4DDocIdSet set = new P4DDocIdSet(batch);
+ PForDeltaDocIdSet set = new PForDeltaDocIdSet(batch);
System.out.println("");
- System.out.println("Running P4DeltaDocSet Iterate Performance test");
+ System.out.println("Running PForDeltaDocIdSet Iterate Performance test");
System.out.println("----------------------------");
Random random = new Random();
// Minimum 5 bits
@@ -422,18 +428,26 @@ public void testP4DDocIdSetIteratePerformance() {
double totalDecompressionTime = 0;
List<Integer> list = new LinkedList<Integer>();
LinkedList<Integer> list2 = new LinkedList<Integer>();
+ Set<Integer> uniqueSet = new TreeSet<Integer>();
int val = 0 ;
for (int i = 1; i < _length + 1; i++) {
int bVal[] = new int[33];
for (int k = 0; k < batch; k++) {
val = randomizer + (int) (random.nextDouble() * 1000);
- list.add(val);
+ uniqueSet.add(val);
}
randomizer += 1000*booster;
}
+
+ Iterator<Integer> iter = uniqueSet.iterator();
+ while(iter.hasNext())
+ {
+ list.add(iter.next());
+ }
+
Collections.sort(list);
System.out.println("Largest Element in the List:"+list.get( list.size() -1 ));
@@ -460,13 +474,13 @@ public void testP4DDocIdSetIteratePerformance() {
System.out.println("Compression Ratio : "+ ((double)set.sizeInBytes())/(batch * _length * 4));
}
-
@Test
- public void testP4DDocIdSetNonBoundarySkipSanity() {
+ public void testPForDeltaDocIdSetNonBoundarySkipSanity() throws IOException {
double booster = ((_max*1.0)/(1000f*_length));
- P4DDocIdSet set = new P4DDocIdSet(batch);
+
+ PForDeltaDocIdSet set = new PForDeltaDocIdSet(batch);
System.out.println("");
- System.out.println("Running P4DeltaDocSet Non-Boundary skip test");
+ System.out.println("Running PForDeltaDocIdSet Non-Boundary skip test");
System.out.println("----------------------------");
Random random = new Random();
int extra = 35;
@@ -479,10 +493,10 @@ public void testP4DDocIdSetNonBoundarySkipSanity() {
double totalDecompressionTime = 0;
List<Integer> list = new LinkedList<Integer>();
-
+ Set<Integer> uniqueSet = new TreeSet<Integer>();
for (int i = 1; i < _length + 1; i++) {
for (int k = 0; k < batch; k++) {
- list.add(randomizer + (int) (random.nextDouble() * 1000));
+ uniqueSet.add(randomizer + (int) (random.nextDouble() * 1000));
}
randomizer += 1000*booster;
@@ -490,9 +504,15 @@ public void testP4DDocIdSetNonBoundarySkipSanity() {
randomizer += 1000*booster;
for (int i = 0; i < extra; i++)
- list.add(randomizer + (int) (random.nextDouble() * 1000));
+ uniqueSet.add(randomizer + (int) (random.nextDouble() * 1000));
int counter = 0;
+ Iterator<Integer> iter = uniqueSet.iterator();
+ while(iter.hasNext())
+ {
+ list.add(iter.next());
+ }
+
Collections.sort(list);
System.out.println("Largest Element in the List:"+list.get( list.size() -1 ));
// System.out.println(list);
@@ -533,13 +553,13 @@ public void testP4DDocIdSetNonBoundarySkipSanity() {
}
@Test
- public void testP4DDocIdSetNonBoundaryCompressionSanity() throws IOException {
+ public void testPForDeltaDocIdSetNonBoundaryCompressionSanity() throws IOException {
int extra = 34;
double booster = ((_max*1.0)/(1000f*_length));
int counter = 0;
- P4DDocIdSet set = new P4DDocIdSet(batch);
+ PForDeltaDocIdSet set = new PForDeltaDocIdSet(batch);
System.out.println("");
- System.out.println("Running P4DeltaDocSet Non-Boundary Compression Sanity test");
+ System.out.println("Running PForDeltaDocSet Non-Boundary Compression Sanity test");
System.out.println("----------------------------");
Random random = new Random();
// Minimum 5 bits
@@ -550,11 +570,12 @@ public void testP4DDocIdSetNonBoundaryCompressionSanity() throws IOException {
int randomizer = 0;
double totalDecompressionTime = 0;
List<Integer> list = new LinkedList<Integer>();
-
+ Set<Integer> uniqueSet = new TreeSet<Integer>();
+
for (int i = 1; i < size + 1; i++) {
for (int k = 0; k < batch; k++) {
counter++;
- list.add(randomizer + (int) (random.nextDouble() * 1000));
+ uniqueSet.add(randomizer + (int) (random.nextDouble() * 1000));
}
randomizer += 1000*booster;
@@ -565,7 +586,13 @@ public void testP4DDocIdSetNonBoundaryCompressionSanity() throws IOException {
for (int i = 0; i < extra; i++)
{
counter++;
- list.add(randomizer + (int) (random.nextDouble() * 1000));
+ uniqueSet.add(randomizer + (int) (random.nextDouble() * 1000));
+ }
+
+ Iterator<Integer> iter = uniqueSet.iterator();
+ while(iter.hasNext())
+ {
+ list.add(iter.next());
}
Collections.sort(list);
@@ -596,11 +623,11 @@ public void testP4DDocIdSetNonBoundaryCompressionSanity() throws IOException {
}
@Test
- public void testP4DDocIdSetSkipSanity() {
+ public void testPForDeltaDocIdSetSkipSanity() throws IOException {
double booster = ((_max*1.0)/(1000f*_length));
- P4DDocIdSet set = new P4DDocIdSet(batch);
+ PForDeltaDocIdSet set = new PForDeltaDocIdSet(batch);
System.out.println("");
- System.out.println("Running P4DeltaDocSet Skip Sanity test");
+ System.out.println("Running PForDeltaDocIdSet Skip Sanity test");
System.out.println("----------------------------");
Random random = new Random();
@@ -610,16 +637,22 @@ public void testP4DDocIdSetSkipSanity() {
double totalDecompressionTime = 0;
List<Integer> list = new LinkedList<Integer>();
LinkedList<Integer> list2 = new LinkedList<Integer>();
-
+ Set<Integer> uniqueSet = new TreeSet<Integer>();
for (int i = 1; i < _length + 1; i++) {
for (int k = 0; k < batch; k++) {
- list.add(randomizer + (int) (random.nextDouble() * 1000));
+ uniqueSet.add(randomizer + (int) (random.nextDouble() * 1000));
}
randomizer += 1000*booster;
}
+ Iterator<Integer> iter = uniqueSet.iterator();
+ while(iter.hasNext())
+ {
+ list.add(iter.next());
+ }
+
Collections.sort(list);
System.out.println("Largest Element in the List:"+list.get( list.size() -1 ));
long time = System.nanoTime();
@@ -660,7 +693,6 @@ public void testP4DDocIdSetSkipSanity() {
}
-
@Test
public void testSkipPerformance() throws IOException
{
@@ -669,9 +701,9 @@ public void testSkipPerformance() throws IOException
System.out.println("----------------------------");
double booster = ((_max*1.0)/(1000f*_length));
- P4DDocIdSet set = new P4DDocIdSet(batch);
+ PForDeltaDocIdSet set = new PForDeltaDocIdSet(batch);
System.out.println("");
- System.out.println("Running P4DeltaDocSet Skip Sanity test");
+ System.out.println("Running PForDeltaDocIdSet Skip Sanity test");
System.out.println("----------------------------");
Random random = new Random();
@@ -681,30 +713,36 @@ public void testSkipPerformance() throws IOException
double totalDecompressionTime = 0;
List<Integer> list = new LinkedList<Integer>();
LinkedList<Integer> list2 = new LinkedList<Integer>();
-
+ Set<Integer> uniqueSet = new TreeSet<Integer>();
for (int i = 1; i < _length + 1; i++) {
for (int k = 0; k < batch; k++) {
- list.add(randomizer + (int) (random.nextDouble() * 1000));
+ uniqueSet.add(randomizer + (int) (random.nextDouble() * 1000));
}
randomizer += 1000*booster;
}
+ Iterator<Integer> iter = uniqueSet.iterator();
+ while(iter.hasNext())
+ {
+ list.add(iter.next());
+ }
+
Collections.sort(list);
//System.out.println("Largest Element in the List:"+list.get( list.size() -1 ));
//P4D
- P4DDocIdSet p4d = new P4DDocIdSet();
+ PForDeltaDocIdSet pfd = new PForDeltaDocIdSet();
int counter=0;
for (Integer c : list) {
counter++;
- p4d.addDoc(c);
+ pfd.addDoc(c);
}
- StatefulDSIterator dcit = p4d.iterator();
+ StatefulDSIterator dcit = pfd.iterator();
_testSkipPerformance(list.get(list.size()-1),dcit);
// Int Array
@@ -713,7 +751,7 @@ public void testSkipPerformance() throws IOException
for (Integer c : list) {
counter++;
- p4d.addDoc(c);
+ pfd.addDoc(c);
}
dcit = iSet.iterator();
_testSkipPerformance(list.get(list.size()-1),dcit);
@@ -724,7 +762,7 @@ public void testSkipPerformance() throws IOException
for (Integer c : list) {
counter++;
- p4d.addDoc(c);
+ pfd.addDoc(c);
}
dcit = oSet.iterator();
_testSkipPerformance(list.get(list.size()-1),dcit);
@@ -748,6 +786,7 @@ private void _testSkipPerformance(int max, StatefulDSIterator dcit) throws IOExc
}
+
@Test
@Ignore
public void testAndDocIdSetPerformance() throws Exception{
@@ -768,24 +807,25 @@ public void testAndDocIdSetPerformance() throws Exception{
for (int j = 0; j < all; j++) {
ArrayList<Integer> intSet = new ArrayList<Integer>();
- P4DDocIdSet docSet = new P4DDocIdSet(batch);
+ PForDeltaDocIdSet docSet = new PForDeltaDocIdSet(batch);
+ Set<Integer> uniqueSet = new TreeSet<Integer>();
+
randomizer = 0;
for (int i = 1; i < size + 1; i++) {
for (int k = 0; k < batch; k++) {
- intSet.add(randomizer + (int) (random.nextDouble() * 1000));
+ uniqueSet.add(randomizer + (int) (random.nextDouble() * 1000));
}
randomizer += 1000*booster;
- Collections.sort(intSet);
-
+
}
- for (Integer c : intSet) {
+ for (Integer c : uniqueSet) {
docSet.addDoc(c);
}
docSets.add(docSet);
-
}
+
System.out.println("Constructed component DocSets");
org.apache.lucene.search.DocIdSetIterator oit = new AndDocIdSet(docSets).iterator();
long now = System.nanoTime();
@@ -825,7 +865,9 @@ public void testNotDocIdSet() throws IOException {
int randomizer = 0;
int b = 0;
ArrayList<Integer> intSet = new ArrayList<Integer>();
- P4DDocIdSet docSet = new P4DDocIdSet(batch);
+ PForDeltaDocIdSet docSet = new PForDeltaDocIdSet(batch);
+ Set<Integer> uniqueSet = new TreeSet<Integer>();
+
randomizer = 0;
for (int i = 1; i < length + 1; i++) {
@@ -833,16 +875,16 @@ public void testNotDocIdSet() throws IOException {
int bVal[] = new int[33];
for (int k = 0; k < batch; k++) {
b = randomizer + (int) (random.nextDouble() * 1000);
- intSet.add(b);
+ uniqueSet.add(b);
}
randomizer += 1000;
- Collections.sort(intSet);
+ // Collections.sort(intSet);
}
- for (Integer c : intSet) {
+ for (Integer c : uniqueSet) {
docSet.addDoc(c);
}
15 src/test/java/com/kamikaze/test/TestDocIdSetSuite.java
View
@@ -1,15 +0,0 @@
-package com.kamikaze.test;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
-
-@RunWith(Suite.class)
-//@SuiteClasses( {PForDeltaKamikazeTest.class})
-@SuiteClasses( { PForDeltaKamikazeTest.class, PForDeltaMultiThreadedAccessTest.class, TestBooleanDocIdSet.class, TestDocSetFactory.class, TestDocSets.class, TestDocSetSerialization.class, TestKamikaze.class, TestMultiThreadedAccess.class, TestParameterizedDocSets.class})
-//@SuiteClasses( { PForDeltaKamikazeTest.class})
-
-//@SuiteClasses( { PForDeltaMultiThreadedAccessTest.class, TestMultiThreadedAccess.class})
-public class TestDocIdSetSuite {
-}
-
827 src/test/java/com/kamikaze/test/TestDocSetSerialization.java
View
@@ -1,827 +0,0 @@
-package com.kamikaze.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-
-import org.apache.lucene.search.DocIdSet;
-import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.lucene.util.OpenBitSet;
-import org.junit.Test;
-
-import com.kamikaze.docidset.api.DocSet;
-import com.kamikaze.docidset.api.StatefulDSIterator;
-import com.kamikaze.docidset.bitset.MyOpenBitSet;
-import com.kamikaze.docidset.impl.AndDocIdSet;
-import com.kamikaze.docidset.impl.IntArrayDocIdSet;
-import com.kamikaze.docidset.impl.NotDocIdSet;
-import com.kamikaze.docidset.impl.OBSDocIdSet;
-import com.kamikaze.docidset.impl.OrDocIdSet;
-import com.kamikaze.docidset.impl.P4DDocIdSet;
-
-public class TestDocSetSerialization {
-
- private static int batch = 128;
-
- private static String serial = "src/test/test-data/SerialDocSet";
-
- public TestDocSetSerialization() {
-
- }
-
-
-
-
- @Test
- public void testAndDocSetSerialization() throws Exception{
-
- System.out.println("");
- System.out.println("Running AndDocIdSet Serialization Test case...");
- System.out.println("----------------------------");
- int set1[] = { 8, 27, 30, 35, 53, 59, 71, 74, 87, 92, 104, 113, 122, 126,
- 135, 135, 137, 138, 185, 186, 188, 192, 197, 227, 227, 230, 242, 252,
- 255, 259, 267, 270, 271, 289, 298, 305, 311, 312, 325, 335, 337, 346,
- 351, 360, 365, 371, 375, 380, 387, 391, 406, 407, 408, 419, 425, 430,
- 443, 451, 454, 456, 464, 466, 469, 473, 478, 483, 496, 502, 517, 527,
- 531, 578, 601, 605, 625, 626, 632, 638, 641, 648, 652, 653, 667, 677,
- 682, 697, 700, 711, 713, 733, 764, 780, 782, 796, 798, 801, 804, 812,
- 817, 831, 835, 849, 859, 872, 886, 891, 893, 895, 903, 908, 914, 915,
- 916, 917, 920, 921, 926, 944, 947, 950, 956, 962, 964, 969, 979, 986,
- 994, 996, 1018, 1019, 1022, 1025, 1029, 1029, 1039, 1058, 1062, 1063,
- 1064, 1068, 1069, 1071, 1075, 1082, 1085, 1096, 1098, 1102, 1103, 1104,
- 1104, 1119, 1120, 1122, 1122, 1123, 1147, 1149, 1179, 1183, 1195, 1197,
- 1200, 1201, 1214, 1215, 1220, 1221, 1221, 1225, 1229, 1252, 1260, 1261,
- 1268, 1269, 1274, 1279, 1293, 1336, 1336, 1348, 1369, 1370, 1375, 1394,
- 1401, 1414, 1444, 1453, 1459, 1468, 1473, 1473, 1474, 1485, 1502, 1505,
- 1506, 1517, 1518, 1520, 1521, 1522, 1528, 1537, 1543, 1549, 1550, 1560,
- 1565, 1566, 1585, 1599, 1604, 1619, 1637, 1650, 1658, 1679, 1684, 1691,
- 1691, 1701, 1701, 1715, 1719, 1720, 1722, 1740, 1740, 1748, 1752, 1756,
- 1756, 1776, 1796, 1799, 1799, 1800, 1809, 1811, 1828, 1829, 1849, 1859,
- 1865, 1868, 1886, 1900, 1933, 1955, 1959, 1983, 1985, 1999, 2003, 2003,
- 2029, 2038, 2048, 2050, 2054, 2056, 2059, 2060, 2079, 2095, 2099, 2104,
- 2111, 2113, 2119, 2119, 2122, 2123, 2141, 2142, 2145, 2148, 2160, 2182,
- 2183, 2200, 2203, 2209, 2210, 2221, 2232, 2261, 2267, 2268, 2272, 2283,
- 2297, 2298, 2313, 2314, 2316, 2316, 2331, 2332, 2338, 2343, 2345, 2350,
- 2350, 2365, 2378, 2384, 2392, 2399, 2414, 2420, 2425, 2433, 2445, 2457,
- 2461, 2462, 2463, 2497, 2503, 2519, 2522, 2533, 2556, 2568, 2577, 2578,
- 2578, 2585, 2589, 2603, 2603, 2613, 2616, 2648, 2651, 2662, 2666, 2667,
- 2672, 2675, 2679, 2691, 2694, 2694, 2699, 2706, 2708, 2709, 2711, 2711,
- 2732, 2736, 2738, 2749, 2750, 2763, 2764, 2770, 2775, 2781, 2793, 2811,
- 2817, 2834, 2842, 2847, 2848, 2852, 2856, 2870, 2872, 2876, 2879, 2887,
- 2897, 2903, 2980, 2984, 2994, 2997 };
- int set2[] = { 7, 21, 29, 31, 35, 37, 62, 64, 67, 72, 77, 88, 90, 96, 98,
- 116, 152, 154, 156, 162, 163, 173, 179, 188, 189, 201, 203, 217, 224,
- 233, 263, 267, 271, 277, 294, 301, 311, 336, 343, 349, 390, 395, 396,
- 401, 407, 411, 414, 425, 432, 436, 444, 468, 476, 483, 492, 496, 497,
- 501, 508, 513, 517, 519, 531, 541, 543, 552, 555, 555, 568, 571, 587,
- 589, 594, 601, 604, 606, 625, 633, 634, 645, 649, 654, 655, 662, 664,
- 665, 666, 671, 671, 678, 690, 693, 697, 708, 714, 723, 726, 743, 746,
- 747, 772, 784, 806, 811, 812, 824, 834, 836, 844, 850, 863, 867, 890,
- 890, 896, 905, 931, 933, 934, 940, 952, 959, 963, 968, 974, 978, 997,
- 997, 1013, 1015, 1019, 1023, 1030, 1033, 1035, 1047, 1048, 1054, 1069,
- 1087, 1147, 1156, 1158, 1165, 1175, 1199, 1211, 1224, 1252, 1255, 1256,
- 1259, 1274, 1280, 1283, 1290, 1292, 1292, 1294, 1297, 1299, 1300, 1301,
- 1312, 1323, 1337, 1340, 1351, 1352, 1356, 1363, 1385, 1392, 1395, 1399,
- 1409, 1413, 1429, 1437, 1460, 1461, 1465, 1466, 1468, 1482, 1497, 1500,
- 1501, 1508, 1517, 1524, 1524, 1529, 1530, 1538, 1538, 1544, 1545, 1552,
- 1556, 1561, 1566, 1569, 1583, 1598, 1606, 1610, 1613, 1634, 1642, 1643,
- 1656, 1675, 1682, 1704, 1708, 1711, 1711, 1719, 1724, 1736, 1740, 1741,
- 1766, 1772, 1774, 1777, 1784, 1793, 1814, 1829, 1833, 1843, 1856, 1857,
- 1870, 1874, 1879, 1884, 1886, 1890, 1901, 1909, 1912, 1940, 1944, 1946,
- 1947, 1948, 1955, 1962, 1971, 1982, 1989, 1995, 1997, 2012, 2015, 2021,
- 2043, 2046, 2049, 2055, 2064, 2068, 2069, 2083, 2088, 2100, 2117, 2122,
- 2126, 2132, 2143, 2148, 2152, 2152, 2153, 2159, 2173, 2176, 2198, 2198,
- 2201, 2205, 2206, 2207, 2211, 2222, 2230, 2254, 2256, 2264, 2268, 2317,
- 2318, 2319, 2330, 2334, 2344, 2353, 2353, 2354, 2369, 2374, 2376, 2392,
- 2402, 2403, 2414, 2417, 2422, 2424, 2435, 2445, 2461, 2475, 2530, 2539,
- 2541, 2542, 2565, 2566, 2571, 2572, 2577, 2579, 2581, 2582, 2586, 2592,
- 2595, 2600, 2642, 2645, 2645, 2651, 2668, 2676, 2699, 2705, 2705, 2709,
- 2715, 2720, 2720, 2736, 2753, 2756, 2761, 2788, 2792, 2793, 2796, 2801,
- 2815, 2834, 2842, 2857, 2859, 2859, 2861, 2865, 2869, 2875, 2879, 2884,
- 2885, 2895, 2901, 2906, 2912, 2935, 2940, 2957, 2958, 2967, 2969, 2976,
- 2978, 2981, 2984, 2994, 2997 };
- int set3[] = { 2994, 2997 };
-
- P4DDocIdSet pset1 = new P4DDocIdSet(batch);
- DocSet pset2 = new OBSDocIdSet(3000);
- P4DDocIdSet pset3 = new P4DDocIdSet(batch);
-
- for (int i = 0; i < set1.length; i++) {
- pset1.addDoc(set1[i]);
- pset2.addDoc(set2[i]);
-
- }
- for (int i = 0; i < set3.length; i++) {
- pset3.addDoc(set3[i]);
- }
-
- List<DocIdSet> its = new ArrayList<DocIdSet>();
- its.add(pset1);
- its.add(pset2);
- its.add(pset3);
- AndDocIdSet andSet = new AndDocIdSet(its);
-
- try {
- File f = new File(serial);
- ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
- oos.writeObject(andSet);
- oos.flush();
- oos.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- org.apache.lucene.search.DocIdSetIterator dcit = andSet.iterator();
- int x = set1.length - 2;
- AndDocIdSet andSet2 = null;
-
- try {
- InputStream f = new FileInputStream(new File(serial));
- ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(f));
- andSet2 = (AndDocIdSet) (ois.readObject());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- org.apache.lucene.search.DocIdSetIterator dcit2 = andSet2.iterator();
- x = 0;
- try {
- while (x < 2) {
- int docid1 = dcit.nextDoc();
- int docid2 = dcit2.nextDoc();
- assertEquals(docid1, set3[x++]);
- assertEquals(docid1, docid2);
- }
- } catch (IOException e) {
- fail(e.getMessage());
- }
- }
-
- @Test
- public void testOrDocSetSerialization() throws Exception{
- System.out.println("");
- System.out.println("Running OrDocIdSet Serializaition Test case...");
- System.out.println("----------------------------");
-
- int set0[] = { 9, 20, 31, 42, 65, 76, 87, 108, 119, 130, 141, 152, 163,
- 186, 197, 208, 219, 230, 241, 265, 276, 287, 298, 309, 332, 343, 354,
- 365, 376, 387, 410, 421, 431, 442, 453, 476, 487, 498, 509, 520, 531,
- 554, 565, 575, 586, 597, 608, 619, 630, 653, 664, 675, 686, 697, 708,
- 717, 728, 739, 750, 773, 784, 814, 820, 831, 842, 853 };
- int set1[] = { 8, 19, 30, 53, 64, 75, 86, 96, 107, 118, 129, 140, 151, 174,
- 185, 196, 207, 218, 229, 252, 264, 275, 286, 297, 320, 331, 342, 353,
- 364, 375, 398, 409, 420, 430, 441, 464, 475, 486, 497, 508, 519, 542,
- 553, 564, 574, 585, 596, 607, 618, 641, 652, 663, 674, 685, 696, 716,
- 727, 738, 761, 772, 783, 802, 813, 819, 830, 841 };
- int set2[] = { 7, 41, 52, 63, 74, 85, 106, 117, 128, 139, 162, 173, 184,
- 195, 206, 217, 240, 251, 263, 274, 285, 308, 319, 330, 341, 352, 363,
- 386, 397, 408, 419, 429, 452, 463, 474, 485, 496, 507, 530, 541, 552,
- 563, 573, 584, 595, 606, 629, 640, 651, 662, 673, 684, 707, 715, 726,
- 749, 760, 771, 782, 791, 801, 812, 818, 829, 852, 858 };
- int set3[] = { 6, 29, 40, 51, 62, 73, 84, 105, 116, 127, 150, 161, 172,
- 183, 194, 205, 228, 239, 250, 262, 273, 296, 307, 318, 329, 340, 351,
- 374, 385, 396, 407, 418, 440, 451, 462, 473, 484, 495, 518, 529, 540,
- 551, 562, 572, 583, 594, 617, 628, 639, 650, 661, 672, 695, 706, 714,
- 737, 748, 759, 770, 781, 790, 793, 800, 811, 840, 851 };
- int set4[] = { 17, 28, 39, 50, 61, 72, 95, 104, 115, 138, 149, 160, 171,
- 182, 193, 216, 227, 238, 249, 260, 261, 284, 295, 306, 317, 328, 339,
- 362, 373, 384, 395, 406, 417, 439, 450, 461, 472, 483, 506, 517, 528,
- 539, 550, 561, 582, 605, 616, 627, 638, 649, 660, 683, 694, 705, 725,
- 736, 747, 758, 769, 780, 789, 799, 810, 828, 839, 850 };
- int set5[] = { 5, 16, 27, 38, 49, 60, 83, 94, 103, 126, 137, 148, 159, 170,
- 181, 204, 215, 226, 237, 248, 259, 272, 283, 294, 305, 316, 327, 350,
- 361, 372, 383, 394, 405, 428, 438, 449, 460, 471, 494, 505, 516, 527,
- 538, 549, 593, 604, 615, 626, 637, 648, 671, 682, 693, 704, 724, 735,
- 746, 757, 768, 788, 792, 798, 809, 827, 838, 849 };
- int set6[] = { 4, 15, 26, 37, 48, 71, 82, 93, 114, 125, 136, 147, 158, 169,
- 192, 203, 214, 225, 236, 247, 271, 282, 293, 304, 315, 338, 349, 360,
- 371, 382, 393, 416, 427, 437, 448, 459, 482, 493, 504, 515, 526, 537,
- 560, 571, 581, 592, 603, 614, 625, 636, 659, 670, 681, 692, 703, 723,
- 734, 745, 756, 779, 787, 796, 797, 826, 837, 848 };
- int set7[] = { 3, 14, 25, 36, 59, 70, 81, 92, 102, 113, 124, 135, 146, 157,
- 180, 191, 202, 213, 224, 235, 258, 270, 281, 292, 303, 326, 337, 348,
- 359, 370, 381, 404, 415, 426, 436, 447, 470, 481, 492, 503, 514, 525,
- 548, 559, 570, 580, 591, 602, 613, 624, 647, 658, 669, 680, 691, 702,
- 722, 733, 744, 767, 778, 795, 808, 825, 836, 847 };
- int set8[] = { 2, 13, 24, 47, 58, 69, 80, 91, 101, 112, 123, 134, 145, 168,
- 179, 190, 201, 212, 223, 246, 257, 269, 280, 291, 314, 325, 336, 347,
- 358, 369, 392, 403, 414, 425, 435, 458, 469, 480, 491, 502, 513, 536,
- 547, 558, 569, 579, 590, 601, 612, 635, 646, 657, 668, 679, 690, 713,
- 721, 732, 755, 766, 777, 786, 794, 807, 824, 835 };
- int set9[] = { 1, 10, 12, 21, 32, 35, 43, 46, 54, 57, 68, 77, 79, 88, 90,
- 97, 100, 111, 120, 122, 131, 133, 142, 153, 156, 164, 167, 175, 178,
- 189, 198, 200, 209, 211, 220, 231, 234, 242, 245, 253, 256, 266, 268,
- 277, 279, 288, 299, 302, 310, 313, 321, 324, 335, 344, 346, 355, 357,
- 366, 377, 380, 388, 391, 399, 402, 413, 422, 424, 432, 443, 446, 454,
- 457, 465, 468, 479, 488, 490, 499, 501, 510, 521, 524, 532, 535, 543,
- 546, 557, 566, 568, 578, 587, 589, 598, 600, 609, 620, 623, 631, 634,
- 642, 645, 656, 665, 667, 676, 678, 687, 698, 701, 709, 712, 718, 720,
- 729, 740, 743, 751, 754, 762, 765, 776, 785, 803, 806, 817, 821, 823,
- 832, 843, 846, 854 };
- int set10[] = { 23, 34, 45, 56, 67, 78, 99, 110, 121, 144, 155, 166, 177,
- 188, 199, 222, 233, 244, 255, 267, 290, 301, 312, 323, 334, 345, 368,
- 379, 390, 401, 412, 423, 434, 445, 456, 467, 478, 489, 512, 523, 534,
- 545, 556, 567, 577, 588, 611, 622, 633, 644, 655, 666, 689, 700, 711,
- 731, 742, 753, 764, 775, 805, 816, 834, 845, 856, 857 };
- int set11[] = { 11, 22, 33, 44, 55, 66, 89, 98, 109, 132, 143, 154, 165,
- 176, 187, 210, 221, 232, 243, 254, 278, 289, 300, 311, 322, 333, 356,
- 367, 378, 389, 400, 411, 433, 444, 455, 466, 477, 500, 511, 522, 533,
- 544, 555, 576, 599, 610, 621, 632, 643, 654, 677, 688, 699, 710, 719,
- 730, 741, 752, 763, 774, 804, 815, 822, 833, 844, 855 };
-
- int set12[] = { 857, 858 };
-
- int result[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
- 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
- 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
- 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
- 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
- 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
- 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
- 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
- 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
- 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162,
- 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176,
- 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,
- 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
- 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
- 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
- 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
- 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260,
- 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
- 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
- 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302,
- 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
- 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330,
- 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
- 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358,
- 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372,
- 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386,
- 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400,
- 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,
- 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428,
- 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442,
- 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456,
- 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470,
- 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484,
- 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498,
- 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512,
- 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526,
- 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540,
- 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554,
- 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568,
- 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582,
- 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596,
- 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610,
- 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624,
- 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638,
- 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652,
- 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666,
- 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680,
- 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694,
- 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708,
- 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722,
- 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736,
- 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750,
- 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764,
- 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778,
- 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792,
- 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806,
- 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820,
- 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834,
- 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848,
- 849, 850, 851, 852, 853, 854, 855, 856, 857, 858 };
- OpenBitSet ps0 = new MyOpenBitSet();
- for (int i = 0; i < set0.length; i++)
- ps0.set(set0[i]);
-
- MyOpenBitSet ps1 = new MyOpenBitSet();
- for (int i = 0; i < set1.length; i++)
- ps1.set(set1[i]);
-
- MyOpenBitSet ps2 = new MyOpenBitSet();
- for (int i = 0; i < set2.length; i++)
- ps2.set(set2[i]);
-
- MyOpenBitSet ps3 = new MyOpenBitSet();
- for (int i = 0; i < set3.length; i++)
- ps3.set(set3[i]);
-
- MyOpenBitSet ps4 = new MyOpenBitSet();
- for (int i = 0; i < set4.length; i++)
- ps4.set(set4[i]);
-
- MyOpenBitSet ps5 = new MyOpenBitSet();
- for (int i = 0; i < set5.length; i++)
- ps5.set(set5[i]);
-
- MyOpenBitSet ps6 = new MyOpenBitSet();
- for (int i = 0; i < set6.length; i++)
- ps6.set(set6[i]);
-
- MyOpenBitSet ps7 = new MyOpenBitSet();
- for (int i = 0; i < set7.length; i++)
- ps7.set(set7[i]);
-
- MyOpenBitSet ps8 = new MyOpenBitSet();
- for (int i = 0; i < set8.length; i++)
- ps8.set(set8[i]);
-
- MyOpenBitSet ps9 = new MyOpenBitSet();
- for (int i = 0; i < set9.length; i++)
- ps9.set(set9[i]);
-
- MyOpenBitSet ps10 = new MyOpenBitSet();
- for (int i = 0; i < set10.length; i++)
- ps10.set(set10[i]);
-
- MyOpenBitSet ps11 = new MyOpenBitSet();
- for (int i = 0; i < set11.length; i++)
- ps11.set(set11[i]);
-
- ArrayList<DocIdSet> sets = new ArrayList<DocIdSet>();
- sets.add(ps0);
- sets.add(ps1);
- sets.add(ps2);
- sets.add(ps3);
- sets.add(ps4);
- sets.add(ps5);
- sets.add(ps6);
- sets.add(ps7);
- sets.add(ps8);
- sets.add(ps9);
- sets.add(ps10);
- sets.add(ps11);
-
- OrDocIdSet ord = new OrDocIdSet(sets);
- org.apache.lucene.search.DocIdSetIterator dcit = ord.iterator();
-
- try {
- File f = new File(serial);
- ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
- oos.writeObject(ord);
- oos.flush();
- oos.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- OrDocIdSet ord2 = null;
-
- try {
- InputStream f = new FileInputStream(new File(serial));
- ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(f));
- ord2 = (OrDocIdSet) (ois.readObject());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- int x = 0;
- org.apache.lucene.search.DocIdSetIterator dcit2 = ord2.iterator();
- try {
- while (x < result.length) {
- int docid1 = dcit.nextDoc();
- int docid2 = dcit2.nextDoc();
- assertEquals(docid1, result[x++]);
- assertEquals(docid1,docid2);
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void testNotDocSetSerialization() throws Exception {
-
- System.out.println("");
- System.out.println("Running NotDocIdSet Serialization Test case...");
- System.out.println("----------------------------");
-
- Random random = new Random();
-
- int randomizer = 0;
- int b = 0;
- int length = 1000;
- int max = 5400;
-
- ArrayList<Integer> intSet = new ArrayList<Integer>();
- P4DDocIdSet docSet = new P4DDocIdSet(batch);
- randomizer = 0;
-
- for (int i = 1; i < 1000 + 1; i++) {
-
- int bVal[] = new int[33];
- for (int k = 0; k < batch; k++) {
- b = randomizer + (int) (random.nextDouble() * 1000);
- intSet.add(b);
-
- }
-
- randomizer += 1000;
- Collections.sort(intSet);
-
- }
- for (Integer c : intSet) {
- docSet.addDoc(c);
- }
-
- DocIdSet not = new NotDocIdSet(docSet, max);
-
- try {
- File f = new File(serial);
- ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
- oos.writeObject(not);
- oos.flush();
- oos.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- NotDocIdSet not2 = null;
-
- try {
- InputStream f = new FileInputStream(new File(serial));
- ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(f));
- not2 = (NotDocIdSet) (ois.readObject());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- org.apache.lucene.search.DocIdSetIterator noit = not.iterator();
- org.apache.lucene.search.DocIdSetIterator noit2 = not2.iterator();
-
- try {
- int docid;
- while ((docid=noit.nextDoc())!=DocIdSetIterator.NO_MORE_DOCS) {
- int docid2 = noit2.nextDoc();
- assertFalse(intSet.contains(docid));
- assertEquals(docid, docid2);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- }
-
- @Test
- public void testP4DDocSetSerialization() throws Exception{
- System.out.println("");
- System.out.println("Running P4DDocIdSet Serialization Test case...");
- System.out.println("----------------------------");
-
- int result[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
- 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
- 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
- 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
- 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
- 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
- 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
- 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
- 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
- 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162,
- 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176,
- 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,
- 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
- 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
- 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
- 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
- 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260,
- 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
- 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
- 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302,
- 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
- 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330,
- 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
- 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358,
- 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372,
- 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386,
- 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400,
- 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,
- 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428,
- 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442,
- 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456,
- 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470,
- 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484,
- 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498,
- 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512,
- 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526,
- 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540,
- 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554,
- 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568,
- 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582,
- 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596,
- 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610,
- 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624,
- 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638,
- 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652,
- 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666,
- 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680,
- 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694,
- 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708,
- 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722,
- 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736,
- 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750,
- 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764,
- 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778,
- 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792,
- 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806,
- 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820,
- 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834,
- 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848,
- 849, 850, 851, 852, 853, 854, 855, 856, 857, 858 };
- P4DDocIdSet docSet = new P4DDocIdSet(batch);
-
- for (int i = 0; i < result.length; i++) {
- docSet.addDoc(result[i]);
- }
-
- try {
- File f = new File(serial);
- ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
- oos.writeObject(docSet);
- oos.flush();
- oos.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- DocIdSet docSet2 = null;
-
- try {
- InputStream f = new FileInputStream(new File(serial));
- ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(f));
- docSet2 = (DocIdSet) (ois.readObject());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- StatefulDSIterator dcit1 = docSet.iterator();
- org.apache.lucene.search.DocIdSetIterator dcit2 = docSet2.iterator();
-
- try {
- for (int i = 0; i < result.length; i++) {
- int docid1 = dcit1.nextDoc();
- int docid2 = dcit2.nextDoc();
- assertEquals(docid1, result[i]);
- assertEquals(docid1, docid2);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- }
-
- @Test
- public void testIntArrayDocSetSerialization() throws Exception{
-
- System.out.println("");
- System.out.println("Running IntArrayDocIdSet Serialization Test case...");
- System.out.println("----------------------------");
-
- int result[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
- 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
- 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
- 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
- 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
- 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
- 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
- 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
- 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
- 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162,
- 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176,
- 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,
- 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
- 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
- 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
- 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
- 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260,
- 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
- 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
- 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302,
- 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
- 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330,
- 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
- 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358,
- 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372,
- 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386,
- 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400,
- 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,
- 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428,
- 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442,
- 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456,
- 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470,
- 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484,
- 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498,
- 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512,
- 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526,
- 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540,
- 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554,
- 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568,
- 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582,
- 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596,
- 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610,
- 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624,
- 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638,
- 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652,
- 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666,
- 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680,
- 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694,
- 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708,
- 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722,
- 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736,
- 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750,
- 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764,
- 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778,
- 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792,
- 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806,
- 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820,
- 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834,
- 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848,
- 849, 850, 851, 852, 853, 854, 855, 856, 857, 858 };
- IntArrayDocIdSet docSet = new IntArrayDocIdSet(batch);
-
- for (int i = 0; i < result.length; i++) {
- docSet.addDoc(result[i]);
- }
-
- try {
- File f = new File(serial);
- ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
- oos.writeObject(docSet);
- oos.flush();
- oos.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- DocIdSet docSet2 = null;
-
- try {
- InputStream f = new FileInputStream(new File(serial));
- ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(f));
- docSet2 = (DocIdSet) (ois.readObject());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- StatefulDSIterator dcit1 = docSet.iterator();
- org.apache.lucene.search.DocIdSetIterator dcit2 = docSet2.iterator();
-
- try {
- for (int i = 0; i < result.length; i++) {
- int docid1 = dcit1.nextDoc();
- int docid2 = dcit2.nextDoc();
- assertEquals(docid1, result[i]);
- assertEquals(docid1, docid2);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void testOBSDocSetSerialization() throws Exception{
-
- System.out.println("");
- System.out.println("Running OBSDocIdSet Serialization Test case...");
- System.out.println("----------------------------");
-
- int result[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
- 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
- 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
- 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
- 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
- 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
- 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
- 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
- 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
- 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162,
- 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176,
- 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,
- 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
- 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
- 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
- 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
- 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260,
- 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
- 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
- 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302,
- 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
- 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330,
- 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
- 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358,
- 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372,
- 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386,
- 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400,
- 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,
- 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428,
- 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442,
- 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456,
- 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470,
- 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484,
- 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498,
- 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512,
- 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526,
- 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540,
- 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554,
- 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568,
- 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582,
- 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596,
- 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610,
- 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624,
- 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638,
- 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652,
- 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666,
- 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680,
- 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694,
- 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708,
- 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722,
- 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736,
- 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750,
- 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764,
- 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778,
- 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792,
- 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806,
- 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820,
- 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834,
- 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848,
- 849, 850, 851, 852, 853, 854, 855, 856, 857, 858 };
- OBSDocIdSet docSet = new OBSDocIdSet(858);
-
- for (int i = 0; i < result.length; i++) {
- docSet.addDoc(result[i]);
- }
-
- try {
- File f = new File(serial);
- ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
- oos.writeObject(docSet);
- oos.flush();
- oos.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- DocIdSet docSet2 = null;
-
- try {
- InputStream f = new FileInputStream(new File(serial));
- ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(f));
- docSet2 = (DocIdSet) (ois.readObject());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- StatefulDSIterator dcit1 = docSet.iterator();
- org.apache.lucene.search.DocIdSetIterator dcit2 = docSet2.iterator();
-
- try {
- for (int i = 0; i < result.length; i++) {
- int docid1 = dcit1.nextDoc();
- int docid2 = dcit2.nextDoc();
- assertEquals(docid1, result[i]);
- assertEquals(docid1, docid2);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- }
-
-}
104 src/test/java/com/kamikaze/test/TestMultiThreadedAccess.java
View
@@ -1,104 +0,0 @@
-package com.kamikaze.test;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Random;
-
-import junit.framework.TestCase;
-
-import org.apache.lucene.search.DocIdSetIterator;
-import org.junit.Test;
-
-import com.kamikaze.docidset.api.StatefulDSIterator;
-import com.kamikaze.docidset.impl.P4DDocIdSet;
-
-
-
-public class TestMultiThreadedAccess extends TestCase{
-
-
- static int _length = 1000;
- static int _max = 300000;
-
- private static class TestThread extends Thread{
- P4DDocIdSet p4d;
- TestThread(P4DDocIdSet p4d){
- this.p4d = p4d;
- }
- public void run()
- {
- StatefulDSIterator dcit = p4d.iterator();
-
- try {
- int docid;
- while((docid = dcit.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
- {
- assertEquals(true, p4d.find(docid));
-
- assertEquals(false,p4d.find(35));
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- @Test
- public void testMultiThreadedFind() throws IOException, InterruptedException
- {
- System.out.println("");
- System.out.println("Running Doc Find Multithreaded");
- System.out.println("----------------------------");
-
- double booster = ((_max*1.0)/(1000f*_length));
- P4DDocIdSet set = new P4DDocIdSet();
- Random random = new Random();
-
- int max = 1000;
-
- int randomizer = 0;
- double totalDecompressionTime = 0;
- List<Integer> list = new LinkedList<Integer>();
- LinkedList<Integer> list2 = new LinkedList<Integer>();
- int prev = 0;
- for (int i = 55; i < _length*256; i++) {
- prev +=i;
- list.add(prev);
- }
-
- Collections.sort(list);
- //System.out.println("Largest Element in the List:"+list.get( list.size() -1 ));
-
- final int maxVal = list.get(list.size()-1);
-
- //P4D
- final P4DDocIdSet p4d = new P4DDocIdSet();
- int counter=0;
-
- for (Integer c : list) {
- counter++;
- //System.out.println(c);
- p4d.addDoc(c);
- }
- System.out.println("Set Size:"+ p4d.size());
-
- Thread arr [] = new Thread[5];
- for(int i=0;i<arr.length;i++)
- {
- Thread t = new TestThread(p4d);
- arr[i] = t;
- t.start();
- }
- for(int i=0;i<arr.length;i++)
- {
- arr[i].join();
- }
-
- }
-
-}
Please sign in to comment.
Something went wrong with that request. Please try again.