mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +00:00
Small fixes and simplifications.
This commit is contained in:
parent
d5126a1339
commit
012e09c5c4
3 changed files with 9 additions and 11 deletions
|
@ -140,7 +140,7 @@ bool BloomFilter::DoUnserialize(UnserialInfo* info)
|
||||||
return false;
|
return false;
|
||||||
hash_ = new hash_policy(static_cast<size_t>(k));
|
hash_ = new hash_policy(static_cast<size_t>(k));
|
||||||
uint64 elements;
|
uint64 elements;
|
||||||
if ( UNSERIALIZE(&elements) )
|
if ( ! UNSERIALIZE(&elements) )
|
||||||
return false;
|
return false;
|
||||||
elements_ = static_cast<size_t>(elements);
|
elements_ = static_cast<size_t>(elements);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -94,15 +94,14 @@ protected:
|
||||||
* A functor that computes a universal hash function.
|
* A functor that computes a universal hash function.
|
||||||
* @tparam Codomain An integral type.
|
* @tparam Codomain An integral type.
|
||||||
*/
|
*/
|
||||||
template <typename Codomain = HashType>
|
|
||||||
class Hasher {
|
class Hasher {
|
||||||
public:
|
public:
|
||||||
template <typename Domain>
|
template <typename T>
|
||||||
Codomain operator()(const Domain& x) const
|
HashType operator()(const T& x) const
|
||||||
{
|
{
|
||||||
return h3_(&x, sizeof(x));
|
return h3_(&x, sizeof(x));
|
||||||
}
|
}
|
||||||
Codomain operator()(const void* x, size_t n) const
|
HashType operator()(const void* x, size_t n) const
|
||||||
{
|
{
|
||||||
return h3_(x, n);
|
return h3_(x, n);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +109,7 @@ protected:
|
||||||
// FIXME: The hardcoded value of 36 comes from UHASH_KEY_SIZE defined in
|
// FIXME: The hardcoded value of 36 comes from UHASH_KEY_SIZE defined in
|
||||||
// Hash.h. I do not know how this value impacts the hash function behavior
|
// Hash.h. I do not know how this value impacts the hash function behavior
|
||||||
// so I'll just copy it verbatim. (Matthias)
|
// so I'll just copy it verbatim. (Matthias)
|
||||||
H3<Codomain, 36> h3_;
|
H3<HashType, 36> h3_;
|
||||||
};
|
};
|
||||||
|
|
||||||
HashPolicy(size_t k) : k_(k) { }
|
HashPolicy(size_t k) : k_(k) { }
|
||||||
|
@ -125,12 +124,11 @@ private:
|
||||||
class DefaultHashing : public HashPolicy {
|
class DefaultHashing : public HashPolicy {
|
||||||
public:
|
public:
|
||||||
DefaultHashing(size_t k) : HashPolicy(k), hashers_(k) { }
|
DefaultHashing(size_t k) : HashPolicy(k), hashers_(k) { }
|
||||||
virtual ~DefaultHashing() { }
|
|
||||||
|
|
||||||
virtual HashVector Hash(const void* x, size_t n) const;
|
virtual HashVector Hash(const void* x, size_t n) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector< Hasher<HashType> > hashers_;
|
std::vector<Hasher> hashers_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,13 +137,12 @@ private:
|
||||||
class DoubleHashing : public HashPolicy {
|
class DoubleHashing : public HashPolicy {
|
||||||
public:
|
public:
|
||||||
DoubleHashing(size_t k) : HashPolicy(k) { }
|
DoubleHashing(size_t k) : HashPolicy(k) { }
|
||||||
virtual ~DoubleHashing() { }
|
|
||||||
|
|
||||||
virtual HashVector Hash(const void* x, size_t n) const;
|
virtual HashVector Hash(const void* x, size_t n) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Hasher<HashType> hasher1_;
|
Hasher hasher1_;
|
||||||
Hasher<HashType> hasher2_;
|
Hasher hasher2_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -533,6 +533,7 @@ bool BloomFilterVal::Typify(BroType* type)
|
||||||
if ( type_ )
|
if ( type_ )
|
||||||
return false;
|
return false;
|
||||||
type_ = type;
|
type_ = type;
|
||||||
|
type_->Ref();
|
||||||
TypeList* tl = new TypeList(type_);
|
TypeList* tl = new TypeList(type_);
|
||||||
tl->Append(type_);
|
tl->Append(type_);
|
||||||
hash_ = new CompositeHash(tl);
|
hash_ = new CompositeHash(tl);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue