Using a real hash function for hashing a BitVector's internal state.

This commit is contained in:
Robin Sommer 2013-08-01 10:46:05 -07:00
parent 00e4369eae
commit 7ab2170641
2 changed files with 20 additions and 13 deletions

View file

@ -1,10 +1,12 @@
// See the file "COPYING" in the main distribution directory for copyright.
#include "BitVector.h"
#include <openssl/sha.h>
#include <cassert>
#include <limits>
#include "BitVector.h"
#include "Serializer.h"
#include "digest.h"
using namespace probabilistic;
@ -494,10 +496,15 @@ size_t BitVector::Hash() const
{
size_t hash = 0;
for ( size_type i = 0; i < Blocks(); ++i )
hash += bits[i];
u_char buf[SHA256_DIGEST_LENGTH];
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)

View file

@ -1,8 +1,8 @@
bf1, global_seed, 1
bf2, global_seed, 5
bf3, my_seed, 5
bf4, my_seed, 6
bf1, global_seed, 5
bf2, global_seed, 6
bf3, my_seed, 5
bf4, my_seed, 6
bf1, global_seed, 11979365913534242684
bf2, global_seed, 12550100962110750449
bf3, my_seed, 12550100962110750449
bf4, my_seed, 945716460325754659
bf1, global_seed, 12550100962110750449
bf2, global_seed, 945716460325754659
bf3, my_seed, 12550100962110750449
bf4, my_seed, 945716460325754659