Java Code Examples for com.tdunning.math.stats.AVLTreeDigest#compress()
The following examples show how to use
com.tdunning.math.stats.AVLTreeDigest#compress() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PercentileAgg.java From lucene-solr with Apache License 2.0 | 5 votes |
public Object getShardValue(int slot) throws IOException { AVLTreeDigest digest = digests[slot]; if (digest == null) return null; // no values for this slot digest.compress(); int sz = digest.byteSize(); if (buf == null || buf.capacity() < sz) { buf = ByteBuffer.allocate(sz+(sz>>1)); // oversize by 50% } else { buf.clear(); } digest.asSmallBytes(buf); byte[] arr = Arrays.copyOf(buf.array(), buf.position()); return arr; }
Example 2
Source File: PercentileAgg.java From lucene-solr with Apache License 2.0 | 5 votes |
public Object getShardValue(int slot) throws IOException { AVLTreeDigest digest = digests[slot]; if (digest == null) return null; // no values for this slot digest.compress(); int sz = digest.byteSize(); if (buf == null || buf.capacity() < sz) { buf = ByteBuffer.allocate(sz+(sz>>1)); // oversize by 50% } else { buf.clear(); } digest.asSmallBytes(buf); byte[] arr = Arrays.copyOf(buf.array(), buf.position()); return arr; }
Example 3
Source File: PercentileAgg.java From lucene-solr with Apache License 2.0 | 5 votes |
public Object getShardValue(int slot) throws IOException { AVLTreeDigest digest = digests[slot]; if (digest == null) return null; digest.compress(); int sz = digest.byteSize(); if (buf == null || buf.capacity() < sz) { buf = ByteBuffer.allocate(sz+(sz>>1)); // oversize by 50% } else { buf.clear(); } digest.asSmallBytes(buf); byte[] arr = Arrays.copyOf(buf.array(), buf.position()); return arr; }
Example 4
Source File: TestJsonFacets.java From lucene-solr with Apache License 2.0 | 4 votes |
/*** test code to ensure TDigest is working as we expect. */ public void XtestTDigest() throws Exception { AVLTreeDigest t1 = new AVLTreeDigest(100); t1.add(10, 1); t1.add(90, 1); t1.add(50, 1); System.out.println(t1.quantile(0.1)); System.out.println(t1.quantile(0.5)); System.out.println(t1.quantile(0.9)); assertEquals(t1.quantile(0.5), 50.0, 0.01); AVLTreeDigest t2 = new AVLTreeDigest(100); t2.add(130, 1); t2.add(170, 1); t2.add(90, 1); System.out.println(t2.quantile(0.1)); System.out.println(t2.quantile(0.5)); System.out.println(t2.quantile(0.9)); AVLTreeDigest top = new AVLTreeDigest(100); t1.compress(); ByteBuffer buf = ByteBuffer.allocate(t1.byteSize()); // upper bound t1.asSmallBytes(buf); byte[] arr1 = Arrays.copyOf(buf.array(), buf.position()); ByteBuffer rbuf = ByteBuffer.wrap(arr1); top.add(AVLTreeDigest.fromBytes(rbuf)); System.out.println(top.quantile(0.1)); System.out.println(top.quantile(0.5)); System.out.println(top.quantile(0.9)); t2.compress(); ByteBuffer buf2 = ByteBuffer.allocate(t2.byteSize()); // upper bound t2.asSmallBytes(buf2); byte[] arr2 = Arrays.copyOf(buf2.array(), buf2.position()); ByteBuffer rbuf2 = ByteBuffer.wrap(arr2); top.add(AVLTreeDigest.fromBytes(rbuf2)); System.out.println(top.quantile(0.1)); System.out.println(top.quantile(0.5)); System.out.println(top.quantile(0.9)); }