bloomfilt.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. /**
  8. * \file bloomfilt.h
  9. *
  10. * \brief Header for bloomfilt.c
  11. **/
  12. #include "orconfig.h"
  13. #include "lib/cc/torint.h"
  14. #include "lib/container/bitarray.h"
  15. /** A set of elements, implemented as a Bloom filter. */
  16. typedef struct bloomfilt_t bloomfilt_t;
  17. /** How many 64-bit siphash values to extract per item. */
  18. #define BLOOMFILT_N_HASHES 2
  19. /** How much key material do we need to randomize hashes? */
  20. #define BLOOMFILT_KEY_LEN (BLOOMFILT_N_HASHES * 16)
  21. struct sipkey;
  22. typedef uint64_t (*bloomfilt_hash_fn)(const struct sipkey *key,
  23. const void *item);
  24. void bloomfilt_add(bloomfilt_t *set, const void *item);
  25. int bloomfilt_probably_contains(const bloomfilt_t *set, const void *item);
  26. bloomfilt_t *bloomfilt_new(int max_elements,
  27. bloomfilt_hash_fn hashfn,
  28. const uint8_t *random_key);
  29. void bloomfilt_free_(bloomfilt_t* set);
  30. #define bloomfilt_free(set) FREE_AND_NULL(bloomfilt_t, bloomfilt_free_, (set))
  31. #endif /* !defined(TOR_BLOOMFILT_H) */