@ SuppressWarnings ( "WeakerAccess" ) public static AVLTreeDigest fromBytes ( ByteBuffer buf ) { int encoding = buf . getInt ( ) ; if ( encoding == VERBOSE_ENCODING ) { double min = buf . getDouble ( ) ; double max = buf . getDouble ( ) ; double compression = buf . getDouble ( ) ; AVLTreeDigest r = new AVLTreeDigest ( compression ) ; r . setMinMax ( min , max ) ; int n = buf . getInt ( ) ; double [ ] means = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { means [ i ] = buf . getDouble ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { r . add ( means [ i ] , buf . getInt ( ) ) ; } return r ; } else if ( encoding == SMALL_ENCODING ) { double min = buf . getDouble ( ) ; double max = buf . getDouble ( ) ; double compression = buf . getDouble ( ) ; AVLTreeDigest r = new AVLTreeDigest ( compression ) ; r . setMinMax ( min , max ) ; int n = buf . getInt ( ) ; double [ ] means = new double [ n ] ; double x = 0 ; for ( int i = 0 ; i < n ; i ++ ) { double delta = buf . getFloat ( ) ; x += delta ; means [ i ] = x ; } for ( int i = 0 ; i < n ; i ++ ) { int z = decode ( buf ) ; r . add ( means [ i ] , z ) ; } return r ; } else { throw new IllegalStateException ( "Invalid format for serialized histogram" ) ; } }
Reads a histogram from a byte buffer