Skip to content

Commit

Permalink
Bug fix attempt with header/source separation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ujvl committed Dec 20, 2018
1 parent e0bc172 commit 9e00bfe
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 29 deletions.
Expand Up @@ -364,7 +364,7 @@ class confluo_universal_sketch {
}

std::vector<confluo_substream_summary<counter_t>> substream_summaries_;
hash_manager<size_t> layer_hashes_;
hash_manager layer_hashes_;

schema_t schema_;
column_t column_;
Expand Down
4 changes: 2 additions & 2 deletions libconfluo/confluo/container/sketch/count_sketch.h
Expand Up @@ -167,8 +167,8 @@ class count_sketch {
size_t width_; // number of buckets

std::vector<atomic_counter_t> counters_;
hash_manager<T> bucket_hash_manager_;
hash_manager<T> sign_hash_manager_;
hash_manager bucket_hash_manager_;
hash_manager sign_hash_manager_;

};

Expand Down
33 changes: 8 additions & 25 deletions libconfluo/confluo/container/sketch/hash_manager.h
Expand Up @@ -13,16 +13,11 @@ namespace sketch {
class pairwise_indep_hash {

public:
static const size_t PRIME = 39916801UL;
static const size_t PRIME;

pairwise_indep_hash()
: pairwise_indep_hash(0, 0) {
}
pairwise_indep_hash();

pairwise_indep_hash(size_t a, size_t b)
: a_(a),
b_(b) {
}
pairwise_indep_hash(size_t a, size_t b);

template<typename T>
size_t apply(T elem) const {
Expand All @@ -35,47 +30,35 @@ class pairwise_indep_hash {
return (a_ * elem + b_) % PRIME;
}

static pairwise_indep_hash generate_random() {
return { utils::rand_utils::rand_uint64(PRIME), utils::rand_utils::rand_uint64(PRIME) };
}
static pairwise_indep_hash generate_random();

private:
size_t a_, b_;

};

const size_t pairwise_indep_hash::PRIME;

template<typename T>
class hash_manager {
public:

/**
* Constructor.
* @param num_hashes number of hashes
*/
hash_manager(size_t num_hashes = 0)
: hashes_() {
this->guarantee_initialized(num_hashes);
}
explicit hash_manager(size_t num_hashes = 0);

/**
* Guarantee enough hashes are intialized.
* @param num_hashes number of hashes
*/
void guarantee_initialized(size_t num_hashes) {
size_t cur_size = hashes_.size();
size_t num_new_hashes = num_hashes > cur_size ? num_hashes - cur_size : 0;
for (size_t i = 0; i < num_new_hashes; i++) {
hashes_.push_back(pairwise_indep_hash::generate_random());
}
}
void guarantee_initialized(size_t num_hashes);

/**
* Hash element.
* @param hash_id id of hash to use
* @param elem element to hash
* @return hashed value
*/
template<typename T>
size_t hash(size_t hash_id, T elem) const {
return hashes_[hash_id].template apply<T>(elem);
}
Expand Down
2 changes: 1 addition & 1 deletion libconfluo/confluo/container/sketch/universal_sketch.h
Expand Up @@ -363,7 +363,7 @@ class universal_sketch {
}

std::vector<substream_summary<T, counter_t>> substream_summaries_;
hash_manager<T> layer_hashes_;
hash_manager layer_hashes_;

bool precise_hh_;

Expand Down
36 changes: 36 additions & 0 deletions libconfluo/src/container/sketch/hash_manager.cc
@@ -0,0 +1,36 @@
#include "container/sketch/hash_manager.h"

namespace confluo {
namespace sketch {

const size_t pairwise_indep_hash::PRIME = 39916801UL;

pairwise_indep_hash::pairwise_indep_hash()
: pairwise_indep_hash(0, 0) {
}

pairwise_indep_hash::pairwise_indep_hash(size_t a, size_t b)
: a_(a),
b_(b) {
}


pairwise_indep_hash pairwise_indep_hash::generate_random() {
return { utils::rand_utils::rand_uint64(PRIME), utils::rand_utils::rand_uint64(PRIME) };
}

hash_manager::hash_manager(size_t num_hashes)
: hashes_() {
this->guarantee_initialized(num_hashes);
}

void hash_manager::guarantee_initialized(size_t num_hashes) {
size_t cur_size = hashes_.size();
size_t num_new_hashes = num_hashes > cur_size ? num_hashes - cur_size : 0;
for (size_t i = 0; i < num_new_hashes; i++) {
hashes_.push_back(pairwise_indep_hash::generate_random());
}
}

}
}

0 comments on commit 9e00bfe

Please sign in to comment.