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

Commit 53cc471

Browse files
kostyafipГригорьев Костяnataraj-hates-MS-for-stealing-github
committed
changed dict in stamp constructor from reference to shared ptr (#1)
* changed dict in stamp constructor from reference to shared ptr --------- Co-authored-by: Григорьев Костя <kostyafip@mail.ru> Co-authored-by: nataraj-hates-MS-for-stealing-github <48326335+nataraj-hates-MS-for-stealing-github@users.noreply.github.com>
1 parent d8f0863 commit 53cc471

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

blobstamper/stamp_dict.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222
#include "stamp_dict.h"
2323

2424
int
25-
StampDict::ChooseStampSize(DictBase & dict)
25+
StampDict::ChooseStampSize(std::shared_ptr<DictBase> dict)
2626
{
27-
if (dict.size()<= UCHAR_MAX+1)
27+
if (dict->size() <= UCHAR_MAX+1)
2828
{
2929
stamp_max_value = UCHAR_MAX;
3030
return 1;
3131
}
32-
if (dict.size()<= USHRT_MAX+1)
32+
if (dict->size() <= USHRT_MAX+1)
3333
{
3434
stamp_max_value = USHRT_MAX;
3535
return 2;
3636
}
37-
if (dict.size()<= UINT_MAX+1)
37+
if (dict->size() <= UINT_MAX+1)
3838
{
3939
stamp_max_value = UINT_MAX;
4040
return 4;
@@ -75,7 +75,7 @@ StampDict::ExtractStr(Blob &blob)
7575
printf("StampDict::ExtractStr: Something is really wrong\n"); // FIXME better to throw something here :-)
7676
exit(1);
7777
}
78-
long long actual_index = ((double) index_oracle) / stamp_max_value * dict.size();
79-
if ( actual_index == dict.size()) actual_index--; /* If we hit the boundary step inside a bit*/
80-
return dict.get(actual_index);
78+
long long actual_index = ((double) index_oracle) / stamp_max_value * dict->size();
79+
if ( actual_index == dict->size()) actual_index--; /* If we hit the boundary step inside a bit*/
80+
return dict->get(actual_index);
8181
}

blobstamper/stamp_dict.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "stamp.h"
2626
#include "stamp_arithm.h"
2727
#include "dict.h"
28+
#include <memory>
2829

2930
class StampDict: public StampBaseStr
3031
{
@@ -34,13 +35,13 @@ class StampDict: public StampBaseStr
3435
StampArithm<unsigned int> stamp32;
3536
StampArithm<unsigned long long> stamp64;
3637
int stamp_size;
37-
DictBase& dict;
38+
std::shared_ptr<DictBase> dict;
3839
unsigned long long stamp_max_value;
3940

40-
int ChooseStampSize(DictBase & dict);
41+
int ChooseStampSize(std::shared_ptr<DictBase> dict);
4142

4243
public:
43-
StampDict(DictBase & dict_arg) : dict{dict_arg}, stamp_size{ChooseStampSize(dict_arg)} {};
44+
StampDict(std::shared_ptr<DictBase> dict_arg) : dict(dict_arg), stamp_size(ChooseStampSize(dict_arg)) {};
4445
std::string ExtractStr(Blob &blob) override;
4546
int minSize() override {return stamp_size;}
4647
int maxSize() override {return stamp_size;}

examples/exampleZZ.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ char data[] =
5454

5555
StampArithm<unsigned char> stampс;
5656

57-
DictLCAlphaSmall dict;
57+
auto dict = std::make_shared<DictLCAlphaSmall>();
5858
StampDict stamp_dict(dict);
5959

6060
StampLottery4Recursion<StampBaseStr> stamp_lot({stampс, stamp_dict});

t/120-stamp_dict.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ main()
4848
{
4949
TEST_START(4);
5050
{ /* 1..4 */
51-
DictTest dict;
51+
auto dict = std::make_shared<DictTest>();
5252
StampDict stamp(dict);
5353
Blob blob((char *) sample, 4);
5454
std::string s;

0 commit comments

Comments
 (0)