-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from ate47/dev_diffcat
Add diffBit into k-HDTCat
- Loading branch information
Showing
29 changed files
with
1,428 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
hdt-java-core/src/main/java/org/rdfhdt/hdt/compact/bitmap/EmptyBitmap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package org.rdfhdt.hdt.compact.bitmap; | ||
|
||
import org.rdfhdt.hdt.compact.integer.VByte; | ||
import org.rdfhdt.hdt.exceptions.NotImplementedException; | ||
import org.rdfhdt.hdt.hdt.HDTVocabulary; | ||
import org.rdfhdt.hdt.listener.ProgressListener; | ||
import org.rdfhdt.hdt.util.crc.CRC32; | ||
import org.rdfhdt.hdt.util.crc.CRC8; | ||
import org.rdfhdt.hdt.util.crc.CRCOutputStream; | ||
import org.rdfhdt.hdt.util.io.IOUtil; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* empty bitmap, act like a bitmap filled with 0, but isn't allocated on disk or in memory, | ||
* will throw a {@link org.rdfhdt.hdt.exceptions.NotImplementedException} if we try to add | ||
* a non 0 value | ||
*/ | ||
public class EmptyBitmap implements ModifiableBitmap { | ||
/** | ||
* create empty bitmap simulating a bitmap of a particular size | ||
* | ||
* @param size the size | ||
* @return bitmap | ||
*/ | ||
public static ModifiableBitmap of(long size) { | ||
return new EmptyBitmap(size); | ||
} | ||
|
||
private long size; | ||
|
||
private EmptyBitmap(long size) { | ||
this.size = size; | ||
} | ||
|
||
@Override | ||
public void append(boolean value) { | ||
set(size, value); | ||
} | ||
|
||
@Override | ||
public void set(long pos, boolean value) { | ||
if (value) { | ||
throw new NotImplementedException("true value in EmptyBitmap"); | ||
} | ||
|
||
size = Math.max(size, pos); | ||
} | ||
|
||
@Override | ||
public boolean access(long pos) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public long rank1(long pos) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long rank0(long pos) { | ||
return pos; | ||
} | ||
|
||
@Override | ||
public long selectPrev1(long start) { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public long selectNext1(long start) { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public long select0(long n) { | ||
return n; | ||
} | ||
|
||
@Override | ||
public long select1(long n) { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public long getNumBits() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public long countOnes() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long countZeros() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public long getSizeBytes() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void save(OutputStream output, ProgressListener listener) throws IOException { | ||
CRCOutputStream out = new CRCOutputStream(output, new CRC8()); | ||
|
||
// Write Type and Numbits | ||
out.write(BitmapFactory.TYPE_BITMAP_PLAIN); | ||
VByte.encode(out, 8L); | ||
|
||
// Write CRC | ||
out.writeCRC(); | ||
|
||
// Setup new CRC | ||
out.setCRC(new CRC32()); | ||
IOUtil.writeLong(out, 0); | ||
|
||
out.writeCRC(); | ||
} | ||
|
||
@Override | ||
public void load(InputStream input, ProgressListener listener) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return HDTVocabulary.BITMAP_TYPE_PLAIN; | ||
} | ||
} |
139 changes: 139 additions & 0 deletions
139
hdt-java-core/src/main/java/org/rdfhdt/hdt/compact/bitmap/NegBitmap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package org.rdfhdt.hdt.compact.bitmap; | ||
|
||
import org.rdfhdt.hdt.exceptions.NotImplementedException; | ||
import org.rdfhdt.hdt.listener.ProgressListener; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* create a negation bitmap of another one, the close method is called if the bitmap implements closeable | ||
* | ||
* access/set are negate when called | ||
* | ||
* @param <T> bitmap type | ||
*/ | ||
public class NegBitmap<T extends Bitmap> implements Bitmap, Closeable { | ||
|
||
/** | ||
* create from a bitmap | ||
* | ||
* @param bitmap bitmap | ||
* @return bitmap | ||
*/ | ||
public static Bitmap of(Bitmap bitmap) { | ||
return new NegBitmap<>(bitmap); | ||
} | ||
|
||
/** | ||
* create from a modifiableBitmap | ||
* | ||
* @param modifiableBitmap modifiableBitmap | ||
* @return modifiableBitmap | ||
*/ | ||
public static ModifiableBitmap of(ModifiableBitmap modifiableBitmap) { | ||
return new NegModifiableBitmap(modifiableBitmap); | ||
} | ||
|
||
private static class NegModifiableBitmap extends NegBitmap<ModifiableBitmap> implements ModifiableBitmap { | ||
|
||
private NegModifiableBitmap(ModifiableBitmap handle) { | ||
super(handle); | ||
} | ||
|
||
@Override | ||
public void set(long position, boolean value) { | ||
handle.set(position, !value); | ||
} | ||
|
||
@Override | ||
public void append(boolean value) { | ||
handle.append(!value); | ||
} | ||
} | ||
|
||
protected final T handle; | ||
|
||
private NegBitmap(T handle) { | ||
this.handle = handle; | ||
} | ||
|
||
@Override | ||
public boolean access(long position) { | ||
return !handle.access(position); | ||
} | ||
|
||
@Override | ||
public long rank1(long position) { | ||
return handle.rank0(position); | ||
} | ||
|
||
@Override | ||
public long rank0(long position) { | ||
return handle.rank1(position); | ||
} | ||
|
||
@Override | ||
public long selectPrev1(long start) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
@Override | ||
public long selectNext1(long start) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
@Override | ||
public long select0(long n) { | ||
return handle.select1(n); | ||
} | ||
|
||
@Override | ||
public long select1(long n) { | ||
return handle.select0(n); | ||
} | ||
|
||
@Override | ||
public long getNumBits() { | ||
return handle.getNumBits(); | ||
} | ||
|
||
@Override | ||
public long countOnes() { | ||
return handle.countZeros(); | ||
} | ||
|
||
@Override | ||
public long countZeros() { | ||
return handle.countOnes(); | ||
} | ||
|
||
@Override | ||
public long getSizeBytes() { | ||
return handle.getSizeBytes(); | ||
} | ||
|
||
@Override | ||
public void save(OutputStream output, ProgressListener listener) throws IOException { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
@Override | ||
public void load(InputStream input, ProgressListener listener) throws IOException { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return handle.getType(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
if (handle instanceof Closeable) { | ||
((Closeable) handle).close(); | ||
} | ||
} | ||
} |
Oops, something went wrong.