bus-bloom.c revision b26fa1a2fbcfee7d03b0c8fd15ec3aa64ae70b9f
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "bus-bloom.h"
#include "siphash24.h"
#include "util.h"
}
static const sd_id128_t hash_keys[] = {
};
static void bloom_add_data(
unsigned k, /* Number of hash functions */
const void *data, /* Data to hash */
size_t n) { /* Size of data to hash in bytes */
uint64_t h;
uint64_t m;
unsigned w, i, c = 0;
unsigned hash_index;
assert(k > 0);
/* Determine bits in filter */
m = size * 8;
/* Determine how many bytes we need to generate a bit index 0..m for this filter */
/* Make sure we have enough hash keys to generate m * k bits
* of hash value. Note that SipHash24 generates 64 bits of
* hash value for each 128 bits of hash key. */
for (i = 0, hash_index = 0; i < k; i++) {
uint64_t p = 0;
unsigned d;
for (d = 0; d < w; d++) {
if (c <= 0) {
c += 8;
}
c--;
}
p &= m - 1;
}
/* log_debug("bloom: adding <%.*s>", (int) n, (char*) data); */
}
size_t n;
char *c;
assert(a);
assert(b);
c = alloca(n + 1);
}
void bloom_add_prefixes(uint64_t filter[], size_t size, unsigned k, const char *a, const char *b, char sep) {
size_t n;
char *c, *p;
assert(a);
assert(b);
c = alloca(n + 1);
strcpy(p, b);
for (;;) {
char *e;
if (!e)
break;
*(e + 1) = 0;
if (e == p)
break;
*e = 0;
}
}
uint64_t m;
unsigned w;
if (size <= 0)
return false;
if (k <= 0)
return false;
m = size * 8;
if (w > sizeof(uint64_t))
return false;
return false;
return true;
}