-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTLBloomFilter.h
36 lines (28 loc) · 1.34 KB
/
TLBloomFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// TLBloomFilter.h
// TLCommon
//
// Created by Joshua Bleecher Snyder on 11/2/09.
//
#import <Foundation/Foundation.h>
@interface TLBloomFilter : NSObject {
@private
NSUInteger length;
NSUInteger hashes;
NSMutableData *data;
}
// bloom filter-related calculations
+ (NSUInteger)numberOfHashesToMinimizeFalsePositivesForLength:(NSUInteger)numberOfBytes capacity:(NSUInteger)numberOfEntries;
+ (NSUInteger)lengthToAchieveFalsePositiveRate:(float)falsePositiveRate forCapacity:(NSUInteger)numberOfEntries;
// initialization
- (id)initWithCapacity:(NSUInteger)numberOfEntries falsePositiveRate:(float)falsePositiveRate; // numberOfEntries MUST be > 0, throws an exception otherwise
- (id)initWithLength:(NSUInteger)numberOfBytes hashes:(NSUInteger)numberOfHashFunctions; // only use if you know what you're doing; length MUST be > 0
// population and querying
- (void)addData:(NSData *)dataRepresentingAnObject;
- (BOOL)containsData:(NSData *)dataRepresentingAnObject;
// for saving and restoring, the ghetto way; todo: properly serialize, etc.
- (id)initWithData:(NSMutableData *)savedBloomFilterData hashes:(NSUInteger)numberOfHashFunctions; // data length MUST be > 0
@property(nonatomic, assign, readonly) NSUInteger length;
@property(nonatomic, assign, readonly) NSUInteger hashes;
@property(nonatomic, retain, readonly) NSMutableData *data;
@end