mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 01:58:20 +00:00
Create hash policies through factory.
This commit is contained in:
parent
85668e7054
commit
e6e5f4926f
4 changed files with 15 additions and 6 deletions
|
@ -34,8 +34,6 @@ BloomFilter* BloomFilter::Unserialize(UnserialInfo* info)
|
|||
bool BloomFilter::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BLOOMFILTER, SerialObj);
|
||||
// FIXME: Since we have a fixed hashing policy, we just serialize the
|
||||
// information needed to reconstruct it.
|
||||
if ( ! SERIALIZE(static_cast<uint16>(hash_->K())) )
|
||||
return false;
|
||||
return SERIALIZE_STR(hash_->Name().c_str(), hash_->Name().size());
|
||||
|
@ -50,8 +48,7 @@ bool BloomFilter::DoUnserialize(UnserialInfo* info)
|
|||
const char* name;
|
||||
if ( ! UNSERIALIZE_STR(&name, 0) )
|
||||
return false;
|
||||
// FIXME: for now Bloom filters always use double hashing.
|
||||
hash_ = new DefaultHashing(k, name);
|
||||
hash_ = HashPolicy::Create(k, name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,11 @@ size_t Hasher::compute_seed(size_t seed, const std::string& extra)
|
|||
}
|
||||
|
||||
|
||||
HashPolicy* HashPolicy::Create(size_t k, const std::string& name)
|
||||
{
|
||||
return new DefaultHashing(k, name);
|
||||
}
|
||||
|
||||
HashPolicy::HashPolicy(size_t k, const std::string& name)
|
||||
: k_(k), name_(name)
|
||||
{
|
||||
|
|
|
@ -42,6 +42,13 @@ private:
|
|||
*/
|
||||
class HashPolicy {
|
||||
public:
|
||||
/**
|
||||
* Constructs the hashing policy used by the implementation. This factory
|
||||
* function exists because the HashingPolicy class hierachy is not yet
|
||||
* serializable.
|
||||
*/
|
||||
static HashPolicy* Create(size_t k, const std::string& name);
|
||||
|
||||
typedef Hasher::hash_type hash_type;
|
||||
typedef std::vector<hash_type> hash_vector;
|
||||
|
||||
|
|
|
@ -5008,7 +5008,7 @@ function bloomfilter_basic_init%(fp: double, capacity: count,
|
|||
|
||||
size_t cells = BasicBloomFilter::M(fp, capacity);
|
||||
size_t optimal_k = BasicBloomFilter::K(cells, capacity);
|
||||
const HashPolicy* hp = new DefaultHashing(optimal_k, name->CheckString());
|
||||
const HashPolicy* hp = HashPolicy::Create(optimal_k, name->CheckString());
|
||||
return new BloomFilterVal(new BasicBloomFilter(hp, cells));
|
||||
%}
|
||||
|
||||
|
@ -5029,7 +5029,7 @@ function bloomfilter_basic_init%(fp: double, capacity: count,
|
|||
function bloomfilter_counting_init%(k: count, cells: count, max: count,
|
||||
name: string &default=""%): opaque of bloomfilter
|
||||
%{
|
||||
const HashPolicy* hp = new DefaultHashing(k, name->CheckString());
|
||||
const HashPolicy* hp = HashPolicy::Create(k, name->CheckString());
|
||||
uint16 width = 0;
|
||||
while ( max >>= 1 )
|
||||
++width;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue