本文整理汇总了Java中it.unimi.dsi.io.OutputBitStream类的典型用法代码示例。如果您正苦于以下问题:Java OutputBitStream类的具体用法?Java OutputBitStream怎么用?Java OutputBitStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OutputBitStream类属于it.unimi.dsi.io包,在下文中一共展示了OutputBitStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:RankSys,项目名称:RankSys,代码行数:21,代码来源:EliasFanoBitStreamCODEC.java
示例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);
}
}
开发者ID:RankSys,项目名称:RankSys,代码行数:19,代码来源:RiceBitStreamCODEC.java
示例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;
}
开发者ID:RankSys,项目名称:RankSys,代码行数:19,代码来源:BitStreamCODEC.java
示例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 );
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:20,代码来源:BVGraph.java
示例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";
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:24,代码来源:BitStreamArcLabelledGraphTest.java
示例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";
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:25,代码来源:BitStreamArcLabelledGraphTest.java
示例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 );
}
开发者ID:helgeho,项目名称:HadoopWebGraph,代码行数:16,代码来源:HdfsBVGraph.java
示例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);
}
}
开发者ID:vigna,项目名称:Sux4J,代码行数:35,代码来源:PaCoTrieDistributor.java
示例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);
}
}
开发者ID:vigna,项目名称:Sux4J,代码行数:36,代码来源:VLPaCoTrieDistributor.java
示例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();
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:36,代码来源:BitStreamArcLabelledImmutableGraph.java
示例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." );
}
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:14,代码来源:BVGraph.java
示例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." );
}
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:14,代码来源:BVGraph.java
示例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." );
}
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:17,代码来源:BVGraph.java
示例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." );
}
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:15,代码来源:BVGraph.java
示例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." );
}
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:15,代码来源:BVGraph.java
示例16: writeResidual
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
/** Writes a residual to the given stream.
*
* @param obs a graph-file output bit stream.
* @param residual the residual.
* @return the number of written bits.
*/
protected final int writeResidual( final OutputBitStream obs, final int residual ) throws IOException {
switch( residualCoding ) {
case GAMMA: return obs.writeGamma( residual );
case ZETA: return obs.writeZeta( residual, zetaK );
case DELTA: return obs.writeDelta( residual );
case GOLOMB: return obs.writeGolomb( residual, zetaK );
case NIBBLE: return obs.writeNibble( residual );
default: throw new UnsupportedOperationException( "The required residuals coding (" + residualCoding + ") is not supported." );
}
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:17,代码来源:BVGraph.java
示例17: createGraph
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
public String createGraph( 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 = new OutputBitStream( basename + "-fixedlabel" + BitStreamArcLabelledImmutableGraph.LABELS_EXTENSION );
OutputBitStream offsets = new OutputBitStream( basename + "-fixedlabel" + BitStreamArcLabelledImmutableGraph.LABEL_OFFSETS_EXTENSION );
Label lab;
offsets.writeGamma( 0 );
for( int i = 0; i < n; i++ ) {
int bits = 0;
for( IntIterator j = LazyIntIterators.eager( g.successors( i ) ); j.hasNext(); ) {
int succ = j.nextInt();
lab = new FakeCSFixedWidthIntLabel( "TEST", width, i * succ + i );
bits += lab.toBitStream( labels, i );
}
offsets.writeGamma( bits );
}
labels.close();
offsets.close();
PrintWriter pw = new PrintWriter( new FileWriter( basename + "-fixedlabel" + ImmutableGraph.PROPERTIES_EXTENSION ) );
pw.println( ImmutableGraph.GRAPHCLASS_PROPERTY_KEY + " = " + BitStreamArcLabelledImmutableGraph.class.getName() );
pw.println( BitStreamArcLabelledImmutableGraph.LABELSPEC_PROPERTY_KEY + " = " + FakeCSFixedWidthIntLabel.class.getName() + "(TEST," + width + ")" );
pw.println( ArcLabelledImmutableGraph.UNDERLYINGGRAPH_PROPERTY_KEY + " = " + basename.getName() );
pw.close();
return basename + "-fixedlabel";
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:29,代码来源:CSSerializationTest.java
示例18: createGraphWithFixedWidthListLabels
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
public String createGraphWithFixedWidthListLabels( File basename, ImmutableGraph g, int width ) throws IllegalArgumentException, SecurityException, IOException {
final int n = g.numNodes();
System.err.println( "Testing " + n + " nodes, element width " + width+ ", basename " + basename );
OutputBitStream labels = createTempBitStream( basename + "-fixedlistlabel" + BitStreamArcLabelledImmutableGraph.LABELS_EXTENSION );
OutputBitStream offsets = createTempBitStream( basename + "-fixedlistlabel" + 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(); ) {
int succ = j.nextInt();
bits += labels.writeGamma( ( succ + 1 ) * 2 ); // list length
for( int k = 0; k < ( succ + 1 ) * 2 ; k++ ) bits += labels.writeInt( i * k + i, width );
}
offsets.writeGamma( bits );
}
labels.close();
offsets.close();
PrintWriter pw = new PrintWriter( new FileWriter( basename + "-fixedlistlabel" + ImmutableGraph.PROPERTIES_EXTENSION ) );
pw.println( ImmutableGraph.GRAPHCLASS_PROPERTY_KEY + " = " + BitStreamArcLabelledImmutableGraph.class.getName() );
pw.println( BitStreamArcLabelledImmutableGraph.LABELSPEC_PROPERTY_KEY + " = " + FixedWidthIntListLabel.class.getName() + "(TEST," + width + ")" );
pw.println( ArcLabelledImmutableGraph.UNDERLYINGGRAPH_PROPERTY_KEY + " = " + basename.getName() );
pw.close();
return basename + "-fixedlistlabel";
}
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:28,代码来源:BitStreamArcLabelledGraphTest.java
示例19: write
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
@Override
protected void write(OutputBitStream obs, int[] in, int offset, int len) throws IOException {
for (int i = offset; i < offset + len; i++) {
obs.writeZeta(in[i], k);
}
}
开发者ID:RankSys,项目名称:RankSys,代码行数:7,代码来源:ZetaBitStreamCODEC.java
示例20: write
import it.unimi.dsi.io.OutputBitStream; //导入依赖的package包/类
@Override
protected void write(OutputBitStream obs, int[] in, int offset, int len) throws IOException {
for (int i = offset; i < offset + len; i++) {
obs.writeGamma(in[i]);
}
}
开发者ID:RankSys,项目名称:RankSys,代码行数:7,代码来源:GammaBitStreamCODEC.java
注:本文中的it.unimi.dsi.io.OutputBitStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论