From 3f0f19a75b691ff4245802b9375cb7f6aee4d2e5 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Sat, 26 Sep 2020 15:36:22 -0700 Subject: [PATCH] Refactoring --- .../Sources/CodableBloomFilter/BitArray.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CodableBloomFilter/Sources/CodableBloomFilter/BitArray.swift b/CodableBloomFilter/Sources/CodableBloomFilter/BitArray.swift index 736b160..4b11b84 100644 --- a/CodableBloomFilter/Sources/CodableBloomFilter/BitArray.swift +++ b/CodableBloomFilter/Sources/CodableBloomFilter/BitArray.swift @@ -11,19 +11,19 @@ struct BitArray { } extension BitArray { - var bitCount: Int { bytes.count * Self.bitsInByte } + var bitCount: Int { bytes.count * UInt8.bitWidth } var data: Data { Data(bytes) } subscript(index: Int) -> Bool { get { - let (byteIndex, bitIndex) = index.quotientAndRemainder(dividingBy: Self.bitsInByte) + let (byteIndex, bitIndex) = index.quotientAndRemainder(dividingBy: UInt8.bitWidth) return bytes[byteIndex] & Self.mask(bitIndex: bitIndex) > 0 } set { - let (byteIndex, bitIndex) = index.quotientAndRemainder(dividingBy: Self.bitsInByte) + let (byteIndex, bitIndex) = index.quotientAndRemainder(dividingBy: UInt8.bitWidth) if newValue { bytes[byteIndex] |= Self.mask(bitIndex: bitIndex) @@ -47,8 +47,6 @@ extension BitArray: Codable { } private extension BitArray { - static let bitsInByte = 8 - static func mask(bitIndex: Int) -> UInt8 { UInt8(2 << (bitIndex - 1)) }