-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDTq MSDL, DiffCat, GenDisk implementation and add tests
- Loading branch information
Showing
81 changed files
with
3,610 additions
and
1,751 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
124 changes: 124 additions & 0 deletions
124
...ore/src/main/java/com/the_qa_company/qendpoint/core/compact/bitmap/GraphDeleteBitmap.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,124 @@ | ||
package com.the_qa_company.qendpoint.core.compact.bitmap; | ||
|
||
import com.the_qa_company.qendpoint.core.exceptions.NotImplementedException; | ||
import com.the_qa_company.qendpoint.core.util.io.Closer; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Bitmap to delete inside a graph, all the ids are mapped on a bitmap with the | ||
* formula | ||
* | ||
* <pre> | ||
* (id, graph) -> id * graphs + graph | ||
* </pre> | ||
* | ||
* @author Antoine Willerval | ||
*/ | ||
public class GraphDeleteBitmap implements SimpleModifiableBitmap, Closeable { | ||
/** | ||
* create empty graph delete bitmap | ||
* | ||
* @param graphs graphs count | ||
* @param size triples count | ||
* @return gdb | ||
*/ | ||
public static GraphDeleteBitmap empty(long graphs, long size) { | ||
return new GraphDeleteBitmap(EmptyBitmap.of(size * graphs), graphs); | ||
} | ||
|
||
/** | ||
* create memory graph delete bitmap | ||
* | ||
* @param graphs graphs count | ||
* @param size triples count | ||
* @return gdb | ||
*/ | ||
public static GraphDeleteBitmap memory(long graphs, long size) { | ||
return new GraphDeleteBitmap(MultiRoaringBitmap.memory(size * graphs), graphs); | ||
} | ||
|
||
/** | ||
* wrap a bitmap to create a {@link GraphDeleteBitmap} | ||
* | ||
* @param bitmap bitmap | ||
* @param graphs graphs count | ||
* @return bitmap if already instanceof graph delete bitmap and contains the | ||
* right graphs number or wrap into GraphDeleteBitmap | ||
*/ | ||
public static GraphDeleteBitmap wrap(Bitmap bitmap, long graphs) { | ||
if (bitmap instanceof GraphDeleteBitmap gdb && gdb.graphs == graphs) { | ||
// use directly the bitmap | ||
return gdb; | ||
} | ||
return new GraphDeleteBitmap(bitmap, graphs); | ||
} | ||
|
||
private final Bitmap store; | ||
private final long graphs; | ||
|
||
private GraphDeleteBitmap(Bitmap store, long graphs) { | ||
this.store = store; | ||
this.graphs = graphs; | ||
} | ||
|
||
/** | ||
* access a bit in a graph | ||
* | ||
* @param graph graph | ||
* @param position position | ||
* @return bit value | ||
*/ | ||
public boolean access(long graph, long position) { | ||
return access(position * graphs + graph); | ||
} | ||
|
||
/** | ||
* set a bit in a graph | ||
* | ||
* @param graph graph | ||
* @param position position | ||
* @param value value | ||
* @throws ClassCastException if the wrapped bitmap isn't a modifiable | ||
* bitmap | ||
*/ | ||
public void set(int graph, long position, boolean value) { | ||
set(position * graphs + graph, value); | ||
} | ||
|
||
@Override | ||
public boolean access(long position) { | ||
return store.access(position); | ||
} | ||
|
||
@Override | ||
public void set(long position, boolean value) { | ||
((ModifiableBitmap) store).set(position, value); | ||
} | ||
|
||
@Override | ||
public long getNumBits() { | ||
return store.getNumBits(); | ||
} | ||
|
||
@Override | ||
public long getSizeBytes() { | ||
return store.getSizeBytes(); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return store.getType(); | ||
} | ||
|
||
@Override | ||
public void append(boolean value) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
Closer.closeSingle(store); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...e/src/main/java/com/the_qa_company/qendpoint/core/compact/bitmap/MappedRoaringBitmap.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,101 @@ | ||
package com.the_qa_company.qendpoint.core.compact.bitmap; | ||
|
||
import com.the_qa_company.qendpoint.core.hdt.HDTVocabulary; | ||
import com.the_qa_company.qendpoint.core.listener.ProgressListener; | ||
import com.the_qa_company.qendpoint.core.util.io.CloseMappedByteBuffer; | ||
import com.the_qa_company.qendpoint.core.util.io.IOUtil; | ||
import org.roaringbitmap.buffer.ImmutableRoaringBitmap; | ||
|
||
import java.io.Closeable; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* Mapped {@link Bitmap} wrapper for the {@link ImmutableRoaringBitmap}, not | ||
* compatible with {@link RoaringBitmap64} | ||
* | ||
* @author Antoine Willerval | ||
*/ | ||
public class MappedRoaringBitmap implements SimpleBitmap, Closeable { | ||
private final CloseMappedByteBuffer buffer; | ||
private final ImmutableRoaringBitmap rbm; | ||
|
||
public MappedRoaringBitmap(CloseMappedByteBuffer buffer) { | ||
this.buffer = buffer; | ||
this.rbm = new ImmutableRoaringBitmap(buffer.getInternalBuffer()); | ||
} | ||
|
||
public ImmutableRoaringBitmap getHandle() { | ||
return rbm; | ||
} | ||
|
||
@Override | ||
public boolean access(long position) { | ||
return rbm.contains((int) position); | ||
} | ||
|
||
@Override | ||
public long getNumBits() { | ||
return rbm.last(); | ||
} | ||
|
||
@Override | ||
public long getSizeBytes() { | ||
return rbm.serializedSizeInBytes() + 8; | ||
} | ||
|
||
@Override | ||
public void save(OutputStream output, ProgressListener listener) throws IOException { | ||
long size = rbm.serializedSizeInBytes(); | ||
IOUtil.writeLong(output, size); | ||
rbm.serialize(new DataOutputStream(output)); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return HDTVocabulary.BITMAP_TYPE_ROARING; | ||
} | ||
|
||
@Override | ||
public long select1(long n) { | ||
long position = n - 1; | ||
if (position == -1) | ||
return -1; | ||
if (position < rbm.getLongCardinality()) { | ||
return rbm.select((int) position); | ||
} else { | ||
return rbm.select((int) rbm.getLongCardinality() - 1) + 1; | ||
} | ||
} | ||
|
||
@Override | ||
public long rank1(long position) { | ||
if (position >= 0) | ||
return rbm.rankLong((int) position); | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long countOnes() { | ||
return rbm.getLongCardinality(); | ||
} | ||
|
||
@Override | ||
public long selectPrev1(long start) { | ||
return select1(rank1(start)); | ||
} | ||
|
||
@Override | ||
public long selectNext1(long start) { | ||
long pos = rank1(start - 1); | ||
if (pos < rbm.getLongCardinality()) | ||
return select1(pos + 1); | ||
return -1; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
buffer.close(); | ||
} | ||
} |
Oops, something went wrong.