mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Using a real hash function for hashing a BitVector's internal state.
This commit is contained in:
parent
00e4369eae
commit
7ab2170641
2 changed files with 20 additions and 13 deletions
|
@ -1,10 +1,12 @@
|
||||||
// See the file "COPYING" in the main distribution directory for copyright.
|
// See the file "COPYING" in the main distribution directory for copyright.
|
||||||
|
|
||||||
#include "BitVector.h"
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include "BitVector.h"
|
||||||
#include "Serializer.h"
|
#include "Serializer.h"
|
||||||
|
#include "digest.h"
|
||||||
|
|
||||||
using namespace probabilistic;
|
using namespace probabilistic;
|
||||||
|
|
||||||
|
@ -494,10 +496,15 @@ size_t BitVector::Hash() const
|
||||||
{
|
{
|
||||||
size_t hash = 0;
|
size_t hash = 0;
|
||||||
|
|
||||||
for ( size_type i = 0; i < Blocks(); ++i )
|
u_char buf[SHA256_DIGEST_LENGTH];
|
||||||
hash += bits[i];
|
SHA256_CTX ctx;
|
||||||
|
sha256_init(&ctx);
|
||||||
|
|
||||||
return hash;
|
for ( size_type i = 0; i < Blocks(); ++i )
|
||||||
|
sha256_update(&ctx, &bits[i], sizeof(bits[i]));
|
||||||
|
|
||||||
|
sha256_final(&ctx, buf);
|
||||||
|
return *reinterpret_cast<size_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)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
bf1, global_seed, 1
|
bf1, global_seed, 11979365913534242684
|
||||||
bf2, global_seed, 5
|
bf2, global_seed, 12550100962110750449
|
||||||
bf3, my_seed, 5
|
bf3, my_seed, 12550100962110750449
|
||||||
bf4, my_seed, 6
|
bf4, my_seed, 945716460325754659
|
||||||
bf1, global_seed, 5
|
bf1, global_seed, 12550100962110750449
|
||||||
bf2, global_seed, 6
|
bf2, global_seed, 945716460325754659
|
||||||
bf3, my_seed, 5
|
bf3, my_seed, 12550100962110750449
|
||||||
bf4, my_seed, 6
|
bf4, my_seed, 945716460325754659
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue