Update of /cvsroot/cweb/lgpl-utils/src/java/it/unimi/dsi/mg4j/io
In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14570/src/java/it/unimi/dsi/mg4j/io
Added Files:
NullInputStream.java OutputBitStream.java InputBitStream.java
Log Message:
Commit incorporates some clases from the mg4j project that I am trying out for order preserving (alphabetic) compression. I am in the process of writing test cases for the HuTuckerCodec that verify its use and order preserving properties. A minimal set of classes from mg4j has been imported to support compression. A fastutils jar has also been incorporated, but it can doubtless be prunned down even further. The import is from the 1.x version of mg4j. I should really re-import from 2.0 now that it has been released.
--- NEW FILE: NullInputStream.java ---
package it.unimi.dsi.mg4j.io;
/*
* MG4J: Managing Gigabytes for Java
*
* Copyright (C) 2003-2006 Sebastiano Vigna
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
import it.unimi.dsi.fastutil.io.MeasurableInputStream;
import it.unimi.dsi.fastutil.io.RepositionableStream;
import java.io.IOException;
import java.io.Serializable;
/** End-of-stream-only input stream.
*
* <P>This stream has length 0, and will always return end-of-file on any read attempt.
*
* <P>This class is a singleton. You cannot create a null input stream,
* but you can obtain an instance of this class using {@link #getInstance()}.
*
* @author Sebastiano Vigna
* @since 0.8
*/
public class NullInputStream extends MeasurableInputStream implements RepositionableStream, Serializable {
private static final long serialVersionUID = 1L;
private final static NullInputStream INSTANCE = new NullInputStream();
private NullInputStream() {}
public int read() { return -1; }
/** Returns the only instance of this class.
*
* @return the only instance of this class.
*/
public static NullInputStream getInstance() {
return INSTANCE;
}
private Object readResolve() {
return INSTANCE;
}
@Override
public long length() {
return 0;
}
@Override
public long position() {
return 0;
}
public void position( long position ) throws IOException {
// TODO: we should specify the semantics out of bounds
return;
}
}
--- NEW FILE: OutputBitStream.java ---
package it.unimi.dsi.mg4j.io;
/*
* MG4J: Managing Gigabytes for Java
*
* Copyright (C) 2002-2006 Sebastiano Vigna
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
[...1058 lines suppressed...]
*
* @param x a long natural number.
* @return the number of bits written.
* @throws IllegalArgumentException if you try to write a negative number.
*/
public int writeLongNibble( final long x ) throws IOException {
if ( x < 0 ) throw new IllegalArgumentException( "The argument " + x + " is negative" );
if ( x == 0 ) return writeInt( 8, 4 );
final int msb = Fast.mostSignificantBit( x );
int h = msb / 3;
do {
writeBit( h == 0 );
writeInt( (int)( x >> h * 3 ) , 3 );
} while( h-- != 0 );
return ( ( msb / 3 ) + 1 ) << 2;
}
}
--- NEW FILE: InputBitStream.java ---
package it.unimi.dsi.mg4j.io;
/*
* MG4J: Managing Gigabytes for Java
*
* Copyright (C) 2002-2006 Sebastiano Vigna
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
[...1177 lines suppressed...]
}
}
public Boolean next() {
return Boolean.valueOf( nextBoolean() );
}
public void remove() {
throw new UnsupportedOperationException();
}
public int skip( final int n ) {
try {
return (int)skip( (long)n );
}
catch ( IOException e ) {
throw new RuntimeException( e );
}
}
}
|