Skip to content

Commit 00c234f

Browse files
committed
Add const keyword to the methods without side effects
1 parent e9468e9 commit 00c234f

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

base64.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ static const std::string base64_chars =
3434
"0123456789+/";
3535

3636

37-
static inline bool is_base64(unsigned char c) {
37+
static inline bool is_base64(unsigned char c) const {
3838
return (isalnum(c) || (c == '+') || (c == '/'));
3939
}
4040

41-
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
41+
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) const {
4242
std::string ret;
4343
int i = 0;
4444
int j = 0;
@@ -81,7 +81,7 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
8181

8282
}
8383

84-
std::string base64_decode(std::string const& encoded_string) {
84+
std::string base64_decode(std::string const& encoded_string) const {
8585
int in_len = encoded_string.size();
8686
int i = 0;
8787
int j = 0;

base64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#include <string>
22

3-
std::string base64_encode(unsigned char const* , unsigned int len);
4-
std::string base64_decode(std::string const& s);
3+
std::string base64_encode(unsigned char const* , unsigned int len) const;
4+
std::string base64_decode(std::string const& s) const;

sbf.cpp

Lines changed: 10 additions & 10 deletions
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

Lines changed: 10 additions & 10 deletions
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)