class TDigestState extends AVLTreeDigest {

    public static final long SHALLOW_SIZE = RamUsageEstimator.shallowSizeOfInstance(TDigestState.class);

    private static final int DEFAULT_COMPRESSION = 100;
    private final double compression;
    private double[] fractions;

    TDigestState(double compression, double[] fractions) {
        super(compression);
        this.compression = compression;
        this.fractions = fractions;
    }

    static TDigestState createEmptyState() {
        return new TDigestState(DEFAULT_COMPRESSION, new double[]{});
    }

    boolean isEmpty() {
        return fractions.length == 0;
    }

    @Override
    public double compression() {
        return compression;
    }

    double[] fractions() {
        return fractions;
    }

    void fractions(double[] fractions) {
        this.fractions = fractions;
    }

    public static void write(TDigestState state, StreamOutput out) throws IOException {
        out.writeDouble(state.compression);
        out.writeDoubleArray(state.fractions);
        out.writeVInt(state.centroidCount());
        for (Centroid centroid : state.centroids()) {
            out.writeDouble(centroid.mean());
            out.writeVLong(centroid.count());
        }
    }

    public static TDigestState read(StreamInput in) throws IOException {<FILL_FUNCTION_BODY>}
}

        double compression = in.readDouble();
        double[] fractions = in.readDoubleArray();
        TDigestState state = new TDigestState(compression, fractions);
        int n = in.readVInt();
        for (int i = 0; i < n; i++) {
            state.add(in.readDouble(), in.readVInt());
        }
        return state;
    
<no_super_class>