2020-05-22 16:18:41 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2020, The PurpleI2P Project
|
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
2016-12-09 17:08:03 +03:00
|
|
|
#ifndef BLOOM_FILTER_H_
|
|
|
|
#define BLOOM_FILTER_H_
|
|
|
|
#include <memory>
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
|
|
|
|
2016-12-09 17:10:08 +03:00
|
|
|
/** @brief interface for bloom filter */
|
|
|
|
struct IBloomFilter
|
|
|
|
{
|
2016-12-09 17:08:03 +03:00
|
|
|
|
2016-12-09 17:10:08 +03:00
|
|
|
/** @brief destructor */
|
2016-12-09 21:42:00 +03:00
|
|
|
virtual ~IBloomFilter() {};
|
2016-12-09 17:10:08 +03:00
|
|
|
/** @brief add entry to bloom filter, return false if filter hit otherwise return true */
|
|
|
|
virtual bool Add(const uint8_t * data, std::size_t len) = 0;
|
|
|
|
/** @brief optionally decay old entries */
|
2016-12-09 21:42:00 +03:00
|
|
|
virtual void Decay() = 0;
|
2016-12-09 17:10:08 +03:00
|
|
|
};
|
2016-12-09 17:08:03 +03:00
|
|
|
|
2016-12-09 17:10:08 +03:00
|
|
|
typedef std::shared_ptr<IBloomFilter> BloomFilterPtr;
|
2016-12-09 17:08:03 +03:00
|
|
|
|
2016-12-09 17:10:08 +03:00
|
|
|
/** @brief create bloom filter */
|
|
|
|
BloomFilterPtr BloomFilter(std::size_t capacity = 1024 * 8);
|
2016-12-09 17:08:03 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|