Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit97772cd

Browse files
Fix StampLottery to have proper maxSize value
1 parentaba9b53 commit97772cd

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

‎blobstamper/stamp_lottery.h

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ template<class StampT> class StampLottery: public StampT
77

88
int stored_min;
99
intinit_stored_min(std::ref_vector<StampT> stamps_arg);
10+
int stored_max;
11+
intinit_stored_max(std::ref_vector<StampT> stamps_arg);
1012

1113
public:
12-
StampLottery(std::ref_vector<StampT> stamps_arg): stamps(stamps_arg), oracle_size(init_oracle_size(stamps_arg)), stored_min(init_stored_min(stamps_arg)) {};
13-
StampLottery(): stored_min(-1) {};
14+
StampLottery(std::ref_vector<StampT> stamps_arg): stamps(stamps_arg),
15+
oracle_size(init_oracle_size(stamps_arg)),
16+
stored_min(init_stored_min(stamps_arg)),
17+
stored_max(init_stored_max(stamps_arg)) {};
18+
StampLottery(): stored_min(-1), stored_max(-2) {};
1419

1520
virtualintminSize()override;
1621
virtualintmaxSize()override;
@@ -34,6 +39,24 @@ init_stored_min(std::ref_vector<StampT> stamps_arg)
3439
return min;
3540
}
3641

42+
template<classStampT>int
43+
StampLottery<StampT>::
44+
init_stored_max(std::ref_vector<StampT> stamps_arg)
45+
{
46+
int max =0;
47+
48+
for(StampT & stamp : stamps)
49+
{
50+
if (stamp.maxSize() == -1)
51+
return -1;
52+
53+
if (max < stamp.maxSize())
54+
max = stamp.maxSize();
55+
}
56+
return max;
57+
}
58+
59+
3760
template<classStampT>int
3861
StampLottery<StampT>::init_oracle_size(std::ref_vector<StampT> stamps_arg)
3962
{
@@ -48,6 +71,11 @@ StampLottery<StampT>::init_oracle_size(std::ref_vector<StampT> stamps_arg)
4871
}
4972

5073

74+
75+
/* StampLottery is used for recustion. Lottery contains trams that uses this very lottery
76+
Calculating sizes on fly leads to infinite recrsion. So we calculate sizes when lottery
77+
item is added, and use stored value, when it is needed*/
78+
5179
template<classStampT>int
5280
StampLottery<StampT>::minSize()
5381
{
@@ -57,7 +85,9 @@ StampLottery<StampT>::minSize()
5785
template<classStampT>int
5886
StampLottery<StampT>::maxSize()
5987
{
60-
return -1;// FIXME this is true only for recurion case. Should fix it somehow if Lottery is used in other cases
88+
if (stored_max == -1)
89+
return -1;
90+
return stored_max + oracle_size;
6191
}
6292

6393

@@ -140,10 +170,21 @@ StampLottery<StampT>::ExtractStr(Blob &blob)
140170
template<classStampT>void
141171
StampLottery<StampT>::Append(StampT & stamp)
142172
{
143-
if (stamp.minSize()<stored_min)
173+
if (stamp.maxSize() == -1)
144174
{
145-
stored_min = stamp.minSize();
175+
stored_max = -1;
176+
}else
177+
{
178+
if (stamp.maxSize() > stored_max)/* this case includes case when stored_max have not beed initialized (==-2)*/
179+
stored_max = stamp.maxSize();
146180
}
181+
182+
if (stored_min == -1)/* stored_min have not been initializes*/
183+
stored_min = stamp.minSize();
184+
185+
if (stamp.minSize() < stored_min)
186+
stored_min = stamp.minSize();
187+
147188
stamps.push_back(stamp);
148189
oracle_size =init_oracle_size(stamps);
149190
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp