/** * Returns a map of range -> event count. The elements of the stream are * a mutable copy of the internal data. */ public Stream<RangeWithCount> stream() { return buckets_.stream() .map(bucket -> new RangeWithCount(bucket.getRange(), bucket.getEvents())); }
/** * Create a histogram from a set of ranges with associated event counters. * * @throws IllegalArgumentException If the items contain mixed signs. */ public Histogram(Stream<RangeWithCount> items) { final List<RangeWithCount> iter = cleanup_(items.map(RangeWithCount::clone).collect(Collectors.toList())); if (iter.isEmpty()) { buckets_ = EMPTY_LIST; return; } if (iter.stream() .map(RangeWithCount::getCount) .map(Math::signum) .distinct() .count() > 1) { throw new IllegalArgumentException("mixed sign"); } final List<Bucket> buckets = new ArrayList<>(iter.size()); double running_total = 0; for (RangeWithCount rwc : iter) { running_total += rwc.getCount(); buckets.add(new Bucket(rwc.getRange(), rwc.getCount(), running_total)); } buckets_ = unmodifiableList(buckets); }
.comparing((RangeWithCount range_count) -> range_count.getRange().getFloor()) .thenComparing(Comparator.comparing((RangeWithCount range_count) -> range_count.getRange().getCeil())); if (head.getRange().equals(succ.getRange())) { succ.setCount(succ.getCount() + head.getCount()); continue; if (head.getRange().getFloor() == succ.getRange().getFloor()) { final double mid = head.getRange().getCeil(); final double ceil = succ.getRange().getCeil(); final double succ_range = succ.getRange().getWidth(); final double succ_left_fraction = (mid - succ.getRange().getFloor()) / succ_range; final double succ_right_fraction = 1 - succ_left_fraction; head.setCount(head.getCount() + succ_left_fraction * succ.getCount()); succ.setCount(succ_right_fraction * succ.getCount()); succ.setRange(new Range(mid, ceil)); imed.add(0, head); sort(imed, cmp); if (head.getRange().getCeil() <= succ.getRange().getFloor()) { if (Math.signum(head.getCount()) != 0) result.add(head); continue; assert (head.getRange().getFloor() < succ.getRange().getFloor()); assert (succ.getRange().getFloor() < head.getRange().getCeil());
.comparing((RangeWithCount range_count) -> range_count.getRange().getFloor()) .thenComparing(Comparator.comparing((RangeWithCount range_count) -> range_count.getRange().getCeil())); if (head.getRange().equals(succ.getRange())) { succ.setCount(succ.getCount() + head.getCount()); continue; if (head.getRange().getFloor() == succ.getRange().getFloor()) { final double mid = head.getRange().getCeil(); final double ceil = succ.getRange().getCeil(); final double succ_range = succ.getRange().getWidth(); final double succ_left_fraction = (mid - succ.getRange().getFloor()) / succ_range; final double succ_right_fraction = 1 - succ_left_fraction; head.setCount(head.getCount() + succ_left_fraction * succ.getCount()); succ.setCount(succ_right_fraction * succ.getCount()); succ.setRange(new Range(mid, ceil)); imed.add(0, head); sort(imed, cmp); if (head.getRange().getCeil() <= succ.getRange().getFloor()) { if (Math.signum(head.getCount()) != 0) result.add(head); continue; assert (head.getRange().getFloor() < succ.getRange().getFloor()); assert (succ.getRange().getFloor() < head.getRange().getCeil());
public final Histogram_elemContext histogram_elem() throws RecognitionException { Histogram_elemContext _localctx = new Histogram_elemContext(_ctx, getState()); enterRule(_localctx, 172, RULE_histogram_elem); try { enterOuterAlt(_localctx, 1); { setState(1254); ((Histogram_elemContext)_localctx).s_floor = number(); setState(1255); match(DOT_DOT_LIT); setState(1256); ((Histogram_elemContext)_localctx).s_ceil = number(); setState(1257); match(EQ_KW); setState(1258); ((Histogram_elemContext)_localctx).s_count = number(); ((Histogram_elemContext)_localctx).s = new Histogram.RangeWithCount(new Histogram.Range(((Histogram_elemContext)_localctx).s_floor.s.doubleValue(), ((Histogram_elemContext)_localctx).s_ceil.s.doubleValue()), ((Histogram_elemContext)_localctx).s_count.s.doubleValue()); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
public final Histogram_elemContext histogram_elem() throws RecognitionException { Histogram_elemContext _localctx = new Histogram_elemContext(_ctx, getState()); enterRule(_localctx, 94, RULE_histogram_elem); try { enterOuterAlt(_localctx, 1); { setState(698); ((Histogram_elemContext)_localctx).s_floor = number(); setState(699); match(DOT_DOT_LIT); setState(700); ((Histogram_elemContext)_localctx).s_ceil = number(); setState(701); match(EQ_KW); setState(702); ((Histogram_elemContext)_localctx).s_count = number(); ((Histogram_elemContext)_localctx).s = new Histogram.RangeWithCount(new Histogram.Range(((Histogram_elemContext)_localctx).s_floor.s.doubleValue(), ((Histogram_elemContext)_localctx).s_ceil.s.doubleValue()), ((Histogram_elemContext)_localctx).s_count.s.doubleValue()); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
/** * Create a histogram from a set of ranges with associated event counters. * * @throws IllegalArgumentException If the items contain mixed signs. */ public Histogram(Stream<RangeWithCount> items) { final List<RangeWithCount> iter = cleanup_(items.map(RangeWithCount::clone).collect(Collectors.toList())); if (iter.isEmpty()) { buckets_ = EMPTY_LIST; return; } if (iter.stream() .map(RangeWithCount::getCount) .map(Math::signum) .distinct() .count() > 1) { throw new IllegalArgumentException("mixed sign"); } final List<Bucket> buckets = new ArrayList<>(iter.size()); double running_total = 0; for (RangeWithCount rwc : iter) { running_total += rwc.getCount(); buckets.add(new Bucket(rwc.getRange(), rwc.getCount(), running_total)); } buckets_ = unmodifiableList(buckets); }
public final Histogram_elemContext histogram_elem() throws RecognitionException { Histogram_elemContext _localctx = new Histogram_elemContext(_ctx, getState()); enterRule(_localctx, 94, RULE_histogram_elem); try { enterOuterAlt(_localctx, 1); { setState(698); ((Histogram_elemContext)_localctx).s_floor = number(); setState(699); match(DOT_DOT_LIT); setState(700); ((Histogram_elemContext)_localctx).s_ceil = number(); setState(701); match(EQ_KW); setState(702); ((Histogram_elemContext)_localctx).s_count = number(); ((Histogram_elemContext)_localctx).s = new Histogram.RangeWithCount(new Histogram.Range(((Histogram_elemContext)_localctx).s_floor.s.doubleValue(), ((Histogram_elemContext)_localctx).s_ceil.s.doubleValue()), ((Histogram_elemContext)_localctx).s_count.s.doubleValue()); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
@Override public RangeWithCount clone() { return new RangeWithCount(range, count); } }
/** * Returns a map of range -> event count. The elements of the stream are * a mutable copy of the internal data. */ public Stream<RangeWithCount> stream() { return buckets_.stream() .map(bucket -> new RangeWithCount(bucket.getRange(), bucket.getEvents())); }
@Override public RangeWithCount clone() { return new RangeWithCount(range, count); } }