bloomfilt.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef TOR_BLOOMFILT_H
  6. #define TOR_BLOOMFILT_H
  7. #include "orconfig.h"
  8. #include "lib/cc/torint.h"
  9. #include "lib/container/bitarray.h"
  10. /** A set of elements, implemented as a Bloom filter. */
  11. typedef struct bloomfilt_t bloomfilt_t;
  12. /** How many 64-bit siphash values to extract per item. */
  13. #define BLOOMFILT_N_HASHES 2
  14. /** How much key material do we need to randomize hashes? */
  15. #define BLOOMFILT_KEY_LEN (BLOOMFILT_N_HASHES * 16)
  16. struct sipkey;
  17. typedef uint64_t (*bloomfilt_hash_fn)(const struct sipkey *key,
  18. const void *item);
  19. void bloomfilt_add(bloomfilt_t *set, const void *item);
  20. int bloomfilt_probably_contains(const bloomfilt_t *set, const void *item);
  21. bloomfilt_t *bloomfilt_new(int max_elements,
  22. bloomfilt_hash_fn hashfn,
  23. const uint8_t *random_key);
  24. void bloomfilt_free_(bloomfilt_t* set);
  25. #define bloomfilt_free(set) FREE_AND_NULL(bloomfilt_t, bloomfilt_free_, (set))
  26. #endif /* !defined(TOR_BLOOMFILT_H) */