Skip to content

Commit 760aac6

Browse files
committed
fix/disable SwiftLint warnings
1 parent b14898d commit 760aac6

File tree

5 files changed

+99
-98
lines changed

5 files changed

+99
-98
lines changed

Sources/Histogram/Histogram.swift

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// http://www.apache.org/licenses/LICENSE-2.0
99
//
1010

11+
// swiftlint:disable file_length type_body_length line_length identifier_name
12+
1113
import Foundation
1214
import Numerics
1315

@@ -49,7 +51,6 @@ public enum HistogramOutputFormat {
4951
* they are encountered. Note that recording calls that cause auto-resizing may take longer to execute, as resizing
5052
* incurs allocation and copying of internal data structures.
5153
*/
52-
5354
public struct Histogram<Count: FixedWidthInteger> {
5455
/// The lowest value that can be discerned (distinguished from 0) by the histogram.
5556
public let lowestDiscernibleValue: UInt64
@@ -69,17 +70,13 @@ public struct Histogram<Count: FixedWidthInteger> {
6970
// Biggest value that can fit in bucket 0
7071
let subBucketMask: UInt64
7172

72-
@usableFromInline
73-
var maxValue: UInt64 = 0
73+
@usableFromInline var maxValue: UInt64 = 0
7474

75-
@usableFromInline
76-
var minNonZeroValue: UInt64 = .max
75+
@usableFromInline var minNonZeroValue: UInt64 = .max
7776

78-
@usableFromInline
79-
var counts: [Count]
77+
@usableFromInline var counts: [Count]
8078

81-
@usableFromInline
82-
var _totalCount: UInt64 = 0
79+
@usableFromInline var _totalCount: UInt64 = 0
8380

8481
/// Total count of all recorded values in the histogram
8582
public var totalCount: UInt64 { _totalCount }
@@ -88,7 +85,7 @@ public struct Histogram<Count: FixedWidthInteger> {
8885
public let numberOfSignificantValueDigits: SignificantDigits
8986

9087
/// Control whether or not the histogram can auto-resize and auto-adjust its ``highestTrackableValue``.
91-
public var autoResize: Bool = false
88+
public var autoResize = false
9289

9390
let subBucketHalfCountMagnitude: UInt8
9491

@@ -167,7 +164,7 @@ public struct Histogram<Count: FixedWidthInteger> {
167164
// fits in 62 bits is debatable, and it makes it harder to work through the logic.
168165
// Sums larger than 64 are totally broken as leadingZeroCountBase would go negative.
169166
precondition(unitMagnitude + subBucketHalfCountMagnitude <= 61,
170-
"Invalid arguments: Cannot represent numberOfSignificantValueDigits worth of values beyond lowestDiscernibleValue")
167+
"Invalid arguments: Cannot represent numberOfSignificantValueDigits worth of values beyond lowestDiscernibleValue")
171168

172169
// Establish leadingZeroCountBase, used in bucketIndexForValue() fast path:
173170
// subtract the bits that would be used by the largest value in bucket 0.
@@ -476,7 +473,7 @@ public struct Histogram<Count: FixedWidthInteger> {
476473
* - Returns: The mean value (in value units) of the histogram data.
477474
*/
478475
public var mean: Double {
479-
if (totalCount == 0) {
476+
if totalCount == 0 {
480477
return 0.0
481478
}
482479
var totalValue: Double = 0
@@ -492,7 +489,7 @@ public struct Histogram<Count: FixedWidthInteger> {
492489
* - Returns: The standard deviation (in value units) of the histogram data.
493490
*/
494491
public var stdDeviation: Double {
495-
if (totalCount == 0) {
492+
if totalCount == 0 {
496493
return 0.0
497494
}
498495

@@ -590,7 +587,7 @@ public struct Histogram<Count: FixedWidthInteger> {
590587

591588
var countAtThisValue: Count = 0
592589

593-
private var freshSubBucket: Bool = true
590+
private var freshSubBucket = true
594591

595592
init(histogram: Histogram) {
596593
self.histogram = histogram
@@ -623,7 +620,8 @@ public struct Histogram<Count: FixedWidthInteger> {
623620

624621
let percentile = (100.0 * Double(totalCountToCurrentIndex)) / Double(arrayTotalCount)
625622

626-
return IterationValue(value: valueIteratedTo, prevValue: prevValueIteratedTo, count: countAtThisValue,
623+
return IterationValue(
624+
value: valueIteratedTo, prevValue: prevValueIteratedTo, count: countAtThisValue,
627625
percentile: percentile, percentileLevelIteratedTo: percentileIteratedTo ?? percentile,
628626
countAddedInThisIterationStep: totalCountToCurrentIndex - totalCountToPrevIndex,
629627
totalCountToThisValue: totalCountToCurrentIndex, totalValueToThisValue: totalValueToCurrentIndex)
@@ -1027,7 +1025,7 @@ public struct Histogram<Count: FixedWidthInteger> {
10271025
outputValueUnitScalingRatio: Double,
10281026
percentileTicksPerHalfDistance ticks: Int = 5,
10291027
format: HistogramOutputFormat = .plainText) {
1030-
1028+
// small helper to pad strings to specific widths, for some reason "%10s"/"%10@" doesn't work in String.init(format:)
10311029
func padded(_ s: String, to: Int) -> String {
10321030
if s.count < to {
10331031
return String(repeating: " ", count: to - s.count) + s
@@ -1051,13 +1049,15 @@ public struct Histogram<Count: FixedWidthInteger> {
10511049

10521050
for iv in percentiles(ticksPerHalfDistance: ticks) {
10531051
if iv.percentileLevelIteratedTo != 100.0 {
1054-
stream.write(String(format: percentileFormatString,
1052+
stream.write(String(
1053+
format: percentileFormatString,
10551054
Double(iv.value) / outputValueUnitScalingRatio,
10561055
iv.percentileLevelIteratedTo / 100.0,
10571056
iv.totalCountToThisValue,
10581057
1.0 / (1.0 - (iv.percentileLevelIteratedTo / 100.0))))
10591058
} else {
1060-
stream.write(String(format: lastLinePercentileFormatString,
1059+
stream.write(String(
1060+
format: lastLinePercentileFormatString,
10611061
Double(iv.value) / outputValueUnitScalingRatio,
10621062
iv.percentileLevelIteratedTo / 100.0,
10631063
iv.totalCountToThisValue))
@@ -1267,8 +1267,8 @@ public struct Histogram<Count: FixedWidthInteger> {
12671267
private static func bucketsNeededToCoverValue(_ value: UInt64, subBucketCount: Int, unitMagnitude: UInt8) -> Int {
12681268
var smallestUntrackableValue = UInt64(subBucketCount) << unitMagnitude
12691269
var bucketsNeeded = 1
1270-
while (smallestUntrackableValue <= value) {
1271-
if (smallestUntrackableValue > UInt64.max / 2) {
1270+
while smallestUntrackableValue <= value {
1271+
if smallestUntrackableValue > UInt64.max / 2 {
12721272
return bucketsNeeded + 1
12731273
}
12741274
smallestUntrackableValue <<= 1
@@ -1311,6 +1311,7 @@ extension Histogram: Equatable {
13111311
// resizing.
13121312
if lhs.counts.count == rhs.counts.count {
13131313
for i in 0..<lhs.counts.count {
1314+
// swiftlint:disable:next for_where
13141315
if lhs.counts[i] != rhs.counts[i] {
13151316
return false
13161317
}
@@ -1319,6 +1320,7 @@ extension Histogram: Equatable {
13191320
// Comparing the values is valid here because we have already confirmed the histograms have the same total
13201321
// count. It would not be correct otherwise.
13211322
for iv in lhs.recordedValues() {
1323+
// swiftlint:disable:next for_where
13221324
if rhs.countForValue(iv.value) != iv.count {
13231325
return false
13241326
}

Sources/HistogramExample/HistogramExample.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// You may obtain a copy of the License at
88
// http://www.apache.org/licenses/LICENSE-2.0
99

10+
// swiftlint:disable identifier_name
11+
1012
import Histogram
1113

1214
@main
@@ -18,7 +20,7 @@ struct HistogramExample {
1820

1921
// record some random values
2022
for _ in 1...100 {
21-
histogram.record(UInt64.random(in: 10...1000))
23+
histogram.record(UInt64.random(in: 10...1_000))
2224
}
2325

2426
// record value n times

Tests/HistogramTests/HistogramAutosizingTest.swift renamed to Tests/HistogramTests/HistogramAutosizingTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
// http://www.apache.org/licenses/LICENSE-2.0
99
//
1010

11-
import XCTest
12-
@testable import Histogram
11+
// swiftlint:disable identifier_name
1312

13+
@testable import Histogram
14+
import XCTest
1415

1516
final class HistogramAutosizingTests: XCTestCase {
16-
static let highestTrackableValue = UInt64(3_600) * 1_000 * 1_000 // e.g. for 1 hr in usec units
17+
private static let highestTrackableValue = UInt64(3_600) * 1_000 * 1_000 // e.g. for 1 hr in usec units
1718

1819
func testHistogramAutoSizingEdges() {
1920
var histogram = Histogram<UInt64>(numberOfSignificantValueDigits: .three)
@@ -74,7 +75,7 @@ final class HistogramAutosizingTests: XCTestCase {
7475
//histogram2.add(histogram1)
7576

7677
XCTAssert(histogram2.valuesAreEquivalent(histogram2.max, 1_000_000_000),
77-
"Max should be equivalent to 1_000_000_000")
78+
"Max should be equivalent to 1_000_000_000")
7879
}
7980

8081
func testAutoSizingAcrossContinuousRange() {

0 commit comments

Comments
 (0)