本文整理汇总了Java中it.unimi.dsi.io.OutputBitStream类的典型用法代码示例。如果您正苦于以下问题:Java OutputBitStream类的具体用法?Java OutputBitStream怎么用?Java OutputBitStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OutputBitStream类属于it.unimi.dsi.io包,在下文中一共展示了OutputBitStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
@Override
protected void write(OutputBitStream obs, int[] in, int offset, int len) throws IOException {
int l = 31 - Integer.numberOfLeadingZeros(in[offset + len - 1] / len);
int mask = (1 << l) - 1;
if (l < 1) {
l = 1;
mask = 1;
}
int d = 0;
obs.writeInt(l, 32);
for (int i = offset; i < offset + len; i++) {
final int x = in[i];
final int hx = x >> l;
obs.writeUnary(hx - d);
obs.writeInt(x & mask, l);
d = hx;
}
}
示例2: write
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
@Override
protected void write(OutputBitStream obs, int[] in, int offset, int len) throws IOException {
long sum = 0;
for (int i = offset; i < offset + len; i++) {
sum += in[i];
}
int b = (int) (0.69 * sum / (double) len);
if (b == 0) {
b = 1;
}
int log2b = 31 - Integer.numberOfLeadingZeros(b);
obs.writeInt(log2b, 32);
for (int i = offset; i < offset + len; i++) {
obs.writeUnary(in[i] >> log2b);
obs.writeInt(in[i] & ((1 << log2b) - 1), log2b);
}
}
示例3: co
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
@Override
public byte[] co(int[] in, int offset, int len) {
byte[] out = new byte[len * 4 + 1024];
int writtenBits = 0;
try (OutputBitStream obs = new OutputBitStream(out)) {
write(obs, in, offset, len);
writtenBits = (int) obs.writtenBits();
} catch (IOException ex) {
LOG.log(Level.SEVERE, null, ex);
}
out = Arrays.copyOf(out, (writtenBits + 7) / 8);
add(len * Integer.BYTES, out.length * Byte.BYTES);
return out;
}
示例4: writeOffsets
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
/** Write the offset file to a given bit stream.
* @param obs the output bit stream to which offsets will be written.
* @param pl a progress logger, or <code>null</code>.
*/
public void writeOffsets( final OutputBitStream obs, final ProgressLogger pl ) throws IOException {
final BVGraphNodeIterator nodeIterator = (BVGraphNodeIterator) nodeIterator( 0 );
int n = numNodes();
long lastOffset = 0;
while( n-- != 0 ) {
// We fetch the current position of the underlying input bit stream, which is at the start of the next node.
writeOffset( obs, nodeIterator.ibs.readBits() - lastOffset );
lastOffset = nodeIterator.ibs.readBits();
nodeIterator.nextInt();
nodeIterator.outdegree();
nodeIterator.successorArray();
if ( pl != null ) pl.update();
}
writeOffset( obs, nodeIterator.ibs.readBits() - lastOffset );
}
示例5: createGraphWithFixedWidthLabels
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
public String createGraphWithFixedWidthLabels( File basename, ImmutableGraph g, int width ) throws IllegalArgumentException, SecurityException, IOException {
final int n = g.numNodes();
System.err.println( "Testing " + n + " nodes, width " + width+ ", basename " + basename );
OutputBitStream labels = createTempBitStream( basename + "-fixedlabel" + BitStreamArcLabelledImmutableGraph.LABELS_EXTENSION );
OutputBitStream offsets = createTempBitStream( basename + "-fixedlabel" + BitStreamArcLabelledImmutableGraph.LABEL_OFFSETS_EXTENSION );
offsets.writeGamma( 0 );
for( int i = 0; i < n; i++ ) {
int bits = 0;
for( IntIterator j = LazyIntIterators.eager( g.successors( i ) ); j.hasNext(); ) bits += labels.writeInt( i * j.nextInt() + i, width );
offsets.writeGamma( bits );
}
labels.close();
offsets.close();
PrintWriter pw = new PrintWriter( new FileWriter( basename + "-fixedlabel.properties" ) );
pw.println( ImmutableGraph.GRAPHCLASS_PROPERTY_KEY + " = " + BitStreamArcLabelledImmutableGraph.class.getName() );
pw.println( BitStreamArcLabelledImmutableGraph.LABELSPEC_PROPERTY_KEY + " = " + FixedWidthIntLabel.class.getName() + "(TEST," + width + ")" );
pw.println( ArcLabelledImmutableGraph.UNDERLYINGGRAPH_PROPERTY_KEY + " = " + basename.getName() );
pw.close();
return basename + "-fixedlabel";
}
示例6: createGraphWithGammaLabels
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
public String createGraphWithGammaLabels( File basename, ImmutableGraph g ) throws IllegalArgumentException, SecurityException, IOException {
// We create a complete graph with labels
final int n = g.numNodes();
System.err.println( "Testing " + n + " nodes, gamma coding, basename " + basename );
OutputBitStream labels = createTempBitStream( basename + "-gammalabel" + BitStreamArcLabelledImmutableGraph.LABELS_EXTENSION );
OutputBitStream offsets = createTempBitStream( basename + "-gammalabel" + BitStreamArcLabelledImmutableGraph.LABEL_OFFSETS_EXTENSION );
offsets.writeGamma( 0 );
for( int i = 0; i < n; i++ ) {
int bits = 0;
for( IntIterator j = LazyIntIterators.eager( g.successors( i ) ); j.hasNext(); ) bits += labels.writeGamma( i * j.nextInt() + i );
offsets.writeGamma( bits );
}
labels.close();
offsets.close();
PrintWriter pw = new PrintWriter( new FileWriter( basename + "-gammalabel" + ImmutableGraph.PROPERTIES_EXTENSION ) );
pw.println( ImmutableGraph.GRAPHCLASS_PROPERTY_KEY + " = " + BitStreamArcLabelledImmutableGraph.class.getName() );
pw.println( BitStreamArcLabelledImmutableGraph.LABELSPEC_PROPERTY_KEY + " = " + GammaCodedIntLabel.class.getName() + "(TEST)" );
pw.println( ArcLabelledImmutableGraph.UNDERLYINGGRAPH_PROPERTY_KEY + " = " + basename.getName() );
pw.close();
return basename + "-gammalabel";
}
示例7: writeOffsets
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
@Override
public void writeOffsets( final OutputBitStream obs, final ProgressLogger pl ) throws IOException {
final HdfsBVGraphNodeIterator nodeIterator = (HdfsBVGraphNodeIterator) nodeIterator( 0 );
int n = numNodes();
long lastOffset = 0;
while( n-- != 0 ) {
writeOffset( obs, nodeIterator.ibs.readBits() - lastOffset );
lastOffset = nodeIterator.ibs.readBits();
nodeIterator.nextInt();
nodeIterator.outdegree();
nodeIterator.successorArray();
if ( pl != null ) pl.update();
}
writeOffset( obs, nodeIterator.ibs.readBits() - lastOffset );
}
示例8: PaCoTrieDistributor
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
/** Creates a partial compacted trie using given elements, bucket size and transformation strategy.
*
* @param elements the elements among which the trie must be able to rank.
* @param log2BucketSize the logarithm of the size of a bucket.
* @param transformationStrategy a transformation strategy that must turn the elements in <code>elements</code> into a list of
* distinct, lexicographically increasing (in iteration order) bit vectors.
*/
@SuppressWarnings("resource")
public PaCoTrieDistributor(final Iterable<? extends T> elements, final int log2BucketSize, final TransformationStrategy<? super T> transformationStrategy) throws IOException {
this.transformationStrategy = transformationStrategy;
final ProgressLogger pl = new ProgressLogger(LOGGER);
pl.displayLocalSpeed = true;
pl.displayFreeMemory = true;
pl.itemsName = "keys";
final PartialTrie<T> immutableBinaryTrie = new PartialTrie<>(elements, log2BucketSize, transformationStrategy, pl);
final FastByteArrayOutputStream fbStream = new FastByteArrayOutputStream();
final OutputBitStream trie = new OutputBitStream(fbStream, 0);
pl.start("Converting to bitstream...");
numberOfLeaves = immutableBinaryTrie.toStream(trie, pl);
pl.done();
defRetValue = -1; // For the very few cases in which we can decide
LOGGER.info("Trie bit size: " + trie.writtenBits());
trie.flush();
fbStream.trim();
this.trie = fbStream.array;
if (DDEBUG) {
final MutableString s = new MutableString();
recToString(new InputBitStream(this.trie), new MutableString(), s, new MutableString(), 0);
System.err.println(s);
}
}
示例9: VLPaCoTrieDistributor
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
/** Creates a partial compacted trie using given elements, bucket size and transformation strategy.
*
* @param elements the elements among which the trie must be able to rank.
* @param bucketSize the size of a bucket.
* @param transformationStrategy a transformation strategy that must turn the elements in <code>elements</code> into a list of
* distinct, lexicographically increasing (in iteration order) bit vectors.
*/
@SuppressWarnings("resource")
public VLPaCoTrieDistributor(final Iterable<? extends T> elements, final long size, final int bucketSize, final TransformationStrategy<? super T> transformationStrategy) throws IOException {
this.transformationStrategy = transformationStrategy;
final ProgressLogger pl = new ProgressLogger(LOGGER);
pl.displayLocalSpeed = true;
pl.displayFreeMemory = true;
pl.itemsName = "keys";
final PartialTrie<T> immutableBinaryTrie = new PartialTrie<>(elements, size, bucketSize, transformationStrategy, pl);
final FastByteArrayOutputStream fbStream = new FastByteArrayOutputStream();
final OutputBitStream trie = new OutputBitStream(fbStream, 0);
pl.expectedUpdates = immutableBinaryTrie.size;
pl.start("Converting to bitstream...");
numberOfLeaves = immutableBinaryTrie.toStream(trie, pl);
pl.done();
offset = immutableBinaryTrie.offset;
LOGGER.debug("Trie bit size: " + trie.writtenBits());
trie.flush();
fbStream.trim();
this.trie = fbStream.array;
if (DDEBUG) {
final MutableString s = new MutableString();
recToString(new InputBitStream(this.trie), new MutableString(), s, new MutableString(), 0);
System.err.println(s);
}
}
示例10: store
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
public static void store( final ArcLabelledImmutableGraph graph, final CharSequence basename, final CharSequence underlyingBasename, final ProgressLogger pl ) throws IOException {
final OutputBitStream labels = new OutputBitStream( basename + LABELS_EXTENSION, STD_BUFFER_SIZE );
final OutputBitStream offsets = new OutputBitStream( basename + LABEL_OFFSETS_EXTENSION, STD_BUFFER_SIZE );
if ( pl != null ) {
pl.itemsName = "nodes";
pl.expectedUpdates = graph.numNodes();
pl.start( "Saving labels..." );
}
final ArcLabelledNodeIterator nodeIterator = graph.nodeIterator();
offsets.writeGamma( 0 );
int curr;
long count;
LabelledArcIterator successors;
while( nodeIterator.hasNext() ) {
curr = nodeIterator.nextInt();
successors = nodeIterator.successors();
count = 0;
while( successors.nextInt() != -1 ) count += successors.label().toBitStream( labels, curr );
offsets.writeLongGamma( count );
if ( pl != null ) pl.lightUpdate();
}
if ( pl != null ) pl.done();
labels.close();
offsets.close();
final PrintWriter properties = new PrintWriter( new FileOutputStream( basename + ImmutableGraph.PROPERTIES_EXTENSION ) );
properties.println( ImmutableGraph.GRAPHCLASS_PROPERTY_KEY + " = " + BitStreamArcLabelledImmutableGraph.class.getName() );
properties.println( ArcLabelledImmutableGraph.UNDERLYINGGRAPH_PROPERTY_KEY + " = " + underlyingBasename );
properties.println( BitStreamArcLabelledImmutableGraph.LABELSPEC_PROPERTY_KEY + " = " + graph.prototype().toSpec() );
properties.close();
}
示例11: writeOffset
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
/** Writes an offset difference to the given stream.
*
* @param obs an offset-file output bit stream.
* @param x an offset difference to be stored in the stream.
* @return the number of bits written.
*/
protected final int writeOffset( final OutputBitStream obs, final long x ) throws IOException {
switch( offsetCoding ) {
case GAMMA: return obs.writeLongGamma( x );
case DELTA: return obs.writeLongDelta( x );
default: throw new UnsupportedOperationException( "The required offset coding (" + offsetCoding + ") is not supported." );
}
}
示例12: writeOutdegree
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
/** Writes an outdegree to the given stream.
*
* @param obs a graph-file output bit stream.
* @param d an outdegree to be stored in the stream.
* @return the number of bits written.
*/
protected final int writeOutdegree( final OutputBitStream obs, final int d ) throws IOException {
switch( outdegreeCoding ) {
case GAMMA: return obs.writeGamma( d );
case DELTA: return obs.writeDelta( d );
default: throw new UnsupportedOperationException( "The required outdegree coding (" + outdegreeCoding + ") is not supported." );
}
}
示例13: writeReference
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
/** Writes a reference to the given stream.
*
* @param obs a graph-file output bit stream.
* @param ref the reference.
* @return the number of bits written.
*/
protected final int writeReference( final OutputBitStream obs, final int ref ) throws IOException {
if ( ref > windowSize ) throw new IllegalStateException( "The required reference (" + ref + ") is incompatible with the window size (" + windowSize + ")" );
switch( referenceCoding ) {
case UNARY: return obs.writeUnary( ref );
case GAMMA: return obs.writeGamma( ref );
case DELTA: return obs.writeDelta( ref );
default: throw new UnsupportedOperationException( "The required reference coding (" + referenceCoding + ") is not supported." );
}
}
示例14: writeBlockCount
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
/** Writes a block count to the given stream.
*
* @param obs a graph-file output bit stream.
* @param count the block count.
* @return the number of written bits.
*/
protected final int writeBlockCount( final OutputBitStream obs, final int count ) throws IOException {
switch( blockCountCoding ) {
case UNARY: return obs.writeUnary( count );
case GAMMA: return obs.writeGamma( count );
case DELTA: return obs.writeDelta( count );
default: throw new UnsupportedOperationException( "The required block count coding (" + blockCountCoding + ") is not supported." );
}
}
示例15: writeBlock
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
/** Writes a block to the given stream.
*
* @param obs a graph-file output bit stream.
* @param block the block.
* @return the number of written bits.
*/
protected final int writeBlock( final OutputBitStream obs, final int block ) throws IOException {
switch( blockCoding ) {
case UNARY: return obs.writeUnary( block );
case GAMMA: return obs.writeGamma( block );
case DELTA: return obs.writeDelta( block );
default: throw new UnsupportedOperationException( "The required block coding (" + blockCoding + ") is not supported." );
}
}