Skip to content

Commit 8a73817

Browse files
authored
Merge pull request #2 from bertof/master
Moved methods to sbf namespace and add const keywords
2 parents e9468e9 + 8d9b9e0 commit 8a73817

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

base64.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
#include "base64.h"
2929
#include <iostream>
3030

31+
namespace sbf {
32+
3133
static const std::string base64_chars =
3234
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3335
"abcdefghijklmnopqrstuvwxyz"
3436
"0123456789+/";
3537

3638

37-
static inline bool is_base64(unsigned char c) {
39+
static inline bool is_base64(const unsigned char c) {
3840
return (isalnum(c) || (c == '+') || (c == '/'));
3941
}
4042

@@ -121,3 +123,5 @@ std::string base64_decode(std::string const& encoded_string) {
121123

122124
return ret;
123125
}
126+
127+
} // namespace sbf

base64.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#include <string>
22

3+
namespace sbf {
4+
35
std::string base64_encode(unsigned char const* , unsigned int len);
46
std::string base64_decode(std::string const& s);
7+
8+
} // namespace sbf

sbf.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void SBF::SetHashDigestLength()
6161
// char *d is the input of the hash value
6262
// size_t n is the input length
6363
// unsigned char *md is where the output should be written
64-
void SBF::Hash(char *d, size_t n, unsigned char *md)
64+
void SBF::Hash(char *d, size_t n, unsigned char *md) const
6565
{
6666
switch(this->HASH_family){
6767
case 1:
@@ -222,7 +222,7 @@ void SBF::SetCell(unsigned int index, int area)
222222

223223

224224
// Returns the area label stored at the specified index
225-
int SBF::GetCell(unsigned int index)
225+
int SBF::GetCell(unsigned int index) const
226226
{
227227
int area;
228228
switch (this->cell_size){
@@ -251,7 +251,7 @@ int SBF::GetCell(unsigned int index)
251251
// Prints the filter and related statistics to the standart output
252252
// mode: 0 prints SBF stats only
253253
// mode: 1 prints SBF information and the full SBF content
254-
void SBF::PrintFilter(int mode)
254+
void SBF::PrintFilter(int mode) const
255255
{
256256
int potential_elements;
257257

@@ -432,7 +432,7 @@ void SBF::Insert(char *string, int size, int area)
432432
// belongs to a set, 0 otherwise.
433433
// char *string the element to be verified
434434
// int size length of the element
435-
int SBF::Check(char *string, int size)
435+
int SBF::Check(char *string, int size) const
436436
{
437437
char* buffer = new char[size];
438438
int area = 0;
@@ -622,14 +622,14 @@ void SBF::SetAreaFpp()
622622

623623

624624
// Returns the number of inserted elements for the input area
625-
int SBF::GetAreaMembers(int area)
625+
int SBF::GetAreaMembers(int area) const
626626
{
627627
return this->AREA_members[area];
628628
}
629629

630630

631631
// Returns the sparsity of the entire SBF
632-
float SBF::GetFilterSparsity()
632+
float SBF::GetFilterSparsity() const
633633
{
634634
float ret;
635635
int sum = 0;
@@ -644,7 +644,7 @@ float SBF::GetFilterSparsity()
644644

645645
// Returns the a-priori false positive probability over the entire filter
646646
// (i.e. not area-specific)
647-
float SBF::GetFilterAPrioriFpp()
647+
float SBF::GetFilterAPrioriFpp() const
648648
{
649649
double p;
650650

@@ -658,7 +658,7 @@ float SBF::GetFilterAPrioriFpp()
658658

659659
// Returns the a-posteriori false positive probability over the entire filter
660660
// (i.e. not area-specific)
661-
float SBF::GetFilterFpp()
661+
float SBF::GetFilterFpp() const
662662
{
663663
double p;
664664
int c = 0;
@@ -675,7 +675,7 @@ float SBF::GetFilterFpp()
675675

676676

677677
// Returns the expected emersion value for the input area
678-
float SBF::GetExpectedAreaEmersion(int area)
678+
float SBF::GetExpectedAreaEmersion(int area) const
679679
{
680680
double p;
681681
int nfill = 0;
@@ -692,7 +692,7 @@ float SBF::GetExpectedAreaEmersion(int area)
692692

693693

694694
// Returns the emersion value for the input area
695-
float SBF::GetAreaEmersion(int area)
695+
float SBF::GetAreaEmersion(int area) const
696696
{
697697
float ret, a, b;
698698
if((this->AREA_members[area]==0) || (this->HASH_number==0)) ret = -1;

sbf.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ namespace sbf {
8181

8282
// Private methods (commented in the sbf.cpp)
8383
void SetCell(unsigned int index, int area);
84-
int GetCell(unsigned int index);
84+
int GetCell(unsigned int index) const;
8585
void CreateHashSalt(std::string path);
8686
void LoadHashSalt(std::string path);
8787
void SetHashDigestLength();
88-
void Hash(char *d, size_t n, unsigned char *md);
88+
void Hash(char *d, size_t n, unsigned char *md) const;
8989

9090

9191
public:
@@ -226,21 +226,21 @@ namespace sbf {
226226

227227

228228
// Public methods (commented in the sbf.cpp)
229-
void PrintFilter(int mode);
229+
void PrintFilter(int mode) const;
230230
void SaveToDisk(std::string path, int mode);
231231
void Insert(char *string, int size, int area);
232-
int Check(char *string, int size);
233-
int GetAreaMembers(int area);
234-
float GetFilterSparsity();
235-
float GetFilterFpp();
236-
float GetFilterAPrioriFpp();
232+
int Check(char *string, int size) const;
233+
int GetAreaMembers(int area) const;
234+
float GetFilterSparsity() const;
235+
float GetFilterFpp() const;
236+
float GetFilterAPrioriFpp() const;
237237
void SetAreaFpp();
238238
void SetAPrioriAreaFpp();
239239
void SetAreaIsep();
240240
void SetAPrioriAreaIsep();
241241
void SetExpectedAreaCells();
242-
float GetExpectedAreaEmersion(int area);
243-
float GetAreaEmersion(int area);
242+
float GetExpectedAreaEmersion(int area) const;
243+
float GetAreaEmersion(int area) const;
244244
};
245245

246246
} //namespace sbf

0 commit comments

Comments
 (0)