Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

changed dict in stamp constructor from reference to shared ptr #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions blobstamper/stamp_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
#include "stamp_dict.h"

int
StampDict::ChooseStampSize(DictBase & dict)
StampDict::ChooseStampSize(std::shared_ptr<DictBase> dict)
{
if (dict.size()<= UCHAR_MAX+1)
if (dict->size() <= UCHAR_MAX+1)
{
stamp_max_value = UCHAR_MAX;
return 1;
}
if (dict.size()<= USHRT_MAX+1)
if (dict->size() <= USHRT_MAX+1)
{
stamp_max_value = USHRT_MAX;
return 2;
}
if (dict.size()<= UINT_MAX+1)
if (dict->size() <= UINT_MAX+1)
{
stamp_max_value = UINT_MAX;
return 4;
Expand Down Expand Up @@ -75,7 +75,7 @@ StampDict::ExtractStr(Blob &blob)
printf("StampDict::ExtractStr: Something is really wrong\n"); // FIXME better to throw something here :-)
exit(1);
}
long long actual_index = ((double) index_oracle) / stamp_max_value * dict.size();
if ( actual_index == dict.size()) actual_index--; /* If we hit the boundary step inside a bit*/
return dict.get(actual_index);
long long actual_index = ((double) index_oracle) / stamp_max_value * dict->size();
if ( actual_index == dict->size()) actual_index--; /* If we hit the boundary step inside a bit*/
return dict->get(actual_index);
}
7 changes: 4 additions & 3 deletions blobstamper/stamp_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "stamp.h"
#include "stamp_arithm.h"
#include "dict.h"
#include <memory>

class StampDict: public StampBaseStr
{
Expand All @@ -34,13 +35,13 @@ class StampDict: public StampBaseStr
StampArithm<unsigned int> stamp32;
StampArithm<unsigned long long> stamp64;
int stamp_size;
DictBase& dict;
std::shared_ptr<DictBase> dict;
unsigned long long stamp_max_value;

int ChooseStampSize(DictBase & dict);
int ChooseStampSize(std::shared_ptr<DictBase> dict);

public:
StampDict(DictBase & dict_arg) : dict{dict_arg}, stamp_size{ChooseStampSize(dict_arg)} {};
StampDict(std::shared_ptr<DictBase> dict_arg) : dict(dict_arg), stamp_size(ChooseStampSize(dict_arg)) {};
std::string ExtractStr(Blob &blob) override;
int minSize() override {return stamp_size;}
int maxSize() override {return stamp_size;}
Expand Down
2 changes: 1 addition & 1 deletion examples/exampleZZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ char data[] =

StampArithm<unsigned char> stampс;

DictLCAlphaSmall dict;
auto dict = std::make_shared<DictLCAlphaSmall>();
StampDict stamp_dict(dict);

StampLottery4Recursion<StampBaseStr> stamp_lot({stampс, stamp_dict});
Expand Down
2 changes: 1 addition & 1 deletion t/120-stamp_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ main()
{
TEST_START(4);
{ /* 1..4 */
DictTest dict;
auto dict = std::make_shared<DictTest>();
StampDict stamp(dict);
Blob blob((char *) sample, 4);
std::string s;
Expand Down