hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dimaspi...@apache.org
Subject [16/52] [partial] hbase-site git commit: Published site at 63808a224c8689d07e55f90efd25f9597b0d04dd.
Date Thu, 29 Sep 2016 20:09:46 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/044b3379/apidocs/src-html/org/apache/hadoop/hbase/util/Counter.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/util/Counter.html b/apidocs/src-html/org/apache/hadoop/hbase/util/Counter.html
index 01ae315..3cb1f0b 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/util/Counter.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/util/Counter.html
@@ -34,188 +34,190 @@
 <span class="sourceLineNo">026</span><a name="line.26"></a>
 <span class="sourceLineNo">027</span>/**<a name="line.27"></a>
 <span class="sourceLineNo">028</span> * High scalable counter. Thread safe.<a name="line.28"></a>
-<span class="sourceLineNo">029</span> */<a name="line.29"></a>
-<span class="sourceLineNo">030</span>@InterfaceAudience.Public<a name="line.30"></a>
-<span class="sourceLineNo">031</span>@InterfaceStability.Evolving<a name="line.31"></a>
-<span class="sourceLineNo">032</span>public class Counter {<a name="line.32"></a>
-<span class="sourceLineNo">033</span>  private static final int MAX_CELLS_LENGTH = 1 &lt;&lt; 20;<a name="line.33"></a>
-<span class="sourceLineNo">034</span><a name="line.34"></a>
-<span class="sourceLineNo">035</span>  private static class Cell {<a name="line.35"></a>
-<span class="sourceLineNo">036</span>    // Pads are added around the value to avoid cache-line contention with<a name="line.36"></a>
-<span class="sourceLineNo">037</span>    // another cell's value. The cache-line size is expected to be equal to or<a name="line.37"></a>
-<span class="sourceLineNo">038</span>    // less than about 128 Bytes (= 64 Bits * 16).<a name="line.38"></a>
-<span class="sourceLineNo">039</span><a name="line.39"></a>
-<span class="sourceLineNo">040</span>    @SuppressWarnings("unused")<a name="line.40"></a>
-<span class="sourceLineNo">041</span>    volatile long p0, p1, p2, p3, p4, p5, p6;<a name="line.41"></a>
-<span class="sourceLineNo">042</span>    volatile long value;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>    @SuppressWarnings("unused")<a name="line.43"></a>
-<span class="sourceLineNo">044</span>    volatile long q0, q1, q2, q3, q4, q5, q6;<a name="line.44"></a>
-<span class="sourceLineNo">045</span><a name="line.45"></a>
-<span class="sourceLineNo">046</span>    static final AtomicLongFieldUpdater&lt;Cell&gt; valueUpdater =<a name="line.46"></a>
-<span class="sourceLineNo">047</span>        AtomicLongFieldUpdater.newUpdater(Cell.class, "value");<a name="line.47"></a>
-<span class="sourceLineNo">048</span><a name="line.48"></a>
-<span class="sourceLineNo">049</span>    Cell() {}<a name="line.49"></a>
+<span class="sourceLineNo">029</span> * @deprecated use {@link java.util.concurrent.atomic.LongAdder} instead.<a name="line.29"></a>
+<span class="sourceLineNo">030</span> */<a name="line.30"></a>
+<span class="sourceLineNo">031</span>@InterfaceAudience.Public<a name="line.31"></a>
+<span class="sourceLineNo">032</span>@InterfaceStability.Evolving<a name="line.32"></a>
+<span class="sourceLineNo">033</span>@Deprecated<a name="line.33"></a>
+<span class="sourceLineNo">034</span>public class Counter {<a name="line.34"></a>
+<span class="sourceLineNo">035</span>  private static final int MAX_CELLS_LENGTH = 1 &lt;&lt; 20;<a name="line.35"></a>
+<span class="sourceLineNo">036</span><a name="line.36"></a>
+<span class="sourceLineNo">037</span>  private static class Cell {<a name="line.37"></a>
+<span class="sourceLineNo">038</span>    // Pads are added around the value to avoid cache-line contention with<a name="line.38"></a>
+<span class="sourceLineNo">039</span>    // another cell's value. The cache-line size is expected to be equal to or<a name="line.39"></a>
+<span class="sourceLineNo">040</span>    // less than about 128 Bytes (= 64 Bits * 16).<a name="line.40"></a>
+<span class="sourceLineNo">041</span><a name="line.41"></a>
+<span class="sourceLineNo">042</span>    @SuppressWarnings("unused")<a name="line.42"></a>
+<span class="sourceLineNo">043</span>    volatile long p0, p1, p2, p3, p4, p5, p6;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>    volatile long value;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>    @SuppressWarnings("unused")<a name="line.45"></a>
+<span class="sourceLineNo">046</span>    volatile long q0, q1, q2, q3, q4, q5, q6;<a name="line.46"></a>
+<span class="sourceLineNo">047</span><a name="line.47"></a>
+<span class="sourceLineNo">048</span>    static final AtomicLongFieldUpdater&lt;Cell&gt; valueUpdater =<a name="line.48"></a>
+<span class="sourceLineNo">049</span>        AtomicLongFieldUpdater.newUpdater(Cell.class, "value");<a name="line.49"></a>
 <span class="sourceLineNo">050</span><a name="line.50"></a>
-<span class="sourceLineNo">051</span>    Cell(long initValue) {<a name="line.51"></a>
-<span class="sourceLineNo">052</span>      value = initValue;<a name="line.52"></a>
-<span class="sourceLineNo">053</span>    }<a name="line.53"></a>
-<span class="sourceLineNo">054</span><a name="line.54"></a>
-<span class="sourceLineNo">055</span>    long get() {<a name="line.55"></a>
-<span class="sourceLineNo">056</span>      return value;<a name="line.56"></a>
-<span class="sourceLineNo">057</span>    }<a name="line.57"></a>
-<span class="sourceLineNo">058</span><a name="line.58"></a>
-<span class="sourceLineNo">059</span>    boolean add(long delta) {<a name="line.59"></a>
-<span class="sourceLineNo">060</span>      long current = value;<a name="line.60"></a>
-<span class="sourceLineNo">061</span>      return valueUpdater.compareAndSet(this, current, current + delta);<a name="line.61"></a>
-<span class="sourceLineNo">062</span>    }<a name="line.62"></a>
-<span class="sourceLineNo">063</span>  }<a name="line.63"></a>
-<span class="sourceLineNo">064</span><a name="line.64"></a>
-<span class="sourceLineNo">065</span>  private static class Container {<a name="line.65"></a>
-<span class="sourceLineNo">066</span>    /** The length should be a power of 2. */<a name="line.66"></a>
-<span class="sourceLineNo">067</span>    final Cell[] cells;<a name="line.67"></a>
-<span class="sourceLineNo">068</span><a name="line.68"></a>
-<span class="sourceLineNo">069</span>    /** True if a new extended container is going to replace this. */<a name="line.69"></a>
-<span class="sourceLineNo">070</span>    final AtomicBoolean demoted = new AtomicBoolean();<a name="line.70"></a>
-<span class="sourceLineNo">071</span><a name="line.71"></a>
-<span class="sourceLineNo">072</span>    Container(Cell cell) {<a name="line.72"></a>
-<span class="sourceLineNo">073</span>      this(new Cell[] { cell });<a name="line.73"></a>
-<span class="sourceLineNo">074</span>    }<a name="line.74"></a>
-<span class="sourceLineNo">075</span><a name="line.75"></a>
-<span class="sourceLineNo">076</span>    /**<a name="line.76"></a>
-<span class="sourceLineNo">077</span>     * @param cells the length should be a power of 2<a name="line.77"></a>
-<span class="sourceLineNo">078</span>     */<a name="line.78"></a>
-<span class="sourceLineNo">079</span>    Container(Cell[] cells) {<a name="line.79"></a>
-<span class="sourceLineNo">080</span>      this.cells = cells;<a name="line.80"></a>
-<span class="sourceLineNo">081</span>    }<a name="line.81"></a>
-<span class="sourceLineNo">082</span>  }<a name="line.82"></a>
-<span class="sourceLineNo">083</span><a name="line.83"></a>
-<span class="sourceLineNo">084</span>  private final AtomicReference&lt;Container&gt; containerRef;<a name="line.84"></a>
+<span class="sourceLineNo">051</span>    Cell() {}<a name="line.51"></a>
+<span class="sourceLineNo">052</span><a name="line.52"></a>
+<span class="sourceLineNo">053</span>    Cell(long initValue) {<a name="line.53"></a>
+<span class="sourceLineNo">054</span>      value = initValue;<a name="line.54"></a>
+<span class="sourceLineNo">055</span>    }<a name="line.55"></a>
+<span class="sourceLineNo">056</span><a name="line.56"></a>
+<span class="sourceLineNo">057</span>    long get() {<a name="line.57"></a>
+<span class="sourceLineNo">058</span>      return value;<a name="line.58"></a>
+<span class="sourceLineNo">059</span>    }<a name="line.59"></a>
+<span class="sourceLineNo">060</span><a name="line.60"></a>
+<span class="sourceLineNo">061</span>    boolean add(long delta) {<a name="line.61"></a>
+<span class="sourceLineNo">062</span>      long current = value;<a name="line.62"></a>
+<span class="sourceLineNo">063</span>      return valueUpdater.compareAndSet(this, current, current + delta);<a name="line.63"></a>
+<span class="sourceLineNo">064</span>    }<a name="line.64"></a>
+<span class="sourceLineNo">065</span>  }<a name="line.65"></a>
+<span class="sourceLineNo">066</span><a name="line.66"></a>
+<span class="sourceLineNo">067</span>  private static class Container {<a name="line.67"></a>
+<span class="sourceLineNo">068</span>    /** The length should be a power of 2. */<a name="line.68"></a>
+<span class="sourceLineNo">069</span>    final Cell[] cells;<a name="line.69"></a>
+<span class="sourceLineNo">070</span><a name="line.70"></a>
+<span class="sourceLineNo">071</span>    /** True if a new extended container is going to replace this. */<a name="line.71"></a>
+<span class="sourceLineNo">072</span>    final AtomicBoolean demoted = new AtomicBoolean();<a name="line.72"></a>
+<span class="sourceLineNo">073</span><a name="line.73"></a>
+<span class="sourceLineNo">074</span>    Container(Cell cell) {<a name="line.74"></a>
+<span class="sourceLineNo">075</span>      this(new Cell[] { cell });<a name="line.75"></a>
+<span class="sourceLineNo">076</span>    }<a name="line.76"></a>
+<span class="sourceLineNo">077</span><a name="line.77"></a>
+<span class="sourceLineNo">078</span>    /**<a name="line.78"></a>
+<span class="sourceLineNo">079</span>     * @param cells the length should be a power of 2<a name="line.79"></a>
+<span class="sourceLineNo">080</span>     */<a name="line.80"></a>
+<span class="sourceLineNo">081</span>    Container(Cell[] cells) {<a name="line.81"></a>
+<span class="sourceLineNo">082</span>      this.cells = cells;<a name="line.82"></a>
+<span class="sourceLineNo">083</span>    }<a name="line.83"></a>
+<span class="sourceLineNo">084</span>  }<a name="line.84"></a>
 <span class="sourceLineNo">085</span><a name="line.85"></a>
-<span class="sourceLineNo">086</span>  public Counter() {<a name="line.86"></a>
-<span class="sourceLineNo">087</span>    this(new Cell());<a name="line.87"></a>
-<span class="sourceLineNo">088</span>  }<a name="line.88"></a>
-<span class="sourceLineNo">089</span><a name="line.89"></a>
-<span class="sourceLineNo">090</span>  public Counter(long initValue) {<a name="line.90"></a>
-<span class="sourceLineNo">091</span>    this(new Cell(initValue));<a name="line.91"></a>
-<span class="sourceLineNo">092</span>  }<a name="line.92"></a>
-<span class="sourceLineNo">093</span><a name="line.93"></a>
-<span class="sourceLineNo">094</span>  private Counter(Cell initCell) {<a name="line.94"></a>
-<span class="sourceLineNo">095</span>    containerRef = new AtomicReference&lt;Container&gt;(new Container(initCell));<a name="line.95"></a>
-<span class="sourceLineNo">096</span>  }<a name="line.96"></a>
-<span class="sourceLineNo">097</span><a name="line.97"></a>
-<span class="sourceLineNo">098</span>  private static int hash() {<a name="line.98"></a>
-<span class="sourceLineNo">099</span>    // The logic is borrowed from high-scale-lib's ConcurrentAutoTable.<a name="line.99"></a>
-<span class="sourceLineNo">100</span><a name="line.100"></a>
-<span class="sourceLineNo">101</span>    int h = System.identityHashCode(Thread.currentThread());<a name="line.101"></a>
-<span class="sourceLineNo">102</span>    // You would think that System.identityHashCode on the current thread<a name="line.102"></a>
-<span class="sourceLineNo">103</span>    // would be a good hash fcn, but actually on SunOS 5.8 it is pretty lousy<a name="line.103"></a>
-<span class="sourceLineNo">104</span>    // in the low bits.<a name="line.104"></a>
-<span class="sourceLineNo">105</span><a name="line.105"></a>
-<span class="sourceLineNo">106</span>    h ^= (h &gt;&gt;&gt; 20) ^ (h &gt;&gt;&gt; 12); // Bit spreader, borrowed from Doug Lea<a name="line.106"></a>
-<span class="sourceLineNo">107</span>    h ^= (h &gt;&gt;&gt;  7) ^ (h &gt;&gt;&gt;  4);<a name="line.107"></a>
-<span class="sourceLineNo">108</span>    return h;<a name="line.108"></a>
-<span class="sourceLineNo">109</span>  }<a name="line.109"></a>
-<span class="sourceLineNo">110</span><a name="line.110"></a>
-<span class="sourceLineNo">111</span>  private static class IndexHolder {<a name="line.111"></a>
-<span class="sourceLineNo">112</span>    int index = hash();<a name="line.112"></a>
-<span class="sourceLineNo">113</span>  }<a name="line.113"></a>
-<span class="sourceLineNo">114</span><a name="line.114"></a>
-<span class="sourceLineNo">115</span>  private final ThreadLocal&lt;IndexHolder&gt; indexHolderThreadLocal =<a name="line.115"></a>
-<span class="sourceLineNo">116</span>      new ThreadLocal&lt;IndexHolder&gt;() {<a name="line.116"></a>
-<span class="sourceLineNo">117</span>    @Override<a name="line.117"></a>
-<span class="sourceLineNo">118</span>    protected IndexHolder initialValue() {<a name="line.118"></a>
-<span class="sourceLineNo">119</span>      return new IndexHolder();<a name="line.119"></a>
-<span class="sourceLineNo">120</span>    }<a name="line.120"></a>
-<span class="sourceLineNo">121</span>  };<a name="line.121"></a>
-<span class="sourceLineNo">122</span><a name="line.122"></a>
-<span class="sourceLineNo">123</span>  public void add(long delta) {<a name="line.123"></a>
-<span class="sourceLineNo">124</span>    Container container = containerRef.get();<a name="line.124"></a>
-<span class="sourceLineNo">125</span>    Cell[] cells = container.cells;<a name="line.125"></a>
-<span class="sourceLineNo">126</span>    int mask = cells.length - 1;<a name="line.126"></a>
-<span class="sourceLineNo">127</span><a name="line.127"></a>
-<span class="sourceLineNo">128</span>    IndexHolder indexHolder = indexHolderThreadLocal.get();<a name="line.128"></a>
-<span class="sourceLineNo">129</span>    int baseIndex = indexHolder.index;<a name="line.129"></a>
-<span class="sourceLineNo">130</span>    if(cells[baseIndex &amp; mask].add(delta)) {<a name="line.130"></a>
-<span class="sourceLineNo">131</span>      return;<a name="line.131"></a>
-<span class="sourceLineNo">132</span>    }<a name="line.132"></a>
-<span class="sourceLineNo">133</span><a name="line.133"></a>
-<span class="sourceLineNo">134</span>    int index = baseIndex + 1;<a name="line.134"></a>
-<span class="sourceLineNo">135</span>    while(true) {<a name="line.135"></a>
-<span class="sourceLineNo">136</span>      if(cells[index &amp; mask].add(delta)) {<a name="line.136"></a>
-<span class="sourceLineNo">137</span>        break;<a name="line.137"></a>
-<span class="sourceLineNo">138</span>      }<a name="line.138"></a>
-<span class="sourceLineNo">139</span>      index++;<a name="line.139"></a>
-<span class="sourceLineNo">140</span>    }<a name="line.140"></a>
-<span class="sourceLineNo">141</span><a name="line.141"></a>
-<span class="sourceLineNo">142</span>    indexHolder.index = index;<a name="line.142"></a>
+<span class="sourceLineNo">086</span>  private final AtomicReference&lt;Container&gt; containerRef;<a name="line.86"></a>
+<span class="sourceLineNo">087</span><a name="line.87"></a>
+<span class="sourceLineNo">088</span>  public Counter() {<a name="line.88"></a>
+<span class="sourceLineNo">089</span>    this(new Cell());<a name="line.89"></a>
+<span class="sourceLineNo">090</span>  }<a name="line.90"></a>
+<span class="sourceLineNo">091</span><a name="line.91"></a>
+<span class="sourceLineNo">092</span>  public Counter(long initValue) {<a name="line.92"></a>
+<span class="sourceLineNo">093</span>    this(new Cell(initValue));<a name="line.93"></a>
+<span class="sourceLineNo">094</span>  }<a name="line.94"></a>
+<span class="sourceLineNo">095</span><a name="line.95"></a>
+<span class="sourceLineNo">096</span>  private Counter(Cell initCell) {<a name="line.96"></a>
+<span class="sourceLineNo">097</span>    containerRef = new AtomicReference&lt;Container&gt;(new Container(initCell));<a name="line.97"></a>
+<span class="sourceLineNo">098</span>  }<a name="line.98"></a>
+<span class="sourceLineNo">099</span><a name="line.99"></a>
+<span class="sourceLineNo">100</span>  private static int hash() {<a name="line.100"></a>
+<span class="sourceLineNo">101</span>    // The logic is borrowed from high-scale-lib's ConcurrentAutoTable.<a name="line.101"></a>
+<span class="sourceLineNo">102</span><a name="line.102"></a>
+<span class="sourceLineNo">103</span>    int h = System.identityHashCode(Thread.currentThread());<a name="line.103"></a>
+<span class="sourceLineNo">104</span>    // You would think that System.identityHashCode on the current thread<a name="line.104"></a>
+<span class="sourceLineNo">105</span>    // would be a good hash fcn, but actually on SunOS 5.8 it is pretty lousy<a name="line.105"></a>
+<span class="sourceLineNo">106</span>    // in the low bits.<a name="line.106"></a>
+<span class="sourceLineNo">107</span><a name="line.107"></a>
+<span class="sourceLineNo">108</span>    h ^= (h &gt;&gt;&gt; 20) ^ (h &gt;&gt;&gt; 12); // Bit spreader, borrowed from Doug Lea<a name="line.108"></a>
+<span class="sourceLineNo">109</span>    h ^= (h &gt;&gt;&gt;  7) ^ (h &gt;&gt;&gt;  4);<a name="line.109"></a>
+<span class="sourceLineNo">110</span>    return h;<a name="line.110"></a>
+<span class="sourceLineNo">111</span>  }<a name="line.111"></a>
+<span class="sourceLineNo">112</span><a name="line.112"></a>
+<span class="sourceLineNo">113</span>  private static class IndexHolder {<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    int index = hash();<a name="line.114"></a>
+<span class="sourceLineNo">115</span>  }<a name="line.115"></a>
+<span class="sourceLineNo">116</span><a name="line.116"></a>
+<span class="sourceLineNo">117</span>  private final ThreadLocal&lt;IndexHolder&gt; indexHolderThreadLocal =<a name="line.117"></a>
+<span class="sourceLineNo">118</span>      new ThreadLocal&lt;IndexHolder&gt;() {<a name="line.118"></a>
+<span class="sourceLineNo">119</span>    @Override<a name="line.119"></a>
+<span class="sourceLineNo">120</span>    protected IndexHolder initialValue() {<a name="line.120"></a>
+<span class="sourceLineNo">121</span>      return new IndexHolder();<a name="line.121"></a>
+<span class="sourceLineNo">122</span>    }<a name="line.122"></a>
+<span class="sourceLineNo">123</span>  };<a name="line.123"></a>
+<span class="sourceLineNo">124</span><a name="line.124"></a>
+<span class="sourceLineNo">125</span>  public void add(long delta) {<a name="line.125"></a>
+<span class="sourceLineNo">126</span>    Container container = containerRef.get();<a name="line.126"></a>
+<span class="sourceLineNo">127</span>    Cell[] cells = container.cells;<a name="line.127"></a>
+<span class="sourceLineNo">128</span>    int mask = cells.length - 1;<a name="line.128"></a>
+<span class="sourceLineNo">129</span><a name="line.129"></a>
+<span class="sourceLineNo">130</span>    IndexHolder indexHolder = indexHolderThreadLocal.get();<a name="line.130"></a>
+<span class="sourceLineNo">131</span>    int baseIndex = indexHolder.index;<a name="line.131"></a>
+<span class="sourceLineNo">132</span>    if(cells[baseIndex &amp; mask].add(delta)) {<a name="line.132"></a>
+<span class="sourceLineNo">133</span>      return;<a name="line.133"></a>
+<span class="sourceLineNo">134</span>    }<a name="line.134"></a>
+<span class="sourceLineNo">135</span><a name="line.135"></a>
+<span class="sourceLineNo">136</span>    int index = baseIndex + 1;<a name="line.136"></a>
+<span class="sourceLineNo">137</span>    while(true) {<a name="line.137"></a>
+<span class="sourceLineNo">138</span>      if(cells[index &amp; mask].add(delta)) {<a name="line.138"></a>
+<span class="sourceLineNo">139</span>        break;<a name="line.139"></a>
+<span class="sourceLineNo">140</span>      }<a name="line.140"></a>
+<span class="sourceLineNo">141</span>      index++;<a name="line.141"></a>
+<span class="sourceLineNo">142</span>    }<a name="line.142"></a>
 <span class="sourceLineNo">143</span><a name="line.143"></a>
-<span class="sourceLineNo">144</span>    if(index - baseIndex &gt;= cells.length &amp;&amp;<a name="line.144"></a>
-<span class="sourceLineNo">145</span>        cells.length &lt; MAX_CELLS_LENGTH &amp;&amp;<a name="line.145"></a>
-<span class="sourceLineNo">146</span>        container.demoted.compareAndSet(false, true)) {<a name="line.146"></a>
-<span class="sourceLineNo">147</span><a name="line.147"></a>
-<span class="sourceLineNo">148</span>      if(containerRef.get() == container) {<a name="line.148"></a>
-<span class="sourceLineNo">149</span>        Cell[] newCells = new Cell[cells.length * 2];<a name="line.149"></a>
-<span class="sourceLineNo">150</span>        System.arraycopy(cells, 0, newCells, 0, cells.length);<a name="line.150"></a>
-<span class="sourceLineNo">151</span>        for(int i = cells.length; i &lt; newCells.length; i++) {<a name="line.151"></a>
-<span class="sourceLineNo">152</span>          newCells[i] = new Cell();<a name="line.152"></a>
-<span class="sourceLineNo">153</span>          // Fill all of the elements with instances. Creating a cell on demand<a name="line.153"></a>
-<span class="sourceLineNo">154</span>          // and putting it into the array makes a concurrent problem about<a name="line.154"></a>
-<span class="sourceLineNo">155</span>          // visibility or, in other words, happens-before relation, because<a name="line.155"></a>
-<span class="sourceLineNo">156</span>          // each element of the array is not volatile so that you should<a name="line.156"></a>
-<span class="sourceLineNo">157</span>          // establish the relation by some piggybacking.<a name="line.157"></a>
-<span class="sourceLineNo">158</span>        }<a name="line.158"></a>
-<span class="sourceLineNo">159</span>        containerRef.compareAndSet(container, new Container(newCells));<a name="line.159"></a>
-<span class="sourceLineNo">160</span>      }<a name="line.160"></a>
-<span class="sourceLineNo">161</span>    }<a name="line.161"></a>
-<span class="sourceLineNo">162</span>  }<a name="line.162"></a>
-<span class="sourceLineNo">163</span><a name="line.163"></a>
-<span class="sourceLineNo">164</span>  public void increment() {<a name="line.164"></a>
-<span class="sourceLineNo">165</span>    add(1);<a name="line.165"></a>
-<span class="sourceLineNo">166</span>  }<a name="line.166"></a>
-<span class="sourceLineNo">167</span><a name="line.167"></a>
-<span class="sourceLineNo">168</span>  public void decrement() {<a name="line.168"></a>
-<span class="sourceLineNo">169</span>    add(-1);<a name="line.169"></a>
-<span class="sourceLineNo">170</span>  }<a name="line.170"></a>
-<span class="sourceLineNo">171</span><a name="line.171"></a>
-<span class="sourceLineNo">172</span>  public void set(long value) {<a name="line.172"></a>
-<span class="sourceLineNo">173</span>    containerRef.set(new Container(new Cell(value)));<a name="line.173"></a>
-<span class="sourceLineNo">174</span>  }<a name="line.174"></a>
-<span class="sourceLineNo">175</span><a name="line.175"></a>
-<span class="sourceLineNo">176</span>  public long get() {<a name="line.176"></a>
-<span class="sourceLineNo">177</span>    long sum = 0;<a name="line.177"></a>
-<span class="sourceLineNo">178</span>    for(Cell cell : containerRef.get().cells) {<a name="line.178"></a>
-<span class="sourceLineNo">179</span>      sum += cell.get();<a name="line.179"></a>
-<span class="sourceLineNo">180</span>    }<a name="line.180"></a>
-<span class="sourceLineNo">181</span>    return sum;<a name="line.181"></a>
-<span class="sourceLineNo">182</span>  }<a name="line.182"></a>
-<span class="sourceLineNo">183</span><a name="line.183"></a>
-<span class="sourceLineNo">184</span>  public void destroy() {<a name="line.184"></a>
-<span class="sourceLineNo">185</span>    indexHolderThreadLocal.remove();<a name="line.185"></a>
-<span class="sourceLineNo">186</span>  }<a name="line.186"></a>
-<span class="sourceLineNo">187</span><a name="line.187"></a>
-<span class="sourceLineNo">188</span>  @Override<a name="line.188"></a>
-<span class="sourceLineNo">189</span>  public String toString() {<a name="line.189"></a>
-<span class="sourceLineNo">190</span>    Cell[] cells = containerRef.get().cells;<a name="line.190"></a>
-<span class="sourceLineNo">191</span><a name="line.191"></a>
-<span class="sourceLineNo">192</span>    long min = Long.MAX_VALUE;<a name="line.192"></a>
-<span class="sourceLineNo">193</span>    long max = Long.MIN_VALUE;<a name="line.193"></a>
-<span class="sourceLineNo">194</span>    long sum = 0;<a name="line.194"></a>
-<span class="sourceLineNo">195</span><a name="line.195"></a>
-<span class="sourceLineNo">196</span>    for(Cell cell : cells) {<a name="line.196"></a>
-<span class="sourceLineNo">197</span>      long value = cell.get();<a name="line.197"></a>
-<span class="sourceLineNo">198</span>      sum += value;<a name="line.198"></a>
-<span class="sourceLineNo">199</span>      if(min &gt; value) { min = value; }<a name="line.199"></a>
-<span class="sourceLineNo">200</span>      if(max &lt; value) { max = value; }<a name="line.200"></a>
-<span class="sourceLineNo">201</span>    }<a name="line.201"></a>
-<span class="sourceLineNo">202</span><a name="line.202"></a>
-<span class="sourceLineNo">203</span>    return new StringBuilder(100)<a name="line.203"></a>
-<span class="sourceLineNo">204</span>    .append("[value=").append(sum)<a name="line.204"></a>
-<span class="sourceLineNo">205</span>    .append(", cells=[length=").append(cells.length)<a name="line.205"></a>
-<span class="sourceLineNo">206</span>    .append(", min=").append(min)<a name="line.206"></a>
-<span class="sourceLineNo">207</span>    .append(", max=").append(max)<a name="line.207"></a>
-<span class="sourceLineNo">208</span>    .append("]]").toString();<a name="line.208"></a>
-<span class="sourceLineNo">209</span>  }<a name="line.209"></a>
-<span class="sourceLineNo">210</span>}<a name="line.210"></a>
+<span class="sourceLineNo">144</span>    indexHolder.index = index;<a name="line.144"></a>
+<span class="sourceLineNo">145</span><a name="line.145"></a>
+<span class="sourceLineNo">146</span>    if(index - baseIndex &gt;= cells.length &amp;&amp;<a name="line.146"></a>
+<span class="sourceLineNo">147</span>        cells.length &lt; MAX_CELLS_LENGTH &amp;&amp;<a name="line.147"></a>
+<span class="sourceLineNo">148</span>        container.demoted.compareAndSet(false, true)) {<a name="line.148"></a>
+<span class="sourceLineNo">149</span><a name="line.149"></a>
+<span class="sourceLineNo">150</span>      if(containerRef.get() == container) {<a name="line.150"></a>
+<span class="sourceLineNo">151</span>        Cell[] newCells = new Cell[cells.length * 2];<a name="line.151"></a>
+<span class="sourceLineNo">152</span>        System.arraycopy(cells, 0, newCells, 0, cells.length);<a name="line.152"></a>
+<span class="sourceLineNo">153</span>        for(int i = cells.length; i &lt; newCells.length; i++) {<a name="line.153"></a>
+<span class="sourceLineNo">154</span>          newCells[i] = new Cell();<a name="line.154"></a>
+<span class="sourceLineNo">155</span>          // Fill all of the elements with instances. Creating a cell on demand<a name="line.155"></a>
+<span class="sourceLineNo">156</span>          // and putting it into the array makes a concurrent problem about<a name="line.156"></a>
+<span class="sourceLineNo">157</span>          // visibility or, in other words, happens-before relation, because<a name="line.157"></a>
+<span class="sourceLineNo">158</span>          // each element of the array is not volatile so that you should<a name="line.158"></a>
+<span class="sourceLineNo">159</span>          // establish the relation by some piggybacking.<a name="line.159"></a>
+<span class="sourceLineNo">160</span>        }<a name="line.160"></a>
+<span class="sourceLineNo">161</span>        containerRef.compareAndSet(container, new Container(newCells));<a name="line.161"></a>
+<span class="sourceLineNo">162</span>      }<a name="line.162"></a>
+<span class="sourceLineNo">163</span>    }<a name="line.163"></a>
+<span class="sourceLineNo">164</span>  }<a name="line.164"></a>
+<span class="sourceLineNo">165</span><a name="line.165"></a>
+<span class="sourceLineNo">166</span>  public void increment() {<a name="line.166"></a>
+<span class="sourceLineNo">167</span>    add(1);<a name="line.167"></a>
+<span class="sourceLineNo">168</span>  }<a name="line.168"></a>
+<span class="sourceLineNo">169</span><a name="line.169"></a>
+<span class="sourceLineNo">170</span>  public void decrement() {<a name="line.170"></a>
+<span class="sourceLineNo">171</span>    add(-1);<a name="line.171"></a>
+<span class="sourceLineNo">172</span>  }<a name="line.172"></a>
+<span class="sourceLineNo">173</span><a name="line.173"></a>
+<span class="sourceLineNo">174</span>  public void set(long value) {<a name="line.174"></a>
+<span class="sourceLineNo">175</span>    containerRef.set(new Container(new Cell(value)));<a name="line.175"></a>
+<span class="sourceLineNo">176</span>  }<a name="line.176"></a>
+<span class="sourceLineNo">177</span><a name="line.177"></a>
+<span class="sourceLineNo">178</span>  public long get() {<a name="line.178"></a>
+<span class="sourceLineNo">179</span>    long sum = 0;<a name="line.179"></a>
+<span class="sourceLineNo">180</span>    for(Cell cell : containerRef.get().cells) {<a name="line.180"></a>
+<span class="sourceLineNo">181</span>      sum += cell.get();<a name="line.181"></a>
+<span class="sourceLineNo">182</span>    }<a name="line.182"></a>
+<span class="sourceLineNo">183</span>    return sum;<a name="line.183"></a>
+<span class="sourceLineNo">184</span>  }<a name="line.184"></a>
+<span class="sourceLineNo">185</span><a name="line.185"></a>
+<span class="sourceLineNo">186</span>  public void destroy() {<a name="line.186"></a>
+<span class="sourceLineNo">187</span>    indexHolderThreadLocal.remove();<a name="line.187"></a>
+<span class="sourceLineNo">188</span>  }<a name="line.188"></a>
+<span class="sourceLineNo">189</span><a name="line.189"></a>
+<span class="sourceLineNo">190</span>  @Override<a name="line.190"></a>
+<span class="sourceLineNo">191</span>  public String toString() {<a name="line.191"></a>
+<span class="sourceLineNo">192</span>    Cell[] cells = containerRef.get().cells;<a name="line.192"></a>
+<span class="sourceLineNo">193</span><a name="line.193"></a>
+<span class="sourceLineNo">194</span>    long min = Long.MAX_VALUE;<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    long max = Long.MIN_VALUE;<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    long sum = 0;<a name="line.196"></a>
+<span class="sourceLineNo">197</span><a name="line.197"></a>
+<span class="sourceLineNo">198</span>    for(Cell cell : cells) {<a name="line.198"></a>
+<span class="sourceLineNo">199</span>      long value = cell.get();<a name="line.199"></a>
+<span class="sourceLineNo">200</span>      sum += value;<a name="line.200"></a>
+<span class="sourceLineNo">201</span>      if(min &gt; value) { min = value; }<a name="line.201"></a>
+<span class="sourceLineNo">202</span>      if(max &lt; value) { max = value; }<a name="line.202"></a>
+<span class="sourceLineNo">203</span>    }<a name="line.203"></a>
+<span class="sourceLineNo">204</span><a name="line.204"></a>
+<span class="sourceLineNo">205</span>    return new StringBuilder(100)<a name="line.205"></a>
+<span class="sourceLineNo">206</span>    .append("[value=").append(sum)<a name="line.206"></a>
+<span class="sourceLineNo">207</span>    .append(", cells=[length=").append(cells.length)<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    .append(", min=").append(min)<a name="line.208"></a>
+<span class="sourceLineNo">209</span>    .append(", max=").append(max)<a name="line.209"></a>
+<span class="sourceLineNo">210</span>    .append("]]").toString();<a name="line.210"></a>
+<span class="sourceLineNo">211</span>  }<a name="line.211"></a>
+<span class="sourceLineNo">212</span>}<a name="line.212"></a>
 
 
 

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/044b3379/apidocs/src-html/org/apache/hadoop/hbase/util/FastLongHistogram.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/util/FastLongHistogram.html b/apidocs/src-html/org/apache/hadoop/hbase/util/FastLongHistogram.html
index c9ecead..7778113 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/util/FastLongHistogram.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/util/FastLongHistogram.html
@@ -25,305 +25,297 @@
 <span class="sourceLineNo">017</span> */<a name="line.17"></a>
 <span class="sourceLineNo">018</span>package org.apache.hadoop.hbase.util;<a name="line.18"></a>
 <span class="sourceLineNo">019</span><a name="line.19"></a>
-<span class="sourceLineNo">020</span>import java.util.concurrent.atomic.AtomicBoolean;<a name="line.20"></a>
+<span class="sourceLineNo">020</span>import java.util.Arrays;<a name="line.20"></a>
 <span class="sourceLineNo">021</span>import java.util.concurrent.atomic.AtomicLong;<a name="line.21"></a>
-<span class="sourceLineNo">022</span><a name="line.22"></a>
-<span class="sourceLineNo">023</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.23"></a>
-<span class="sourceLineNo">024</span>import org.apache.hadoop.hbase.classification.InterfaceStability;<a name="line.24"></a>
-<span class="sourceLineNo">025</span><a name="line.25"></a>
-<span class="sourceLineNo">026</span>/**<a name="line.26"></a>
-<span class="sourceLineNo">027</span> * FastLongHistogram is a thread-safe class that estimate distribution of data and computes the<a name="line.27"></a>
-<span class="sourceLineNo">028</span> * quantiles.<a name="line.28"></a>
-<span class="sourceLineNo">029</span> */<a name="line.29"></a>
-<span class="sourceLineNo">030</span>@InterfaceAudience.Public<a name="line.30"></a>
-<span class="sourceLineNo">031</span>@InterfaceStability.Evolving<a name="line.31"></a>
-<span class="sourceLineNo">032</span>public class FastLongHistogram {<a name="line.32"></a>
-<span class="sourceLineNo">033</span><a name="line.33"></a>
-<span class="sourceLineNo">034</span>  /**<a name="line.34"></a>
-<span class="sourceLineNo">035</span>   * Default number of bins.<a name="line.35"></a>
-<span class="sourceLineNo">036</span>   */<a name="line.36"></a>
-<span class="sourceLineNo">037</span>  public static final int DEFAULT_NBINS = 255;<a name="line.37"></a>
-<span class="sourceLineNo">038</span><a name="line.38"></a>
-<span class="sourceLineNo">039</span>  public static final double[] DEFAULT_QUANTILES =<a name="line.39"></a>
-<span class="sourceLineNo">040</span>      new double[]{0.25, 0.5, 0.75, 0.90, 0.95, 0.98, 0.99, 0.999};<a name="line.40"></a>
-<span class="sourceLineNo">041</span><a name="line.41"></a>
-<span class="sourceLineNo">042</span>  /**<a name="line.42"></a>
-<span class="sourceLineNo">043</span>   * Bins is a class containing a list of buckets(or bins) for estimation histogram of some data.<a name="line.43"></a>
-<span class="sourceLineNo">044</span>   */<a name="line.44"></a>
-<span class="sourceLineNo">045</span>  private static class Bins {<a name="line.45"></a>
-<span class="sourceLineNo">046</span>    private final Counter[] counts;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>    // inclusive<a name="line.47"></a>
-<span class="sourceLineNo">048</span>    private final long binsMin;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>    // exclusive<a name="line.49"></a>
-<span class="sourceLineNo">050</span>    private final long binsMax;<a name="line.50"></a>
-<span class="sourceLineNo">051</span>    private final long bins10XMax;<a name="line.51"></a>
-<span class="sourceLineNo">052</span>    private final AtomicLong min = new AtomicLong(Long.MAX_VALUE);<a name="line.52"></a>
-<span class="sourceLineNo">053</span>    private final AtomicLong max = new AtomicLong(0L);<a name="line.53"></a>
-<span class="sourceLineNo">054</span><a name="line.54"></a>
-<span class="sourceLineNo">055</span>    private final Counter count = new Counter(0);<a name="line.55"></a>
-<span class="sourceLineNo">056</span>    private final Counter total = new Counter(0);<a name="line.56"></a>
-<span class="sourceLineNo">057</span><a name="line.57"></a>
-<span class="sourceLineNo">058</span>    // set to true when any of data has been inserted to the Bins. It is set after the counts are<a name="line.58"></a>
-<span class="sourceLineNo">059</span>    // updated.<a name="line.59"></a>
-<span class="sourceLineNo">060</span>    private final AtomicBoolean hasData = new AtomicBoolean(false);<a name="line.60"></a>
-<span class="sourceLineNo">061</span><a name="line.61"></a>
-<span class="sourceLineNo">062</span>    /**<a name="line.62"></a>
-<span class="sourceLineNo">063</span>     * The constructor for creating a Bins without any prior data.<a name="line.63"></a>
-<span class="sourceLineNo">064</span>     */<a name="line.64"></a>
-<span class="sourceLineNo">065</span>    public Bins(int numBins) {<a name="line.65"></a>
-<span class="sourceLineNo">066</span>      counts = createCounters(numBins + 3);<a name="line.66"></a>
-<span class="sourceLineNo">067</span>      this.binsMin = 1L;<a name="line.67"></a>
-<span class="sourceLineNo">068</span><a name="line.68"></a>
-<span class="sourceLineNo">069</span>      // These two numbers are total guesses<a name="line.69"></a>
-<span class="sourceLineNo">070</span>      // and should be treated as highly suspect.<a name="line.70"></a>
-<span class="sourceLineNo">071</span>      this.binsMax = 1000;<a name="line.71"></a>
-<span class="sourceLineNo">072</span>      this.bins10XMax = binsMax * 10;<a name="line.72"></a>
-<span class="sourceLineNo">073</span>    }<a name="line.73"></a>
-<span class="sourceLineNo">074</span><a name="line.74"></a>
-<span class="sourceLineNo">075</span>    /**<a name="line.75"></a>
-<span class="sourceLineNo">076</span>     * The constructor for creating a Bins with last Bins.<a name="line.76"></a>
-<span class="sourceLineNo">077</span>     */<a name="line.77"></a>
-<span class="sourceLineNo">078</span>    public Bins(Bins last, int numOfBins, double minQ, double maxQ) {<a name="line.78"></a>
-<span class="sourceLineNo">079</span>      long[] values = last.getQuantiles(new double[] { minQ, maxQ });<a name="line.79"></a>
-<span class="sourceLineNo">080</span>      long wd = values[1] - values[0] + 1;<a name="line.80"></a>
-<span class="sourceLineNo">081</span>      // expand minQ and maxQ in two ends back assuming uniform distribution<a name="line.81"></a>
-<span class="sourceLineNo">082</span>      this.binsMin = Math.max(0L, (long) (values[0] - wd * minQ));<a name="line.82"></a>
-<span class="sourceLineNo">083</span>      long binsMax = (long) (values[1] + wd * (1 - maxQ)) + 1;<a name="line.83"></a>
-<span class="sourceLineNo">084</span>      // make sure each of bins is at least of width 1<a name="line.84"></a>
-<span class="sourceLineNo">085</span>      this.binsMax = Math.max(binsMax, this.binsMin + numOfBins);<a name="line.85"></a>
-<span class="sourceLineNo">086</span>      this.bins10XMax = Math.max((long) (values[1] + (binsMax - 1) * 9), this.binsMax + 1);<a name="line.86"></a>
-<span class="sourceLineNo">087</span><a name="line.87"></a>
-<span class="sourceLineNo">088</span>      this.counts = createCounters(numOfBins + 3);<a name="line.88"></a>
-<span class="sourceLineNo">089</span>    }<a name="line.89"></a>
-<span class="sourceLineNo">090</span><a name="line.90"></a>
-<span class="sourceLineNo">091</span>    private Counter[] createCounters(int num) {<a name="line.91"></a>
-<span class="sourceLineNo">092</span>      Counter[] counters = new Counter[num];<a name="line.92"></a>
-<span class="sourceLineNo">093</span>      for (int i = 0; i &lt; num; i++) {<a name="line.93"></a>
-<span class="sourceLineNo">094</span>        counters[i] = new Counter();<a name="line.94"></a>
-<span class="sourceLineNo">095</span>      }<a name="line.95"></a>
-<span class="sourceLineNo">096</span>      return counters;<a name="line.96"></a>
-<span class="sourceLineNo">097</span>    }<a name="line.97"></a>
-<span class="sourceLineNo">098</span><a name="line.98"></a>
-<span class="sourceLineNo">099</span>    private int getIndex(long value) {<a name="line.99"></a>
-<span class="sourceLineNo">100</span>      if (value &lt; this.binsMin) {<a name="line.100"></a>
-<span class="sourceLineNo">101</span>        return 0;<a name="line.101"></a>
-<span class="sourceLineNo">102</span>      } else if (value &gt; this.bins10XMax) {<a name="line.102"></a>
-<span class="sourceLineNo">103</span>        return this.counts.length - 1;<a name="line.103"></a>
-<span class="sourceLineNo">104</span>      } else if (value &gt;= this.binsMax) {<a name="line.104"></a>
-<span class="sourceLineNo">105</span>        return this.counts.length - 2;<a name="line.105"></a>
-<span class="sourceLineNo">106</span>      }<a name="line.106"></a>
-<span class="sourceLineNo">107</span>      // compute the position<a name="line.107"></a>
-<span class="sourceLineNo">108</span>      return 1 + (int) ((value - this.binsMin) * (this.counts.length - 3) /<a name="line.108"></a>
-<span class="sourceLineNo">109</span>          (this.binsMax - this.binsMin));<a name="line.109"></a>
+<span class="sourceLineNo">022</span>import java.util.concurrent.atomic.LongAdder;<a name="line.22"></a>
+<span class="sourceLineNo">023</span>import java.util.stream.Stream;<a name="line.23"></a>
+<span class="sourceLineNo">024</span><a name="line.24"></a>
+<span class="sourceLineNo">025</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import org.apache.hadoop.hbase.classification.InterfaceStability;<a name="line.26"></a>
+<span class="sourceLineNo">027</span><a name="line.27"></a>
+<span class="sourceLineNo">028</span>/**<a name="line.28"></a>
+<span class="sourceLineNo">029</span> * FastLongHistogram is a thread-safe class that estimate distribution of data and computes the<a name="line.29"></a>
+<span class="sourceLineNo">030</span> * quantiles.<a name="line.30"></a>
+<span class="sourceLineNo">031</span> */<a name="line.31"></a>
+<span class="sourceLineNo">032</span>@InterfaceAudience.Public<a name="line.32"></a>
+<span class="sourceLineNo">033</span>@InterfaceStability.Evolving<a name="line.33"></a>
+<span class="sourceLineNo">034</span>public class FastLongHistogram {<a name="line.34"></a>
+<span class="sourceLineNo">035</span><a name="line.35"></a>
+<span class="sourceLineNo">036</span>  /**<a name="line.36"></a>
+<span class="sourceLineNo">037</span>   * Default number of bins.<a name="line.37"></a>
+<span class="sourceLineNo">038</span>   */<a name="line.38"></a>
+<span class="sourceLineNo">039</span>  public static final int DEFAULT_NBINS = 255;<a name="line.39"></a>
+<span class="sourceLineNo">040</span><a name="line.40"></a>
+<span class="sourceLineNo">041</span>  public static final double[] DEFAULT_QUANTILES =<a name="line.41"></a>
+<span class="sourceLineNo">042</span>      new double[]{0.25, 0.5, 0.75, 0.90, 0.95, 0.98, 0.99, 0.999};<a name="line.42"></a>
+<span class="sourceLineNo">043</span><a name="line.43"></a>
+<span class="sourceLineNo">044</span>  /**<a name="line.44"></a>
+<span class="sourceLineNo">045</span>   * Bins is a class containing a list of buckets(or bins) for estimation histogram of some data.<a name="line.45"></a>
+<span class="sourceLineNo">046</span>   */<a name="line.46"></a>
+<span class="sourceLineNo">047</span>  private static class Bins {<a name="line.47"></a>
+<span class="sourceLineNo">048</span>    private final LongAdder[] counts;<a name="line.48"></a>
+<span class="sourceLineNo">049</span>    // inclusive<a name="line.49"></a>
+<span class="sourceLineNo">050</span>    private final long binsMin;<a name="line.50"></a>
+<span class="sourceLineNo">051</span>    // exclusive<a name="line.51"></a>
+<span class="sourceLineNo">052</span>    private final long binsMax;<a name="line.52"></a>
+<span class="sourceLineNo">053</span>    private final long bins10XMax;<a name="line.53"></a>
+<span class="sourceLineNo">054</span>    private final AtomicLong min = new AtomicLong(Long.MAX_VALUE);<a name="line.54"></a>
+<span class="sourceLineNo">055</span>    private final AtomicLong max = new AtomicLong(0L);<a name="line.55"></a>
+<span class="sourceLineNo">056</span><a name="line.56"></a>
+<span class="sourceLineNo">057</span>    private final LongAdder count = new LongAdder();<a name="line.57"></a>
+<span class="sourceLineNo">058</span>    private final LongAdder total = new LongAdder();<a name="line.58"></a>
+<span class="sourceLineNo">059</span><a name="line.59"></a>
+<span class="sourceLineNo">060</span>    // set to true when any of data has been inserted to the Bins. It is set after the counts are<a name="line.60"></a>
+<span class="sourceLineNo">061</span>    // updated.<a name="line.61"></a>
+<span class="sourceLineNo">062</span>    private volatile boolean hasData = false;<a name="line.62"></a>
+<span class="sourceLineNo">063</span><a name="line.63"></a>
+<span class="sourceLineNo">064</span>    /**<a name="line.64"></a>
+<span class="sourceLineNo">065</span>     * The constructor for creating a Bins without any prior data.<a name="line.65"></a>
+<span class="sourceLineNo">066</span>     */<a name="line.66"></a>
+<span class="sourceLineNo">067</span>    public Bins(int numBins) {<a name="line.67"></a>
+<span class="sourceLineNo">068</span>      counts = createCounters(numBins);<a name="line.68"></a>
+<span class="sourceLineNo">069</span>      this.binsMin = 1L;<a name="line.69"></a>
+<span class="sourceLineNo">070</span><a name="line.70"></a>
+<span class="sourceLineNo">071</span>      // These two numbers are total guesses<a name="line.71"></a>
+<span class="sourceLineNo">072</span>      // and should be treated as highly suspect.<a name="line.72"></a>
+<span class="sourceLineNo">073</span>      this.binsMax = 1000;<a name="line.73"></a>
+<span class="sourceLineNo">074</span>      this.bins10XMax = binsMax * 10;<a name="line.74"></a>
+<span class="sourceLineNo">075</span>    }<a name="line.75"></a>
+<span class="sourceLineNo">076</span><a name="line.76"></a>
+<span class="sourceLineNo">077</span>    /**<a name="line.77"></a>
+<span class="sourceLineNo">078</span>     * The constructor for creating a Bins with last Bins.<a name="line.78"></a>
+<span class="sourceLineNo">079</span>     */<a name="line.79"></a>
+<span class="sourceLineNo">080</span>    public Bins(Bins last, int numBins, double minQ, double maxQ) {<a name="line.80"></a>
+<span class="sourceLineNo">081</span>      long[] values = last.getQuantiles(new double[] { minQ, maxQ });<a name="line.81"></a>
+<span class="sourceLineNo">082</span>      long wd = values[1] - values[0] + 1;<a name="line.82"></a>
+<span class="sourceLineNo">083</span>      // expand minQ and maxQ in two ends back assuming uniform distribution<a name="line.83"></a>
+<span class="sourceLineNo">084</span>      this.binsMin = Math.max(0L, (long) (values[0] - wd * minQ));<a name="line.84"></a>
+<span class="sourceLineNo">085</span>      long binsMax = (long) (values[1] + wd * (1 - maxQ)) + 1;<a name="line.85"></a>
+<span class="sourceLineNo">086</span>      // make sure each of bins is at least of width 1<a name="line.86"></a>
+<span class="sourceLineNo">087</span>      this.binsMax = Math.max(binsMax, this.binsMin + numBins);<a name="line.87"></a>
+<span class="sourceLineNo">088</span>      this.bins10XMax = Math.max((long) (values[1] + (binsMax - 1) * 9), this.binsMax + 1);<a name="line.88"></a>
+<span class="sourceLineNo">089</span><a name="line.89"></a>
+<span class="sourceLineNo">090</span>      this.counts = createCounters(numBins);<a name="line.90"></a>
+<span class="sourceLineNo">091</span>    }<a name="line.91"></a>
+<span class="sourceLineNo">092</span><a name="line.92"></a>
+<span class="sourceLineNo">093</span>    private LongAdder[] createCounters(int numBins) {<a name="line.93"></a>
+<span class="sourceLineNo">094</span>      return Stream.generate(LongAdder::new).limit(numBins + 3).toArray(LongAdder[]::new);<a name="line.94"></a>
+<span class="sourceLineNo">095</span>    }<a name="line.95"></a>
+<span class="sourceLineNo">096</span><a name="line.96"></a>
+<span class="sourceLineNo">097</span>    private int getIndex(long value) {<a name="line.97"></a>
+<span class="sourceLineNo">098</span>      if (value &lt; this.binsMin) {<a name="line.98"></a>
+<span class="sourceLineNo">099</span>        return 0;<a name="line.99"></a>
+<span class="sourceLineNo">100</span>      } else if (value &gt; this.bins10XMax) {<a name="line.100"></a>
+<span class="sourceLineNo">101</span>        return this.counts.length - 1;<a name="line.101"></a>
+<span class="sourceLineNo">102</span>      } else if (value &gt;= this.binsMax) {<a name="line.102"></a>
+<span class="sourceLineNo">103</span>        return this.counts.length - 2;<a name="line.103"></a>
+<span class="sourceLineNo">104</span>      }<a name="line.104"></a>
+<span class="sourceLineNo">105</span>      // compute the position<a name="line.105"></a>
+<span class="sourceLineNo">106</span>      return 1 + (int) ((value - this.binsMin) * (this.counts.length - 3) /<a name="line.106"></a>
+<span class="sourceLineNo">107</span>          (this.binsMax - this.binsMin));<a name="line.107"></a>
+<span class="sourceLineNo">108</span><a name="line.108"></a>
+<span class="sourceLineNo">109</span>    }<a name="line.109"></a>
 <span class="sourceLineNo">110</span><a name="line.110"></a>
-<span class="sourceLineNo">111</span>    }<a name="line.111"></a>
-<span class="sourceLineNo">112</span><a name="line.112"></a>
-<span class="sourceLineNo">113</span>    /**<a name="line.113"></a>
-<span class="sourceLineNo">114</span>     * Adds a value to the histogram.<a name="line.114"></a>
-<span class="sourceLineNo">115</span>     */<a name="line.115"></a>
-<span class="sourceLineNo">116</span>    public void add(long value, long count) {<a name="line.116"></a>
-<span class="sourceLineNo">117</span>      if (value &lt; 0) {<a name="line.117"></a>
-<span class="sourceLineNo">118</span>        // The whole computation is completely thrown off if there are negative numbers<a name="line.118"></a>
-<span class="sourceLineNo">119</span>        //<a name="line.119"></a>
-<span class="sourceLineNo">120</span>        // Normally we would throw an IllegalArgumentException however this is the metrics<a name="line.120"></a>
-<span class="sourceLineNo">121</span>        // system and it should be completely safe at all times.<a name="line.121"></a>
-<span class="sourceLineNo">122</span>        // So silently throw it away.<a name="line.122"></a>
-<span class="sourceLineNo">123</span>        return;<a name="line.123"></a>
-<span class="sourceLineNo">124</span>      }<a name="line.124"></a>
-<span class="sourceLineNo">125</span>      AtomicUtils.updateMin(min, value);<a name="line.125"></a>
-<span class="sourceLineNo">126</span>      AtomicUtils.updateMax(max, value);<a name="line.126"></a>
-<span class="sourceLineNo">127</span><a name="line.127"></a>
-<span class="sourceLineNo">128</span>      this.count.add(count);<a name="line.128"></a>
-<span class="sourceLineNo">129</span>      this.total.add(value * count);<a name="line.129"></a>
-<span class="sourceLineNo">130</span><a name="line.130"></a>
-<span class="sourceLineNo">131</span>      int pos = getIndex(value);<a name="line.131"></a>
-<span class="sourceLineNo">132</span>      this.counts[pos].add(count);<a name="line.132"></a>
-<span class="sourceLineNo">133</span><a name="line.133"></a>
-<span class="sourceLineNo">134</span>      // hasData needs to be updated as last<a name="line.134"></a>
-<span class="sourceLineNo">135</span>      this.hasData.set(true);<a name="line.135"></a>
-<span class="sourceLineNo">136</span>    }<a name="line.136"></a>
-<span class="sourceLineNo">137</span><a name="line.137"></a>
-<span class="sourceLineNo">138</span>    /**<a name="line.138"></a>
-<span class="sourceLineNo">139</span>     * Computes the quantiles give the ratios.<a name="line.139"></a>
-<span class="sourceLineNo">140</span>     */<a name="line.140"></a>
-<span class="sourceLineNo">141</span>    public long[] getQuantiles(double[] quantiles) {<a name="line.141"></a>
-<span class="sourceLineNo">142</span>      if (!this.hasData.get()) {<a name="line.142"></a>
-<span class="sourceLineNo">143</span>        // No data yet.<a name="line.143"></a>
-<span class="sourceLineNo">144</span>        return new long[quantiles.length];<a name="line.144"></a>
-<span class="sourceLineNo">145</span>      }<a name="line.145"></a>
-<span class="sourceLineNo">146</span><a name="line.146"></a>
-<span class="sourceLineNo">147</span>      // Make a snapshot of lowerCounter, higherCounter and bins.counts to counts.<a name="line.147"></a>
-<span class="sourceLineNo">148</span>      // This is not synchronized, but since the counter are accumulating, the result is a good<a name="line.148"></a>
-<span class="sourceLineNo">149</span>      // estimation of a snapshot.<a name="line.149"></a>
-<span class="sourceLineNo">150</span>      long[] counts = new long[this.counts.length];<a name="line.150"></a>
-<span class="sourceLineNo">151</span>      long total = 0L;<a name="line.151"></a>
-<span class="sourceLineNo">152</span>      for (int i = 0; i &lt; this.counts.length; i++) {<a name="line.152"></a>
-<span class="sourceLineNo">153</span>        counts[i] = this.counts[i].get();<a name="line.153"></a>
-<span class="sourceLineNo">154</span>        total += counts[i];<a name="line.154"></a>
-<span class="sourceLineNo">155</span>      }<a name="line.155"></a>
-<span class="sourceLineNo">156</span><a name="line.156"></a>
-<span class="sourceLineNo">157</span>      int rIndex = 0;<a name="line.157"></a>
-<span class="sourceLineNo">158</span>      double qCount = total * quantiles[0];<a name="line.158"></a>
-<span class="sourceLineNo">159</span>      long cum = 0L;<a name="line.159"></a>
-<span class="sourceLineNo">160</span><a name="line.160"></a>
-<span class="sourceLineNo">161</span>      long[] res = new long[quantiles.length];<a name="line.161"></a>
-<span class="sourceLineNo">162</span>      countsLoop: for (int i = 0; i &lt; counts.length; i++) {<a name="line.162"></a>
-<span class="sourceLineNo">163</span>        // mn and mx define a value range<a name="line.163"></a>
-<span class="sourceLineNo">164</span>        long mn, mx;<a name="line.164"></a>
-<span class="sourceLineNo">165</span>        if (i == 0) {<a name="line.165"></a>
-<span class="sourceLineNo">166</span>          mn = this.min.get();<a name="line.166"></a>
-<span class="sourceLineNo">167</span>          mx = this.binsMin;<a name="line.167"></a>
-<span class="sourceLineNo">168</span>        } else if (i == counts.length - 1) {<a name="line.168"></a>
-<span class="sourceLineNo">169</span>          mn = this.bins10XMax;<a name="line.169"></a>
-<span class="sourceLineNo">170</span>          mx = this.max.get();<a name="line.170"></a>
-<span class="sourceLineNo">171</span>        } else if (i == counts.length - 2) {<a name="line.171"></a>
-<span class="sourceLineNo">172</span>          mn = this.binsMax;<a name="line.172"></a>
-<span class="sourceLineNo">173</span>          mx = this.bins10XMax;<a name="line.173"></a>
-<span class="sourceLineNo">174</span>        } else {<a name="line.174"></a>
-<span class="sourceLineNo">175</span>          mn = this.binsMin + (i - 1) * (this.binsMax - this.binsMin) / (this.counts.length - 3);<a name="line.175"></a>
-<span class="sourceLineNo">176</span>          mx = this.binsMin + i * (this.binsMax - this.binsMin) / (this.counts.length - 3);<a name="line.176"></a>
-<span class="sourceLineNo">177</span>        }<a name="line.177"></a>
-<span class="sourceLineNo">178</span><a name="line.178"></a>
-<span class="sourceLineNo">179</span>        if (mx &lt; this.min.get()) {<a name="line.179"></a>
-<span class="sourceLineNo">180</span>          continue;<a name="line.180"></a>
-<span class="sourceLineNo">181</span>        }<a name="line.181"></a>
-<span class="sourceLineNo">182</span>        if (mn &gt; this.max.get()) {<a name="line.182"></a>
-<span class="sourceLineNo">183</span>          break;<a name="line.183"></a>
-<span class="sourceLineNo">184</span>        }<a name="line.184"></a>
-<span class="sourceLineNo">185</span>        mn = Math.max(mn, this.min.get());<a name="line.185"></a>
-<span class="sourceLineNo">186</span>        mx = Math.min(mx, this.max.get());<a name="line.186"></a>
-<span class="sourceLineNo">187</span><a name="line.187"></a>
-<span class="sourceLineNo">188</span>        // lastCum/cum are the corresponding counts to mn/mx<a name="line.188"></a>
-<span class="sourceLineNo">189</span>        double lastCum = cum;<a name="line.189"></a>
-<span class="sourceLineNo">190</span>        cum += counts[i];<a name="line.190"></a>
-<span class="sourceLineNo">191</span><a name="line.191"></a>
-<span class="sourceLineNo">192</span>        // fill the results for qCount is within current range.<a name="line.192"></a>
-<span class="sourceLineNo">193</span>        while (qCount &lt;= cum) {<a name="line.193"></a>
-<span class="sourceLineNo">194</span>          if (cum == lastCum) {<a name="line.194"></a>
-<span class="sourceLineNo">195</span>            res[rIndex] = mn;<a name="line.195"></a>
-<span class="sourceLineNo">196</span>          } else {<a name="line.196"></a>
-<span class="sourceLineNo">197</span>            res[rIndex] = (long) ((qCount - lastCum) * (mx - mn) / (cum - lastCum) + mn);<a name="line.197"></a>
-<span class="sourceLineNo">198</span>          }<a name="line.198"></a>
-<span class="sourceLineNo">199</span><a name="line.199"></a>
-<span class="sourceLineNo">200</span>          // move to next quantile<a name="line.200"></a>
-<span class="sourceLineNo">201</span>          rIndex++;<a name="line.201"></a>
-<span class="sourceLineNo">202</span>          if (rIndex &gt;= quantiles.length) {<a name="line.202"></a>
-<span class="sourceLineNo">203</span>            break countsLoop;<a name="line.203"></a>
-<span class="sourceLineNo">204</span>          }<a name="line.204"></a>
-<span class="sourceLineNo">205</span>          qCount = total * quantiles[rIndex];<a name="line.205"></a>
-<span class="sourceLineNo">206</span>        }<a name="line.206"></a>
-<span class="sourceLineNo">207</span>      }<a name="line.207"></a>
-<span class="sourceLineNo">208</span>      // In case quantiles contains values &gt;= 100%<a name="line.208"></a>
-<span class="sourceLineNo">209</span>      for (; rIndex &lt; quantiles.length; rIndex++) {<a name="line.209"></a>
-<span class="sourceLineNo">210</span>        res[rIndex] = this.max.get();<a name="line.210"></a>
-<span class="sourceLineNo">211</span>      }<a name="line.211"></a>
-<span class="sourceLineNo">212</span><a name="line.212"></a>
-<span class="sourceLineNo">213</span>      return res;<a name="line.213"></a>
-<span class="sourceLineNo">214</span>    }<a name="line.214"></a>
-<span class="sourceLineNo">215</span><a name="line.215"></a>
-<span class="sourceLineNo">216</span><a name="line.216"></a>
-<span class="sourceLineNo">217</span>    long getNumAtOrBelow(long val) {<a name="line.217"></a>
-<span class="sourceLineNo">218</span>      final int targetIndex = getIndex(val);<a name="line.218"></a>
-<span class="sourceLineNo">219</span>      long totalToCurrentIndex = 0;<a name="line.219"></a>
-<span class="sourceLineNo">220</span>      for (int i = 0; i &lt;= targetIndex; i++) {<a name="line.220"></a>
-<span class="sourceLineNo">221</span>        totalToCurrentIndex += this.counts[i].get();<a name="line.221"></a>
-<span class="sourceLineNo">222</span>      }<a name="line.222"></a>
-<span class="sourceLineNo">223</span>      return  totalToCurrentIndex;<a name="line.223"></a>
-<span class="sourceLineNo">224</span>    }<a name="line.224"></a>
-<span class="sourceLineNo">225</span>  }<a name="line.225"></a>
-<span class="sourceLineNo">226</span><a name="line.226"></a>
-<span class="sourceLineNo">227</span>  // The bins counting values. It is replaced with a new one in calling of reset().<a name="line.227"></a>
-<span class="sourceLineNo">228</span>  private volatile Bins bins;<a name="line.228"></a>
-<span class="sourceLineNo">229</span><a name="line.229"></a>
-<span class="sourceLineNo">230</span>  /**<a name="line.230"></a>
-<span class="sourceLineNo">231</span>   * Constructor.<a name="line.231"></a>
-<span class="sourceLineNo">232</span>   */<a name="line.232"></a>
-<span class="sourceLineNo">233</span>  public FastLongHistogram() {<a name="line.233"></a>
-<span class="sourceLineNo">234</span>    this(DEFAULT_NBINS);<a name="line.234"></a>
-<span class="sourceLineNo">235</span>  }<a name="line.235"></a>
-<span class="sourceLineNo">236</span><a name="line.236"></a>
-<span class="sourceLineNo">237</span>  /**<a name="line.237"></a>
-<span class="sourceLineNo">238</span>   * Constructor.<a name="line.238"></a>
-<span class="sourceLineNo">239</span>   * @param numOfBins the number of bins for the histogram. A larger value results in more precise<a name="line.239"></a>
-<span class="sourceLineNo">240</span>   *          results but with lower efficiency, and vice versus.<a name="line.240"></a>
-<span class="sourceLineNo">241</span>   */<a name="line.241"></a>
-<span class="sourceLineNo">242</span>  public FastLongHistogram(int numOfBins) {<a name="line.242"></a>
-<span class="sourceLineNo">243</span>    this.bins = new Bins(numOfBins);<a name="line.243"></a>
-<span class="sourceLineNo">244</span>  }<a name="line.244"></a>
-<span class="sourceLineNo">245</span><a name="line.245"></a>
-<span class="sourceLineNo">246</span>  /**<a name="line.246"></a>
-<span class="sourceLineNo">247</span>   * Constructor setting the bins assuming a uniform distribution within a range.<a name="line.247"></a>
-<span class="sourceLineNo">248</span>   * @param numOfBins the number of bins for the histogram. A larger value results in more precise<a name="line.248"></a>
-<span class="sourceLineNo">249</span>   *          results but with lower efficiency, and vice versus.<a name="line.249"></a>
-<span class="sourceLineNo">250</span>   * @param min lower bound of the region, inclusive.<a name="line.250"></a>
-<span class="sourceLineNo">251</span>   * @param max higher bound of the region, inclusive.<a name="line.251"></a>
-<span class="sourceLineNo">252</span>   */<a name="line.252"></a>
-<span class="sourceLineNo">253</span>  public FastLongHistogram(int numOfBins, long min, long max) {<a name="line.253"></a>
-<span class="sourceLineNo">254</span>    this(numOfBins);<a name="line.254"></a>
-<span class="sourceLineNo">255</span>    Bins bins = new Bins(numOfBins);<a name="line.255"></a>
-<span class="sourceLineNo">256</span>    bins.add(min, 1);<a name="line.256"></a>
-<span class="sourceLineNo">257</span>    bins.add(max, 1);<a name="line.257"></a>
-<span class="sourceLineNo">258</span>    this.bins = new Bins(bins, numOfBins, 0.01, 0.999);<a name="line.258"></a>
-<span class="sourceLineNo">259</span>  }<a name="line.259"></a>
-<span class="sourceLineNo">260</span><a name="line.260"></a>
-<span class="sourceLineNo">261</span>  private FastLongHistogram(Bins bins) {<a name="line.261"></a>
-<span class="sourceLineNo">262</span>    this.bins = bins;<a name="line.262"></a>
-<span class="sourceLineNo">263</span>  }<a name="line.263"></a>
-<span class="sourceLineNo">264</span><a name="line.264"></a>
-<span class="sourceLineNo">265</span>  /**<a name="line.265"></a>
-<span class="sourceLineNo">266</span>   * Adds a value to the histogram.<a name="line.266"></a>
-<span class="sourceLineNo">267</span>   */<a name="line.267"></a>
-<span class="sourceLineNo">268</span>  public void add(long value, long count) {<a name="line.268"></a>
-<span class="sourceLineNo">269</span>    this.bins.add(value, count);<a name="line.269"></a>
-<span class="sourceLineNo">270</span>  }<a name="line.270"></a>
-<span class="sourceLineNo">271</span><a name="line.271"></a>
-<span class="sourceLineNo">272</span>  /**<a name="line.272"></a>
-<span class="sourceLineNo">273</span>   * Computes the quantiles give the ratios.<a name="line.273"></a>
-<span class="sourceLineNo">274</span>   */<a name="line.274"></a>
-<span class="sourceLineNo">275</span>  public long[] getQuantiles(double[] quantiles) {<a name="line.275"></a>
-<span class="sourceLineNo">276</span>    return this.bins.getQuantiles(quantiles);<a name="line.276"></a>
-<span class="sourceLineNo">277</span>  }<a name="line.277"></a>
-<span class="sourceLineNo">278</span><a name="line.278"></a>
-<span class="sourceLineNo">279</span>  public long[] getQuantiles() {<a name="line.279"></a>
-<span class="sourceLineNo">280</span>    return this.bins.getQuantiles(DEFAULT_QUANTILES);<a name="line.280"></a>
-<span class="sourceLineNo">281</span>  }<a name="line.281"></a>
-<span class="sourceLineNo">282</span><a name="line.282"></a>
-<span class="sourceLineNo">283</span>  public long getMin() {<a name="line.283"></a>
-<span class="sourceLineNo">284</span>    long min = this.bins.min.get();<a name="line.284"></a>
-<span class="sourceLineNo">285</span>    return min == Long.MAX_VALUE ? 0 : min; // in case it is not initialized<a name="line.285"></a>
+<span class="sourceLineNo">111</span>    /**<a name="line.111"></a>
+<span class="sourceLineNo">112</span>     * Adds a value to the histogram.<a name="line.112"></a>
+<span class="sourceLineNo">113</span>     */<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    public void add(long value, long count) {<a name="line.114"></a>
+<span class="sourceLineNo">115</span>      if (value &lt; 0) {<a name="line.115"></a>
+<span class="sourceLineNo">116</span>        // The whole computation is completely thrown off if there are negative numbers<a name="line.116"></a>
+<span class="sourceLineNo">117</span>        //<a name="line.117"></a>
+<span class="sourceLineNo">118</span>        // Normally we would throw an IllegalArgumentException however this is the metrics<a name="line.118"></a>
+<span class="sourceLineNo">119</span>        // system and it should be completely safe at all times.<a name="line.119"></a>
+<span class="sourceLineNo">120</span>        // So silently throw it away.<a name="line.120"></a>
+<span class="sourceLineNo">121</span>        return;<a name="line.121"></a>
+<span class="sourceLineNo">122</span>      }<a name="line.122"></a>
+<span class="sourceLineNo">123</span>      AtomicUtils.updateMin(min, value);<a name="line.123"></a>
+<span class="sourceLineNo">124</span>      AtomicUtils.updateMax(max, value);<a name="line.124"></a>
+<span class="sourceLineNo">125</span><a name="line.125"></a>
+<span class="sourceLineNo">126</span>      this.count.add(count);<a name="line.126"></a>
+<span class="sourceLineNo">127</span>      this.total.add(value * count);<a name="line.127"></a>
+<span class="sourceLineNo">128</span><a name="line.128"></a>
+<span class="sourceLineNo">129</span>      int pos = getIndex(value);<a name="line.129"></a>
+<span class="sourceLineNo">130</span>      this.counts[pos].add(count);<a name="line.130"></a>
+<span class="sourceLineNo">131</span><a name="line.131"></a>
+<span class="sourceLineNo">132</span>      // hasData needs to be updated as last<a name="line.132"></a>
+<span class="sourceLineNo">133</span>      this.hasData = true;<a name="line.133"></a>
+<span class="sourceLineNo">134</span>    }<a name="line.134"></a>
+<span class="sourceLineNo">135</span><a name="line.135"></a>
+<span class="sourceLineNo">136</span>    /**<a name="line.136"></a>
+<span class="sourceLineNo">137</span>     * Computes the quantiles give the ratios.<a name="line.137"></a>
+<span class="sourceLineNo">138</span>     */<a name="line.138"></a>
+<span class="sourceLineNo">139</span>    public long[] getQuantiles(double[] quantiles) {<a name="line.139"></a>
+<span class="sourceLineNo">140</span>      if (!hasData) {<a name="line.140"></a>
+<span class="sourceLineNo">141</span>        // No data yet.<a name="line.141"></a>
+<span class="sourceLineNo">142</span>        return new long[quantiles.length];<a name="line.142"></a>
+<span class="sourceLineNo">143</span>      }<a name="line.143"></a>
+<span class="sourceLineNo">144</span><a name="line.144"></a>
+<span class="sourceLineNo">145</span>      // Make a snapshot of lowerCounter, higherCounter and bins.counts to counts.<a name="line.145"></a>
+<span class="sourceLineNo">146</span>      // This is not synchronized, but since the counter are accumulating, the result is a good<a name="line.146"></a>
+<span class="sourceLineNo">147</span>      // estimation of a snapshot.<a name="line.147"></a>
+<span class="sourceLineNo">148</span>      long[] counts = new long[this.counts.length];<a name="line.148"></a>
+<span class="sourceLineNo">149</span>      long total = 0L;<a name="line.149"></a>
+<span class="sourceLineNo">150</span>      for (int i = 0; i &lt; this.counts.length; i++) {<a name="line.150"></a>
+<span class="sourceLineNo">151</span>        counts[i] = this.counts[i].sum();<a name="line.151"></a>
+<span class="sourceLineNo">152</span>        total += counts[i];<a name="line.152"></a>
+<span class="sourceLineNo">153</span>      }<a name="line.153"></a>
+<span class="sourceLineNo">154</span><a name="line.154"></a>
+<span class="sourceLineNo">155</span>      int rIndex = 0;<a name="line.155"></a>
+<span class="sourceLineNo">156</span>      double qCount = total * quantiles[0];<a name="line.156"></a>
+<span class="sourceLineNo">157</span>      long cum = 0L;<a name="line.157"></a>
+<span class="sourceLineNo">158</span><a name="line.158"></a>
+<span class="sourceLineNo">159</span>      long[] res = new long[quantiles.length];<a name="line.159"></a>
+<span class="sourceLineNo">160</span>      countsLoop: for (int i = 0; i &lt; counts.length; i++) {<a name="line.160"></a>
+<span class="sourceLineNo">161</span>        // mn and mx define a value range<a name="line.161"></a>
+<span class="sourceLineNo">162</span>        long mn, mx;<a name="line.162"></a>
+<span class="sourceLineNo">163</span>        if (i == 0) {<a name="line.163"></a>
+<span class="sourceLineNo">164</span>          mn = this.min.get();<a name="line.164"></a>
+<span class="sourceLineNo">165</span>          mx = this.binsMin;<a name="line.165"></a>
+<span class="sourceLineNo">166</span>        } else if (i == counts.length - 1) {<a name="line.166"></a>
+<span class="sourceLineNo">167</span>          mn = this.bins10XMax;<a name="line.167"></a>
+<span class="sourceLineNo">168</span>          mx = this.max.get();<a name="line.168"></a>
+<span class="sourceLineNo">169</span>        } else if (i == counts.length - 2) {<a name="line.169"></a>
+<span class="sourceLineNo">170</span>          mn = this.binsMax;<a name="line.170"></a>
+<span class="sourceLineNo">171</span>          mx = this.bins10XMax;<a name="line.171"></a>
+<span class="sourceLineNo">172</span>        } else {<a name="line.172"></a>
+<span class="sourceLineNo">173</span>          mn = this.binsMin + (i - 1) * (this.binsMax - this.binsMin) / (this.counts.length - 3);<a name="line.173"></a>
+<span class="sourceLineNo">174</span>          mx = this.binsMin + i * (this.binsMax - this.binsMin) / (this.counts.length - 3);<a name="line.174"></a>
+<span class="sourceLineNo">175</span>        }<a name="line.175"></a>
+<span class="sourceLineNo">176</span><a name="line.176"></a>
+<span class="sourceLineNo">177</span>        if (mx &lt; this.min.get()) {<a name="line.177"></a>
+<span class="sourceLineNo">178</span>          continue;<a name="line.178"></a>
+<span class="sourceLineNo">179</span>        }<a name="line.179"></a>
+<span class="sourceLineNo">180</span>        if (mn &gt; this.max.get()) {<a name="line.180"></a>
+<span class="sourceLineNo">181</span>          break;<a name="line.181"></a>
+<span class="sourceLineNo">182</span>        }<a name="line.182"></a>
+<span class="sourceLineNo">183</span>        mn = Math.max(mn, this.min.get());<a name="line.183"></a>
+<span class="sourceLineNo">184</span>        mx = Math.min(mx, this.max.get());<a name="line.184"></a>
+<span class="sourceLineNo">185</span><a name="line.185"></a>
+<span class="sourceLineNo">186</span>        // lastCum/cum are the corresponding counts to mn/mx<a name="line.186"></a>
+<span class="sourceLineNo">187</span>        double lastCum = cum;<a name="line.187"></a>
+<span class="sourceLineNo">188</span>        cum += counts[i];<a name="line.188"></a>
+<span class="sourceLineNo">189</span><a name="line.189"></a>
+<span class="sourceLineNo">190</span>        // fill the results for qCount is within current range.<a name="line.190"></a>
+<span class="sourceLineNo">191</span>        while (qCount &lt;= cum) {<a name="line.191"></a>
+<span class="sourceLineNo">192</span>          if (cum == lastCum) {<a name="line.192"></a>
+<span class="sourceLineNo">193</span>            res[rIndex] = mn;<a name="line.193"></a>
+<span class="sourceLineNo">194</span>          } else {<a name="line.194"></a>
+<span class="sourceLineNo">195</span>            res[rIndex] = (long) ((qCount - lastCum) * (mx - mn) / (cum - lastCum) + mn);<a name="line.195"></a>
+<span class="sourceLineNo">196</span>          }<a name="line.196"></a>
+<span class="sourceLineNo">197</span><a name="line.197"></a>
+<span class="sourceLineNo">198</span>          // move to next quantile<a name="line.198"></a>
+<span class="sourceLineNo">199</span>          rIndex++;<a name="line.199"></a>
+<span class="sourceLineNo">200</span>          if (rIndex &gt;= quantiles.length) {<a name="line.200"></a>
+<span class="sourceLineNo">201</span>            break countsLoop;<a name="line.201"></a>
+<span class="sourceLineNo">202</span>          }<a name="line.202"></a>
+<span class="sourceLineNo">203</span>          qCount = total * quantiles[rIndex];<a name="line.203"></a>
+<span class="sourceLineNo">204</span>        }<a name="line.204"></a>
+<span class="sourceLineNo">205</span>      }<a name="line.205"></a>
+<span class="sourceLineNo">206</span>      // In case quantiles contains values &gt;= 100%<a name="line.206"></a>
+<span class="sourceLineNo">207</span>      for (; rIndex &lt; quantiles.length; rIndex++) {<a name="line.207"></a>
+<span class="sourceLineNo">208</span>        res[rIndex] = this.max.get();<a name="line.208"></a>
+<span class="sourceLineNo">209</span>      }<a name="line.209"></a>
+<span class="sourceLineNo">210</span><a name="line.210"></a>
+<span class="sourceLineNo">211</span>      return res;<a name="line.211"></a>
+<span class="sourceLineNo">212</span>    }<a name="line.212"></a>
+<span class="sourceLineNo">213</span><a name="line.213"></a>
+<span class="sourceLineNo">214</span>    long getNumAtOrBelow(long val) {<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      return Arrays.stream(counts).mapToLong(c -&gt; c.sum()).limit(getIndex(val) + 1).sum();<a name="line.215"></a>
+<span class="sourceLineNo">216</span>    }<a name="line.216"></a>
+<span class="sourceLineNo">217</span>  }<a name="line.217"></a>
+<span class="sourceLineNo">218</span><a name="line.218"></a>
+<span class="sourceLineNo">219</span>  // The bins counting values. It is replaced with a new one in calling of reset().<a name="line.219"></a>
+<span class="sourceLineNo">220</span>  private volatile Bins bins;<a name="line.220"></a>
+<span class="sourceLineNo">221</span><a name="line.221"></a>
+<span class="sourceLineNo">222</span>  /**<a name="line.222"></a>
+<span class="sourceLineNo">223</span>   * Constructor.<a name="line.223"></a>
+<span class="sourceLineNo">224</span>   */<a name="line.224"></a>
+<span class="sourceLineNo">225</span>  public FastLongHistogram() {<a name="line.225"></a>
+<span class="sourceLineNo">226</span>    this(DEFAULT_NBINS);<a name="line.226"></a>
+<span class="sourceLineNo">227</span>  }<a name="line.227"></a>
+<span class="sourceLineNo">228</span><a name="line.228"></a>
+<span class="sourceLineNo">229</span>  /**<a name="line.229"></a>
+<span class="sourceLineNo">230</span>   * Constructor.<a name="line.230"></a>
+<span class="sourceLineNo">231</span>   * @param numOfBins the number of bins for the histogram. A larger value results in more precise<a name="line.231"></a>
+<span class="sourceLineNo">232</span>   *          results but with lower efficiency, and vice versus.<a name="line.232"></a>
+<span class="sourceLineNo">233</span>   */<a name="line.233"></a>
+<span class="sourceLineNo">234</span>  public FastLongHistogram(int numOfBins) {<a name="line.234"></a>
+<span class="sourceLineNo">235</span>    this.bins = new Bins(numOfBins);<a name="line.235"></a>
+<span class="sourceLineNo">236</span>  }<a name="line.236"></a>
+<span class="sourceLineNo">237</span><a name="line.237"></a>
+<span class="sourceLineNo">238</span>  /**<a name="line.238"></a>
+<span class="sourceLineNo">239</span>   * Constructor setting the bins assuming a uniform distribution within a range.<a name="line.239"></a>
+<span class="sourceLineNo">240</span>   * @param numOfBins the number of bins for the histogram. A larger value results in more precise<a name="line.240"></a>
+<span class="sourceLineNo">241</span>   *          results but with lower efficiency, and vice versus.<a name="line.241"></a>
+<span class="sourceLineNo">242</span>   * @param min lower bound of the region, inclusive.<a name="line.242"></a>
+<span class="sourceLineNo">243</span>   * @param max higher bound of the region, inclusive.<a name="line.243"></a>
+<span class="sourceLineNo">244</span>   */<a name="line.244"></a>
+<span class="sourceLineNo">245</span>  public FastLongHistogram(int numOfBins, long min, long max) {<a name="line.245"></a>
+<span class="sourceLineNo">246</span>    this(numOfBins);<a name="line.246"></a>
+<span class="sourceLineNo">247</span>    Bins bins = new Bins(numOfBins);<a name="line.247"></a>
+<span class="sourceLineNo">248</span>    bins.add(min, 1);<a name="line.248"></a>
+<span class="sourceLineNo">249</span>    bins.add(max, 1);<a name="line.249"></a>
+<span class="sourceLineNo">250</span>    this.bins = new Bins(bins, numOfBins, 0.01, 0.999);<a name="line.250"></a>
+<span class="sourceLineNo">251</span>  }<a name="line.251"></a>
+<span class="sourceLineNo">252</span><a name="line.252"></a>
+<span class="sourceLineNo">253</span>  private FastLongHistogram(Bins bins) {<a name="line.253"></a>
+<span class="sourceLineNo">254</span>    this.bins = bins;<a name="line.254"></a>
+<span class="sourceLineNo">255</span>  }<a name="line.255"></a>
+<span class="sourceLineNo">256</span><a name="line.256"></a>
+<span class="sourceLineNo">257</span>  /**<a name="line.257"></a>
+<span class="sourceLineNo">258</span>   * Adds a value to the histogram.<a name="line.258"></a>
+<span class="sourceLineNo">259</span>   */<a name="line.259"></a>
+<span class="sourceLineNo">260</span>  public void add(long value, long count) {<a name="line.260"></a>
+<span class="sourceLineNo">261</span>    this.bins.add(value, count);<a name="line.261"></a>
+<span class="sourceLineNo">262</span>  }<a name="line.262"></a>
+<span class="sourceLineNo">263</span><a name="line.263"></a>
+<span class="sourceLineNo">264</span>  /**<a name="line.264"></a>
+<span class="sourceLineNo">265</span>   * Computes the quantiles give the ratios.<a name="line.265"></a>
+<span class="sourceLineNo">266</span>   */<a name="line.266"></a>
+<span class="sourceLineNo">267</span>  public long[] getQuantiles(double[] quantiles) {<a name="line.267"></a>
+<span class="sourceLineNo">268</span>    return this.bins.getQuantiles(quantiles);<a name="line.268"></a>
+<span class="sourceLineNo">269</span>  }<a name="line.269"></a>
+<span class="sourceLineNo">270</span><a name="line.270"></a>
+<span class="sourceLineNo">271</span>  public long[] getQuantiles() {<a name="line.271"></a>
+<span class="sourceLineNo">272</span>    return this.bins.getQuantiles(DEFAULT_QUANTILES);<a name="line.272"></a>
+<span class="sourceLineNo">273</span>  }<a name="line.273"></a>
+<span class="sourceLineNo">274</span><a name="line.274"></a>
+<span class="sourceLineNo">275</span>  public long getMin() {<a name="line.275"></a>
+<span class="sourceLineNo">276</span>    long min = this.bins.min.get();<a name="line.276"></a>
+<span class="sourceLineNo">277</span>    return min == Long.MAX_VALUE ? 0 : min; // in case it is not initialized<a name="line.277"></a>
+<span class="sourceLineNo">278</span>  }<a name="line.278"></a>
+<span class="sourceLineNo">279</span><a name="line.279"></a>
+<span class="sourceLineNo">280</span>  public long getMax() {<a name="line.280"></a>
+<span class="sourceLineNo">281</span>    return this.bins.max.get();<a name="line.281"></a>
+<span class="sourceLineNo">282</span>  }<a name="line.282"></a>
+<span class="sourceLineNo">283</span><a name="line.283"></a>
+<span class="sourceLineNo">284</span>  public long getCount() {<a name="line.284"></a>
+<span class="sourceLineNo">285</span>    return this.bins.count.sum();<a name="line.285"></a>
 <span class="sourceLineNo">286</span>  }<a name="line.286"></a>
 <span class="sourceLineNo">287</span><a name="line.287"></a>
-<span class="sourceLineNo">288</span>  public long getMax() {<a name="line.288"></a>
-<span class="sourceLineNo">289</span>    return this.bins.max.get();<a name="line.289"></a>
-<span class="sourceLineNo">290</span>  }<a name="line.290"></a>
-<span class="sourceLineNo">291</span><a name="line.291"></a>
-<span class="sourceLineNo">292</span>  public long getCount() {<a name="line.292"></a>
-<span class="sourceLineNo">293</span>    return this.bins.count.get();<a name="line.293"></a>
-<span class="sourceLineNo">294</span>  }<a name="line.294"></a>
-<span class="sourceLineNo">295</span><a name="line.295"></a>
-<span class="sourceLineNo">296</span>  public long getMean() {<a name="line.296"></a>
-<span class="sourceLineNo">297</span>    Bins bins = this.bins;<a name="line.297"></a>
-<span class="sourceLineNo">298</span>    long count = bins.count.get();<a name="line.298"></a>
-<span class="sourceLineNo">299</span>    long total = bins.total.get();<a name="line.299"></a>
-<span class="sourceLineNo">300</span>    if (count == 0) {<a name="line.300"></a>
-<span class="sourceLineNo">301</span>      return 0;<a name="line.301"></a>
-<span class="sourceLineNo">302</span>    }<a name="line.302"></a>
-<span class="sourceLineNo">303</span>    return total / count;<a name="line.303"></a>
-<span class="sourceLineNo">304</span>  }<a name="line.304"></a>
-<span class="sourceLineNo">305</span><a name="line.305"></a>
-<span class="sourceLineNo">306</span>  public long getNumAtOrBelow(long value) {<a name="line.306"></a>
-<span class="sourceLineNo">307</span>    return this.bins.getNumAtOrBelow(value);<a name="line.307"></a>
-<span class="sourceLineNo">308</span>  }<a name="line.308"></a>
-<span class="sourceLineNo">309</span><a name="line.309"></a>
-<span class="sourceLineNo">310</span>  /**<a name="line.310"></a>
-<span class="sourceLineNo">311</span>   * Resets the histogram for new counting.<a name="line.311"></a>
-<span class="sourceLineNo">312</span>   */<a name="line.312"></a>
-<span class="sourceLineNo">313</span>  public FastLongHistogram reset() {<a name="line.313"></a>
-<span class="sourceLineNo">314</span>    Bins oldBins = this.bins;<a name="line.314"></a>
-<span class="sourceLineNo">315</span>    this.bins = new Bins(this.bins, this.bins.counts.length - 3, 0.01, 0.99);<a name="line.315"></a>
-<span class="sourceLineNo">316</span>    return new FastLongHistogram(oldBins);<a name="line.316"></a>
-<span class="sourceLineNo">317</span>  }<a name="line.317"></a>
-<span class="sourceLineNo">318</span>}<a name="line.318"></a>
+<span class="sourceLineNo">288</span>  public long getMean() {<a name="line.288"></a>
+<span class="sourceLineNo">289</span>    Bins bins = this.bins;<a name="line.289"></a>
+<span class="sourceLineNo">290</span>    long count = bins.count.sum();<a name="line.290"></a>
+<span class="sourceLineNo">291</span>    long total = bins.total.sum();<a name="line.291"></a>
+<span class="sourceLineNo">292</span>    if (count == 0) {<a name="line.292"></a>
+<span class="sourceLineNo">293</span>      return 0;<a name="line.293"></a>
+<span class="sourceLineNo">294</span>    }<a name="line.294"></a>
+<span class="sourceLineNo">295</span>    return total / count;<a name="line.295"></a>
+<span class="sourceLineNo">296</span>  }<a name="line.296"></a>
+<span class="sourceLineNo">297</span><a name="line.297"></a>
+<span class="sourceLineNo">298</span>  public long getNumAtOrBelow(long value) {<a name="line.298"></a>
+<span class="sourceLineNo">299</span>    return this.bins.getNumAtOrBelow(value);<a name="line.299"></a>
+<span class="sourceLineNo">300</span>  }<a name="line.300"></a>
+<span class="sourceLineNo">301</span><a name="line.301"></a>
+<span class="sourceLineNo">302</span>  /**<a name="line.302"></a>
+<span class="sourceLineNo">303</span>   * Resets the histogram for new counting.<a name="line.303"></a>
+<span class="sourceLineNo">304</span>   */<a name="line.304"></a>
+<span class="sourceLineNo">305</span>  public FastLongHistogram reset() {<a name="line.305"></a>
+<span class="sourceLineNo">306</span>    Bins oldBins = this.bins;<a name="line.306"></a>
+<span class="sourceLineNo">307</span>    this.bins = new Bins(this.bins, this.bins.counts.length - 3, 0.01, 0.99);<a name="line.307"></a>
+<span class="sourceLineNo">308</span>    return new FastLongHistogram(oldBins);<a name="line.308"></a>
+<span class="sourceLineNo">309</span>  }<a name="line.309"></a>
+<span class="sourceLineNo">310</span>}<a name="line.310"></a>
 
 
 


Mime
View raw message