package com.discord.utilities.collections; import a0.a.a.a; import a0.a.a.b; import androidx.annotation.VisibleForTesting; import com.google.android.material.shadow.ShadowDrawableWrapper; import d0.t.n; import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; import kotlin.collections.ArrayDeque; import kotlin.jvm.internal.DefaultConstructorMarker; /* compiled from: Histogram.kt */ public final class Histogram { private final int bucketLimit; private long count; private final int halfPrecision; private final TreeMap histogram; private Long max; private Long min; private final int precision; private long total; /* compiled from: Histogram.kt */ public static final class Report { private final double average; private final int bucketCount; private final long count; private final long max; private final long min; private final long percentile25; private final long percentile50; private final long percentile75; private final long percentile90; private final long percentile95; public Report(long j, long j2, double d, long j3, int i, long j4, long j5, long j6, long j7, long j8) { this.min = j; this.max = j2; this.average = d; this.count = j3; this.bucketCount = i; this.percentile25 = j4; this.percentile50 = j5; this.percentile75 = j6; this.percentile90 = j7; this.percentile95 = j8; } public static /* synthetic */ Report copy$default(Report report, long j, long j2, double d, long j3, int i, long j4, long j5, long j6, long j7, long j8, int i2, Object obj) { return report.copy((i2 & 1) != 0 ? report.min : j, (i2 & 2) != 0 ? report.max : j2, (i2 & 4) != 0 ? report.average : d, (i2 & 8) != 0 ? report.count : j3, (i2 & 16) != 0 ? report.bucketCount : i, (i2 & 32) != 0 ? report.percentile25 : j4, (i2 & 64) != 0 ? report.percentile50 : j5, (i2 & 128) != 0 ? report.percentile75 : j6, (i2 & 256) != 0 ? report.percentile90 : j7, (i2 & 512) != 0 ? report.percentile95 : j8); } public final long component1() { return this.min; } public final long component10() { return this.percentile95; } public final long component2() { return this.max; } public final double component3() { return this.average; } public final long component4() { return this.count; } public final int component5() { return this.bucketCount; } public final long component6() { return this.percentile25; } public final long component7() { return this.percentile50; } public final long component8() { return this.percentile75; } public final long component9() { return this.percentile90; } public final Report copy(long j, long j2, double d, long j3, int i, long j4, long j5, long j6, long j7, long j8) { return new Report(j, j2, d, j3, i, j4, j5, j6, j7, j8); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Report)) { return false; } Report report = (Report) obj; return this.min == report.min && this.max == report.max && Double.compare(this.average, report.average) == 0 && this.count == report.count && this.bucketCount == report.bucketCount && this.percentile25 == report.percentile25 && this.percentile50 == report.percentile50 && this.percentile75 == report.percentile75 && this.percentile90 == report.percentile90 && this.percentile95 == report.percentile95; } public final double getAverage() { return this.average; } public final int getBucketCount() { return this.bucketCount; } public final long getCount() { return this.count; } public final long getMax() { return this.max; } public final long getMin() { return this.min; } public final long getPercentile25() { return this.percentile25; } public final long getPercentile50() { return this.percentile50; } public final long getPercentile75() { return this.percentile75; } public final long getPercentile90() { return this.percentile90; } public final long getPercentile95() { return this.percentile95; } public int hashCode() { int a = b.a(this.max); int a2 = a.a(this.average); int a3 = b.a(this.count); int a4 = b.a(this.percentile25); int a5 = b.a(this.percentile50); int a6 = b.a(this.percentile75); int a7 = b.a(this.percentile90); return b.a(this.percentile95) + ((a7 + ((a6 + ((a5 + ((a4 + ((((a3 + ((a2 + ((a + (b.a(this.min) * 31)) * 31)) * 31)) * 31) + this.bucketCount) * 31)) * 31)) * 31)) * 31)) * 31); } public String toString() { StringBuilder L = c.d.b.a.a.L("Report(min="); L.append(this.min); L.append(", max="); L.append(this.max); L.append(", average="); L.append(this.average); L.append(", count="); L.append(this.count); L.append(", bucketCount="); L.append(this.bucketCount); L.append(", percentile25="); L.append(this.percentile25); L.append(", percentile50="); L.append(this.percentile50); L.append(", percentile75="); L.append(this.percentile75); L.append(", percentile90="); L.append(this.percentile90); L.append(", percentile95="); return c.d.b.a.a.y(L, this.percentile95, ")"); } } public Histogram(int i, int i2) { this.precision = i; this.bucketLimit = i2; this.histogram = new TreeMap<>(); this.halfPrecision = i / 2; } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ Histogram(int i, int i2, int i3, DefaultConstructorMarker defaultConstructorMarker) { this(i, (i3 & 2) != 0 ? 1000 : i2); } public final void addSample(long j) { this.count++; this.total += j; Long l = this.min; Long l2 = this.max; if (l == null || l.longValue() > j) { this.min = Long.valueOf(j); } if (l2 == null || l2.longValue() < j) { this.max = Long.valueOf(j); } long roundValue$utils_release = roundValue$utils_release(j); Long l3 = this.histogram.get(Long.valueOf(roundValue$utils_release)); if (l3 != null || this.histogram.size() <= this.bucketLimit) { this.histogram.put(Long.valueOf(roundValue$utils_release), Long.valueOf((l3 != null ? l3.longValue() : 0) + 1)); } } public final Report getReport() { long j; Integer num; LinkedHashMap linkedHashMap = new LinkedHashMap(); int i = 50; ArrayDeque arrayDeque = new ArrayDeque(n.listOf((Object[]) new Integer[]{25, 50, 75, 90, 95})); long j2 = 0; for (Map.Entry entry : this.histogram.entrySet()) { long longValue = entry.getKey().longValue(); long longValue2 = entry.getValue().longValue(); if (arrayDeque.isEmpty()) { break; } j2 += longValue2; double d = (((double) j2) / ((double) this.count)) * ((double) 100); while (true) { if (!(!arrayDeque.isEmpty())) { break; } else if (((Number) arrayDeque.get(0)).doubleValue() > d) { break; } else { linkedHashMap.put(Integer.valueOf(((Number) arrayDeque.removeFirst()).intValue()), Long.valueOf(longValue)); } } i = i; } Long l = this.min; long longValue3 = l != null ? l.longValue() : 0; Long l2 = this.max; long longValue4 = l2 != null ? l2.longValue() : 0; long j3 = this.count; double d2 = j3 == 0 ? ShadowDrawableWrapper.COS_45 : ((double) this.total) / ((double) j3); int size = this.histogram.size(); Long l3 = (Long) linkedHashMap.get(25); if (l3 != null) { j = l3.longValue(); num = i; } else { num = i; j = 0; } Long l4 = (Long) linkedHashMap.get(num); long longValue5 = l4 != null ? l4.longValue() : 0; Long l5 = (Long) linkedHashMap.get(75); long longValue6 = l5 != null ? l5.longValue() : 0; Long l6 = (Long) linkedHashMap.get(90); long longValue7 = l6 != null ? l6.longValue() : 0; Long l7 = (Long) linkedHashMap.get(95); return new Report(longValue3, longValue4, d2, j3, size, j, longValue5, longValue6, longValue7, l7 != null ? l7.longValue() : 0); } @VisibleForTesting public final long roundValue$utils_release(long j) { int i = this.precision; long j2 = j % ((long) i); long j3 = j - j2; return j2 <= ((long) this.halfPrecision) ? j3 : j3 + ((long) i); } }