Accept set instead of array in Bloom filter initializer

This commit is contained in:
Justin Mazzocchi 2020-09-05 19:51:15 -07:00
parent c7f6972fdb
commit fc2aa33fae
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
3 changed files with 11 additions and 3 deletions

View file

@ -11,8 +11,9 @@ public struct BloomFilter<T: DeterministicallyHashable>: Codable {
private var data: BitArray
public init(hashers: [DeterministicHasher], byteCount: Int) {
self.hashers = hashers
public init(hashers: Set<DeterministicHasher>, byteCount: Int) {
// Sort the hashers for consistent decoding output
self.hashers = Array(hashers.sorted { $0.rawValue < $1.rawValue })
data = BitArray(byteCount: byteCount)
}
}

View file

@ -15,7 +15,7 @@ final class CodableBloomFilterTests: XCTestCase {
}
func testCoding() throws {
var sut = BloomFilter<String>(hashers: [.djb2, .sdbm], byteCount: 8)
var sut = BloomFilter<String>(hashers: [.sdbm, .djb2], byteCount: 8)
let expectedSerialization = Data(#"{"data":"ABAAAAACAJA=","hashers":["djb2","sdbm"]}"#.utf8)
sut.insert("lol")

View file

@ -42,6 +42,7 @@
D0C7D4D924F7616A001EBDBB /* KingfisherOptionsInfo+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0C7D46E24F76169001EBDBB /* KingfisherOptionsInfo+Extensions.swift */; };
D0C7D4DA24F7616A001EBDBB /* View+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0C7D46F24F76169001EBDBB /* View+Extensions.swift */; };
D0C7D4DC24F7616A001EBDBB /* Data+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0C7D47124F76169001EBDBB /* Data+Extensions.swift */; };
D0C93E0B25047DC100442506 /* CodableBloomFilter in Frameworks */ = {isa = PBXBuildFile; productRef = D0C93E0A25047DC100442506 /* CodableBloomFilter */; };
D0E2C1D124FD97F000854680 /* ViewModels in Frameworks */ = {isa = PBXBuildFile; productRef = D0E2C1D024FD97F000854680 /* ViewModels */; };
D0E5361C24E3EB4D00FB1CE1 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0E5361B24E3EB4D00FB1CE1 /* NotificationService.swift */; };
D0E5362024E3EB4D00FB1CE1 /* Notification Service Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = D0E5361924E3EB4D00FB1CE1 /* Notification Service Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
@ -138,6 +139,7 @@
D06B492324D4611300642749 /* KingfisherSwiftUI in Frameworks */,
D0E2C1D124FD97F000854680 /* ViewModels in Frameworks */,
D0BECB9F2501D9AD002C1B13 /* PreviewViewModels in Frameworks */,
D0C93E0B25047DC100442506 /* CodableBloomFilter in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -334,6 +336,7 @@
D06B492224D4611300642749 /* KingfisherSwiftUI */,
D0E2C1D024FD97F000854680 /* ViewModels */,
D0BECB9E2501D9AD002C1B13 /* PreviewViewModels */,
D0C93E0A25047DC100442506 /* CodableBloomFilter */,
);
productName = "Metatext (iOS)";
productReference = D047FA8C24C3E21200AF17C5 /* Metatext.app */;
@ -873,6 +876,10 @@
isa = XCSwiftPackageProductDependency;
productName = PreviewViewModels;
};
D0C93E0A25047DC100442506 /* CodableBloomFilter */ = {
isa = XCSwiftPackageProductDependency;
productName = CodableBloomFilter;
};
D0E2C1D024FD97F000854680 /* ViewModels */ = {
isa = XCSwiftPackageProductDependency;
productName = ViewModels;