mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 15:18:20 +00:00
Change bloom filter's dependence on size_t.
That type can vary across platforms, but factored in to a bloom filter's internal state, e.g. size of the seed.
This commit is contained in:
parent
f7a31ab004
commit
774dadfe9a
7 changed files with 11 additions and 13 deletions
|
@ -492,10 +492,8 @@ BitVector::size_type BitVector::FindNext(size_type i) const
|
||||||
return block ? bi * bits_per_block + lowest_bit(block) : find_from(bi + 1);
|
return block ? bi * bits_per_block + lowest_bit(block) : find_from(bi + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BitVector::Hash() const
|
uint64_t BitVector::Hash() const
|
||||||
{
|
{
|
||||||
size_t hash = 0;
|
|
||||||
|
|
||||||
u_char buf[SHA256_DIGEST_LENGTH];
|
u_char buf[SHA256_DIGEST_LENGTH];
|
||||||
SHA256_CTX ctx;
|
SHA256_CTX ctx;
|
||||||
sha256_init(&ctx);
|
sha256_init(&ctx);
|
||||||
|
@ -504,7 +502,7 @@ size_t BitVector::Hash() const
|
||||||
sha256_update(&ctx, &bits[i], sizeof(bits[i]));
|
sha256_update(&ctx, &bits[i], sizeof(bits[i]));
|
||||||
|
|
||||||
sha256_final(&ctx, buf);
|
sha256_final(&ctx, buf);
|
||||||
return *reinterpret_cast<size_t*>(buf); // Use the first bytes as seed.
|
return *reinterpret_cast<uint64_t*>(buf); // Use the first bytes as seed.
|
||||||
}
|
}
|
||||||
|
|
||||||
BitVector::size_type BitVector::lowest_bit(block_type block)
|
BitVector::size_type BitVector::lowest_bit(block_type block)
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace probabilistic {
|
||||||
*/
|
*/
|
||||||
class BitVector : public SerialObj {
|
class BitVector : public SerialObj {
|
||||||
public:
|
public:
|
||||||
typedef size_t block_type;
|
typedef uint64_t block_type;
|
||||||
typedef size_t size_type;
|
typedef size_t size_type;
|
||||||
typedef bool const_reference;
|
typedef bool const_reference;
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return The hash.
|
* @return The hash.
|
||||||
*/
|
*/
|
||||||
size_t Hash() const;
|
uint64_t Hash() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes the bit vector.
|
* Serializes the bit vector.
|
||||||
|
|
|
@ -111,7 +111,7 @@ BasicBloomFilter* BasicBloomFilter::Clone() const
|
||||||
|
|
||||||
std::string BasicBloomFilter::InternalState() const
|
std::string BasicBloomFilter::InternalState() const
|
||||||
{
|
{
|
||||||
return fmt("%" PRIu64, (uint64_t)bits->Hash());
|
return fmt("%" PRIu64, bits->Hash());
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicBloomFilter::BasicBloomFilter()
|
BasicBloomFilter::BasicBloomFilter()
|
||||||
|
@ -219,7 +219,7 @@ CountingBloomFilter* CountingBloomFilter::Clone() const
|
||||||
|
|
||||||
string CountingBloomFilter::InternalState() const
|
string CountingBloomFilter::InternalState() const
|
||||||
{
|
{
|
||||||
return fmt("%" PRIu64, (uint64_t)cells->Hash());
|
return fmt("%" PRIu64, cells->Hash());
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPLEMENT_SERIAL(CountingBloomFilter, SER_COUNTINGBLOOMFILTER)
|
IMPLEMENT_SERIAL(CountingBloomFilter, SER_COUNTINGBLOOMFILTER)
|
||||||
|
|
|
@ -153,7 +153,7 @@ CounterVector operator|(const CounterVector& x, const CounterVector& y)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CounterVector::Hash() const
|
uint64_t CounterVector::Hash() const
|
||||||
{
|
{
|
||||||
return bits->Hash();
|
return bits->Hash();
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return The hash.
|
* @return The hash.
|
||||||
*/
|
*/
|
||||||
size_t Hash() const;
|
uint64_t Hash() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes the bit vector.
|
* Serializes the bit vector.
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
using namespace probabilistic;
|
using namespace probabilistic;
|
||||||
|
|
||||||
size_t Hasher::MakeSeed(const void* data, size_t size)
|
uint64_t Hasher::MakeSeed(const void* data, size_t size)
|
||||||
{
|
{
|
||||||
u_char buf[SHA256_DIGEST_LENGTH];
|
u_char buf[SHA256_DIGEST_LENGTH];
|
||||||
SHA256_CTX ctx;
|
SHA256_CTX ctx;
|
||||||
|
@ -29,7 +29,7 @@ size_t Hasher::MakeSeed(const void* data, size_t size)
|
||||||
}
|
}
|
||||||
|
|
||||||
sha256_final(&ctx, buf);
|
sha256_final(&ctx, buf);
|
||||||
return *reinterpret_cast<size_t*>(buf); // Use the first bytes as seed.
|
return *reinterpret_cast<uint64_t*>(buf); // Use the first bytes as seed.
|
||||||
}
|
}
|
||||||
|
|
||||||
Hasher::digest_vector Hasher::Hash(const HashKey* key) const
|
Hasher::digest_vector Hasher::Hash(const HashKey* key) const
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return A seed suitable for hashers.
|
* @return A seed suitable for hashers.
|
||||||
*/
|
*/
|
||||||
static size_t MakeSeed(const void* data, size_t size);
|
static uint64_t MakeSeed(const void* data, size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue