Skip to content

Commit

Permalink
remove PForDeltaWithBase and remove unnecessary memory allocation in …
Browse files Browse the repository at this point in the history
…readobject of PForDeltaDocIdSet
  • Loading branch information
hao yan committed Jul 18, 2012
1 parent 6007b82 commit 4a04719
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 94 deletions.

This file was deleted.

34 changes: 16 additions & 18 deletions src/main/java/com/kamikaze/docidset/impl/PForDeltaDocIdSet.java
@@ -1,6 +1,5 @@
package com.kamikaze.docidset.impl;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
Expand All @@ -13,11 +12,11 @@

import com.kamikaze.docidset.api.DocSet;
import com.kamikaze.docidset.api.StatefulDSIterator;
import com.kamikaze.docidset.compression.PForDeltaWithBase;
import com.kamikaze.docidset.utils.CompResult;
import com.kamikaze.docidset.utils.Conversion;
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)
Expand All @@ -43,7 +42,6 @@ public class PForDeltaDocIdSet extends DocSet implements Serializable {
private int totalDocIdNum=0; // the total number of elemnts that have been inserted/accessed so far
private long compressedBitSize=0; // compressed size in bits

transient private PForDeltaWithBase compBlockWithBase = new PForDeltaWithBase(); // the PForDelta algorithm to compress a block
transient private IntArray baseListForOnlyCompBlocks; // the base lists for skipping
transient private int[] currentNoCompBlock; // the memory used to store the uncompressed elements. Once the block is full, all its elements are compressed into sequencOfCompBlock and the block is cleared.
transient private int sizeOfCurrentNoCompBlock = 0; // the number of uncompressed elements that is hold in the currentNoCompBlock
Expand Down Expand Up @@ -232,19 +230,15 @@ private void readObject(ObjectInputStream inStrm) throws IOException, ClassNotFo
{
inStrm.defaultReadObject();

compBlockWithBase = new PForDeltaWithBase();

int[] baseArray = (int[])inStrm.readObject();
baseListForOnlyCompBlocks = new IntArray();
for(int i=0; i<baseArray.length; ++i)
{
baseListForOnlyCompBlocks.add(baseArray[i]);
}

int[] noCompBlock = (int[])inStrm.readObject();
sizeOfCurrentNoCompBlock = noCompBlock.length;
currentNoCompBlock = new int[sizeOfCurrentNoCompBlock];
System.arraycopy(noCompBlock, 0, currentNoCompBlock, 0, sizeOfCurrentNoCompBlock);
currentNoCompBlock = (int[])inStrm.readObject();
sizeOfCurrentNoCompBlock = currentNoCompBlock.length;
}


Expand Down Expand Up @@ -302,7 +296,9 @@ public boolean find(int target)
return false;

// compBlockWithBase.decompressOneBlock(curDecompBlock, sequenceOfCompBlocks.get(iterDecompBlock), _blockSize);
compBlockWithBase.decompressOneBlock(myDecompBlock, sequenceOfCompBlocks.get(iterDecompBlock), _blockSize);
//compBlockWithBase.decompressOneBlock(myDecompBlock, sequenceOfCompBlocks.get(iterDecompBlock), _blockSize);
PForDelta.decompressOneBlock(myDecompBlock, sequenceOfCompBlocks.get(iterDecompBlock), _blockSize);

int idx ;
lastId = myDecompBlock[0];
if (lastId == target) return true;
Expand Down Expand Up @@ -560,8 +556,11 @@ public void flush(int docId)
*/
private CompResult PForDeltaCompressOneBlock(int[] srcData)
{
CompResult compRes = compBlockWithBase.compressOneBlock(srcData, _blockSize);
return compRes;
int[] compBlock = PForDelta.compressOneBlockOpt(srcData, _blockSize);
CompResult res = new CompResult();
res.setCompressedSize(compBlock.length<<5);
res.setCompressedBlock(compBlock);
return res;
}

/**
Expand All @@ -570,7 +569,7 @@ private CompResult PForDeltaCompressOneBlock(int[] srcData)
*/
private int PForDeltaEstimateCompSize(int[] srcData, int b)
{
return compBlockWithBase.estimateCompSize(srcData, b, _blockSize);
return PForDelta.estimateCompressedSize(srcData, b, _blockSize);
}

private void initSet() {
Expand Down Expand Up @@ -765,7 +764,6 @@ class PForDeltaDocIdIterator extends StatefulDSIterator implements Serializable

int compBlockNum=0; // the number of compressed blocks
transient int[] iterDecompBlock = new int[_blockSize]; // temporary storage for the decompressed data
PForDeltaWithBase iterPForDeltaSetWithBase = new PForDeltaWithBase(); // PForDelta algorithm

PForDeltaDocIdIterator() {
super();
Expand Down Expand Up @@ -806,7 +804,7 @@ public int nextDoc()
// must be in one of the compressed blocks
else if(offset == 0) // case 2: the comp block has been decompressed;
{
iterPForDeltaSetWithBase.decompressOneBlock(iterDecompBlock, sequenceOfCompBlocks.get(iterBlockIndex), _blockSize);
PForDelta.decompressOneBlock(iterDecompBlock, sequenceOfCompBlocks.get(iterBlockIndex), _blockSize);
lastAccessedDocId = iterDecompBlock[offset];
}
else // case 3: in the recently decompressed block
Expand Down Expand Up @@ -945,7 +943,7 @@ private int advanceToTargetInTheFollowingCompBlocks(int target, int startBlockIn
System.err.println("ERROR: advanceToTargetInTheFollowingCompBlocks(): Impossible, we must be able to find the block");
}

iterPForDeltaSetWithBase.decompressOneBlock(iterDecompBlock, sequenceOfCompBlocks.get(iterBlockIndex), _blockSize);
PForDelta.decompressOneBlock(iterDecompBlock, sequenceOfCompBlocks.get(iterBlockIndex), _blockSize);
postProcessBlock(iterDecompBlock, _blockSize);

int offset = binarySearchForFirstElementEqualOrLargerThanTarget(iterDecompBlock, 0, _blockSize-1, target);
Expand Down Expand Up @@ -973,7 +971,7 @@ private int advanceToTargetInTheFollowingCompBlocksNoPostProcessing(int target,
System.err.println("ERROR: advanceToTargetInTheFollowingCompBlocks(): Impossible, we must be able to find the block");
}

iterPForDeltaSetWithBase.decompressOneBlock(iterDecompBlock, sequenceOfCompBlocks.get(iterBlockIndex), _blockSize);
PForDelta.decompressOneBlock(iterDecompBlock, sequenceOfCompBlocks.get(iterBlockIndex), _blockSize);
lastAccessedDocId = iterDecompBlock[0];
if (lastAccessedDocId >= target)
{
Expand Down Expand Up @@ -1011,7 +1009,7 @@ private void printSet()
{
for (int i = 0; i < _blockSize; i++)
{
iterPForDeltaSetWithBase.decompressOneBlock(iterDecompBlock, sequenceOfCompBlocks.get(i), _blockSize);
PForDelta.decompressOneBlock(iterDecompBlock, sequenceOfCompBlocks.get(i), _blockSize);
postProcessBlock(iterDecompBlock, _blockSize);
System.out.print(iterDecompBlock + ",");
}
Expand Down

0 comments on commit 4a04719

Please sign in to comment.