aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/storageutil/bloomfilter.cpp
blob: 3afa9a8bbf26063e54c21047e63a3465c96c59b2 (plain) (blame)
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
37
38
39
40
41
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "bloomfilter.h"
#include <cstdlib>
#include <cstring>

BloomFilter::BloomFilter(int size, int hashes, uint32_t *buf)
    : _size(size),
      _hashes(hashes),
      _buf(buf),
      _mine(false)
{
    if (!_buf) {
        _buf = new uint32_t[(_size / 32) + 1];
        memset(_buf, 0, ((_size / 32) + 1) * sizeof(uint32_t));
        _mine = true;
    }
}

BloomFilter::~BloomFilter()
{
    if (_mine) {
        delete [] _buf;
    }
}

/*
int main(int argc, char **argv)
{
    int size = atoi(argv[1]);
    int hashes = atoi(argv[2]);
    char buf[1000];
    BloomFilter bloom(size, hashes);

    while (fgets(buf, sizeof(buf), stdin)) {
        if (bloom.check(buf, true)) {
            printf("matched %s\n", buf);
        }
    }
}
*/