Skip to content

Commit

Permalink
Store FPR for quick access. Only generated if needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinChu committed Jul 31, 2020
1 parent 4f38eb5 commit 3b2a990
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion BloomFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BloomFilter
, m_dFPR(0)
, m_nEntry(0)
, m_tEntry(0)
, m_FPR(0)
{}

/* De novo filter constructor.
Expand All @@ -69,6 +70,7 @@ class BloomFilter
, m_dFPR(0)
, m_nEntry(0)
, m_tEntry(0)
, m_FPR(0)
{
initSize(m_size);
}
Expand All @@ -85,6 +87,7 @@ class BloomFilter
, m_dFPR(fpr)
, m_nEntry(0)
, m_tEntry(0)
, m_FPR(0)
{
if (m_hashNum == 0) {
m_hashNum = calcOptiHashNum(m_dFPR);
Expand Down Expand Up @@ -340,7 +343,19 @@ class BloomFilter
/*
* Return FPR based on popcount
*/
double getFPR() const { return pow(double(getPop()) / double(m_size), double(m_hashNum)); }
double getFPR()
{
m_FPR = pow(double(getPop()) / double(m_size), double(m_hashNum));
return m_FPR;
}

/*
* Return FPR based on popcount assuming m_FPR has been already calcuated
*/
double getFPRPrecompute() const
{
return m_FPR;
}

/*
* Return FPR based on number of inserted elements
Expand Down Expand Up @@ -426,6 +441,7 @@ class BloomFilter
double m_dFPR;
uint64_t m_nEntry;
uint64_t m_tEntry;
double m_FPR;
static constexpr const char* MAGIC_HEADER_STRING = "BTLBloomFilter_v1";
};

Expand Down

0 comments on commit 3b2a990

Please sign in to comment.