com.indeed.mph.serializers.AbstractSmartSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mph-table Show documentation
Show all versions of mph-table Show documentation
Minimal Perfect Hash Tables
package com.indeed.mph.serializers;
import com.indeed.mph.SmartSerializer;
import com.indeed.mph.LinearDiophantineEquation;
import com.indeed.mph.NullOutputStream;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* @author alexs
*/
public abstract class AbstractSmartSerializer extends AbstractParseable implements SmartSerializer {
private static final long serialVersionUID = 5010196727600564999L;
public void skip(final DataInput in, final int n) throws IOException {
for (int i = 0; i < n; ++i) {
read(in);
}
}
public long sizeOf(final T t) throws IOException {
final LinearDiophantineEquation eq = size();
if (eq != null && eq.isConstant()) {
return eq.apply(0);
}
final NullOutputStream nullOut = new NullOutputStream();
final DataOutputStream dataOut = new DataOutputStream(nullOut);
write(t, dataOut);
return nullOut.getCount();
}
public LinearDiophantineEquation size() {
return null;
}
}