@Test public void get() { final Histogram h = new Histogram(new HashMap<Histogram.Range, Double>() { { put(new Histogram.Range(0, 1), 1d); put(new Histogram.Range(1, 2), 1d); put(new Histogram.Range(2, 6), 4d); put(new Histogram.Range(6, 7), 1d); put(new Histogram.Range(7, 10), 3d); } }.entrySet().stream().map(HistogramTest::map_)); assertEquals(0, h.get(-0.0), 0.000001); assertEquals(0, h.get(0), 0.000001); assertEquals(10, h.get(10), 0.000001); assertEquals(5, h.get(5), 0.000001); assertEquals(9.9, h.get(9.9), 0.000001); assertEquals(6.9, h.get(6.9), 0.000001); }
public double get(double index) { ListIterator<Bucket> b = buckets_.listIterator(0); ListIterator<Bucket> e = buckets_.listIterator(buckets_.size()); while (b.nextIndex() < e.previousIndex()) { final ListIterator<Bucket> mid = buckets_.listIterator(b.nextIndex() / 2 + e.nextIndex() / 2); final Bucket mid_bucket = mid.next(); mid.previous(); if (mid_bucket.getRunningEventsCount() == index && mid.nextIndex() >= e.previousIndex()) { return mid_bucket.getRange().getCeil(); } else if (mid_bucket.getRunningEventsCount() <= index) { b = mid; b.next(); } else if (mid_bucket.getRunningEventsCount() - mid_bucket.getEvents() > index) { e = mid; } else { b = mid; break; } } final Bucket bucket = b.next(); b.previous(); final double low = bucket.getRunningEventsCount() - bucket.getEvents(); final double off = index - low; final double left_fraction = off / bucket.getEvents(); final double right_fraction = 1 - left_fraction; return bucket.getRange().getCeil() * left_fraction + bucket.getRange().getFloor() * right_fraction; }
Histogram implements Serializable, Comparable<Histogram> { public double get(double index) { ListIterator<Bucket> b = buckets_.listIterator(0); ListIterator<Bucket> e = buckets_.listIterator(buckets_.size()); while (b.nextIndex() < e.previousIndex()) { final ListIterator<Bucket> mid = buckets_.listIterator(b.nextIndex() / 2 + e.nextIndex() / 2); final Bucket mid_bucket = mid.next(); mid.previous(); if (mid_bucket.getRunningEventsCount() == index && mid.nextIndex() >= e.previousIndex()) { return mid_bucket.getRange().getCeil(); } else if (mid_bucket.getRunningEventsCount() <= index) { b = mid; b.next(); } else if (mid_bucket.getRunningEventsCount() - mid_bucket.getEvents() > index) { e = mid; } else { b = mid; break; } } final Bucket bucket = b.next(); b.previous(); final double low = bucket.getRunningEventsCount() - bucket.getEvents(); final double off = index - low; final double left_fraction = off / bucket.getEvents(); final double right_fraction = 1 - left_fraction; return bucket.getRange().getCeil() * left_fraction + bucket.getRange().getFloor() * right_fraction; } }
Histogram implements Serializable, Comparable<Histogram> { public double get(double index) { ListIterator<Bucket> b = buckets_.listIterator(0); ListIterator<Bucket> e = buckets_.listIterator(buckets_.size()); while (b.nextIndex() < e.previousIndex()) { final ListIterator<Bucket> mid = buckets_.listIterator(b.nextIndex() / 2 + e.nextIndex() / 2); final Bucket mid_bucket = mid.next(); mid.previous(); if (mid_bucket.getRunningEventsCount() == index && mid.nextIndex() >= e.previousIndex()) { return mid_bucket.getRange().getCeil(); } else if (mid_bucket.getRunningEventsCount() <= index) { b = mid; b.next(); } else if (mid_bucket.getRunningEventsCount() - mid_bucket.getEvents() > index) { e = mid; } else { b = mid; break; } } final Bucket bucket = b.next(); b.previous(); final double low = bucket.getRunningEventsCount() - bucket.getEvents(); final double off = index - low; final double left_fraction = off / bucket.getEvents(); final double right_fraction = 1 - left_fraction; return bucket.getRange().getCeil() * left_fraction + bucket.getRange().getFloor() * right_fraction; } Histogram(RangeWithCount... items);  Histogram(Stream<RangeWithCount> items); }
Histogram implements Serializable, Comparable<Histogram> { public double get(double index) { ListIterator<Bucket> b = buckets_.listIterator(0); ListIterator<Bucket> e = buckets_.listIterator(buckets_.size()); while (b.nextIndex() < e.previousIndex()) { final ListIterator<Bucket> mid = buckets_.listIterator(b.nextIndex() / 2 + e.nextIndex() / 2); final Bucket mid_bucket = mid.next(); mid.previous(); if (mid_bucket.getRunningEventsCount() == index && mid.nextIndex() >= e.previousIndex()) { return mid_bucket.getRange().getCeil(); } else if (mid_bucket.getRunningEventsCount() <= index) { b = mid; b.next(); } else if (mid_bucket.getRunningEventsCount() - mid_bucket.getEvents() > index) { e = mid; } else { b = mid; break; } } final Bucket bucket = b.next(); b.previous(); final double low = bucket.getRunningEventsCount() - bucket.getEvents(); final double off = index - low; final double left_fraction = off / bucket.getEvents(); final double right_fraction = 1 - left_fraction; return bucket.getRange().getCeil() * left_fraction + bucket.getRange().getFloor() * right_fraction; } Histogram(RangeWithCount... items);  Histogram(Stream<RangeWithCount> items); Stream<RangeWithCount> stream(); double getEventCount(); boolean isEmpty(); Optional<Double> min(); Optional<Double> max(); Optional<Double> median(); Optional<Double> avg(); double sum(); double get(double index); double percentile(double percentile); Histogram modifyEventCounters(BiFunction<Range, Double, Double> fn); static Histogram add(Histogram x, Histogram y); static Histogram negate(Histogram x); static Histogram subtract(Histogram x, Histogram y); static Histogram multiply(Histogram x, double y); static Histogram divide(Histogram x, double y); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(Histogram o); @Override String toString(); }
Histogram implements Serializable, Comparable<Histogram> { public double get(double index) { ListIterator<Bucket> b = buckets_.listIterator(0); ListIterator<Bucket> e = buckets_.listIterator(buckets_.size()); while (b.nextIndex() < e.previousIndex()) { final ListIterator<Bucket> mid = buckets_.listIterator(b.nextIndex() / 2 + e.nextIndex() / 2); final Bucket mid_bucket = mid.next(); mid.previous(); if (mid_bucket.getRunningEventsCount() == index && mid.nextIndex() >= e.previousIndex()) { return mid_bucket.getRange().getCeil(); } else if (mid_bucket.getRunningEventsCount() <= index) { b = mid; b.next(); } else if (mid_bucket.getRunningEventsCount() - mid_bucket.getEvents() > index) { e = mid; } else { b = mid; break; } } final Bucket bucket = b.next(); b.previous(); final double low = bucket.getRunningEventsCount() - bucket.getEvents(); final double off = index - low; final double left_fraction = off / bucket.getEvents(); final double right_fraction = 1 - left_fraction; return bucket.getRange().getCeil() * left_fraction + bucket.getRange().getFloor() * right_fraction; } Histogram(RangeWithCount... items);  Histogram(Stream<RangeWithCount> items); Stream<RangeWithCount> stream(); double getEventCount(); boolean isEmpty(); Optional<Double> min(); Optional<Double> max(); Optional<Double> median(); Optional<Double> avg(); double sum(); double get(double index); double percentile(double percentile); Histogram modifyEventCounters(BiFunction<Range, Double, Double> fn); static Histogram add(Histogram x, Histogram y); static Histogram negate(Histogram x); static Histogram subtract(Histogram x, Histogram y); static Histogram multiply(Histogram x, double y); static Histogram divide(Histogram x, double y); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(Histogram o); @Override String toString();  }