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

Commitc7f6510

Browse files
Move StampLotery to poper file in the lib
1 parentb139576 commitc7f6510

File tree

5 files changed

+156
-156
lines changed

5 files changed

+156
-156
lines changed

‎blobstamper/blobstamper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
#include"dict.h"
2424
#include"galley.h"
2525
#include"stamp_enumerator.h"
26-
26+
#include"stamp_lottery.h"

‎blobstamper/helpers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ max precision
9595
}
9696

9797

98+
namespacestd
99+
{
100+
template<classT>using ref_vector = vector<reference_wrapper<T>>;
101+
}
102+
103+
98104
template<classT>classsized_ptr
99105
{
100106
private:

‎blobstamper/stamp_lottery.cpp

Whitespace-only changes.

‎blobstamper/stamp_lottery.h

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
template<classStampT>classStampLottery:publicStampT
2+
{
3+
protected:
4+
std::ref_vector<StampT> stamps;
5+
int oracle_size;
6+
intinit_oracle_size(std::ref_vector<StampT> stamps_arg);
7+
8+
int stored_min;
9+
intinit_stored_min(std::ref_vector<StampT> stamps_arg);
10+
11+
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+
15+
virtualintminSize()override;
16+
virtualintmaxSize()override;
17+
virtual std::stringExtractStr(Blob &blob)override;
18+
voidAppend(StampT & stamp);
19+
};
20+
21+
22+
template<classStampT>int
23+
StampLottery<StampT>::
24+
init_stored_min(std::ref_vector<StampT> stamps_arg)
25+
{
26+
int min = std::numeric_limits<int>::max();
27+
28+
for(StampT & stamp : stamps)
29+
{
30+
31+
if (min > stamp.minSize())
32+
min = stamp.minSize();
33+
}
34+
return min;
35+
}
36+
37+
template<classStampT>int
38+
StampLottery<StampT>::init_oracle_size(std::ref_vector<StampT> stamps_arg)
39+
{
40+
unsignedlong size = stamps_arg.size();
41+
if (size < std::numeric_limits<unsignedchar>::max())
42+
return1;
43+
if (size < std::numeric_limits<unsignedshortint>::max())
44+
return2;
45+
if (size < std::numeric_limits<unsignedint>::max())
46+
return4;
47+
return8;
48+
}
49+
50+
51+
template<classStampT>int
52+
StampLottery<StampT>::minSize()
53+
{
54+
return stored_min + oracle_size;
55+
}
56+
57+
template<classStampT>int
58+
StampLottery<StampT>::maxSize()
59+
{
60+
return -1;// FIXME this is true only for recurion case. Should fix it somehow if Lottery is used in other cases
61+
}
62+
63+
64+
template<classStampT> std::string
65+
StampLottery<StampT>::ExtractStr(Blob &blob)
66+
{
67+
unsignedlong oracle;
68+
unsignedlong oracle_max;
69+
70+
switch (oracle_size)
71+
{
72+
case1:
73+
{
74+
StampArithm<unsignedchar> stamp;
75+
oracle = stamp.ExtractValue(blob);
76+
oracle_max = std::numeric_limits<unsignedchar>::max();
77+
break;
78+
}
79+
case2:
80+
{
81+
StampArithm<unsignedshort> stamp;
82+
oracle = stamp.ExtractValue(blob);
83+
oracle_max = std::numeric_limits<unsignedshort>::max();
84+
break;
85+
}
86+
case4:
87+
{
88+
StampArithm<unsignedint> stamp;
89+
oracle = stamp.ExtractValue(blob);
90+
oracle_max = std::numeric_limits<unsignedint>::max();
91+
break;
92+
}
93+
case8:
94+
{
95+
StampArithm<unsignedlong> stamp;
96+
oracle = stamp.ExtractValue(blob);
97+
oracle_max = std::numeric_limits<unsignedlong>::max();
98+
break;
99+
}
100+
default:
101+
abort();// Should never get here
102+
}
103+
104+
/* Actually we use only stamps that short enogh to consume blob's available data*/
105+
std::ref_vector<StampT> actual_stamps;
106+
for(StampT & stamp : stamps)
107+
{
108+
if(blob.Size() < stamp.minSize())// Skip all stamps that dose not fit
109+
continue;
110+
if ( stamp.isUnbounded() ||// Unbounded is always ok
111+
stamp.maxSize() > blob.Size() ||// Variated that can consume all data is ok
112+
stamp.minSize() *2 > blob.Size()// Fixed or variated stamp that lefts less data then it's min size will also do
113+
)
114+
{
115+
actual_stamps.push_back(stamp);
116+
}
117+
}
118+
if (actual_stamps.empty())
119+
{
120+
// Add just everything that fits
121+
for(StampT & stamp : stamps)
122+
{
123+
if(blob.Size() < stamp.minSize())// Skip all stamps that dose not fit
124+
continue;
125+
actual_stamps.push_back(stamp);
126+
}
127+
}
128+
129+
if (actual_stamps.empty())
130+
throwOutOfData();// This should never happen
131+
132+
longlongindex = ((double) oracle) / oracle_max * actual_stamps.size();
133+
if (index == actual_stamps.size())index--;/* If we hit the boundary step inside a bit*/
134+
135+
StampT& stamp = actual_stamps[index];
136+
return stamp.ExtractStr(blob);
137+
}
138+
139+
140+
template<classStampT>void
141+
StampLottery<StampT>::Append(StampT & stamp)
142+
{
143+
if (stamp.minSize()<stored_min)
144+
{
145+
stored_min = stamp.minSize();
146+
}
147+
stamps.push_back(stamp);
148+
oracle_size =init_oracle_size(stamps);
149+
}

‎examples/exampleZZ.cpp

Lines changed: 0 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -7,161 +7,6 @@
77

88
#include<blobstamper/blobstamper.h>
99

10-
namespacestd
11-
{
12-
template<classT>using ref_vector = vector<reference_wrapper<T>>;
13-
}
14-
15-
template<classStampT>classStampLottery:publicStampT
16-
{
17-
protected:
18-
std::ref_vector<StampT> stamps;
19-
int oracle_size;
20-
intinit_oracle_size(std::ref_vector<StampT> stamps_arg);
21-
22-
int stored_min;
23-
intinit_stored_min(std::ref_vector<StampT> stamps_arg);
24-
25-
public:
26-
StampLottery(std::ref_vector<StampT> stamps_arg): stamps(stamps_arg), oracle_size(init_oracle_size(stamps_arg)), stored_min(init_stored_min(stamps_arg)) {};
27-
StampLottery(): stored_min(-1) {};
28-
29-
virtualintminSize()override;
30-
virtualintmaxSize()override;
31-
virtual std::stringExtractStr(Blob &blob)override;
32-
voidAppend(StampT & stamp);
33-
};
34-
35-
36-
template<classStampT>int
37-
StampLottery<StampT>::
38-
init_stored_min(std::ref_vector<StampT> stamps_arg)
39-
{
40-
int min = std::numeric_limits<int>::max();
41-
42-
for(StampT & stamp : stamps)
43-
{
44-
45-
if (min > stamp.minSize())
46-
min = stamp.minSize();
47-
}
48-
return min;
49-
}
50-
51-
template<classStampT>int
52-
StampLottery<StampT>::init_oracle_size(std::ref_vector<StampT> stamps_arg)
53-
{
54-
unsignedlong size = stamps_arg.size();
55-
if (size < std::numeric_limits<unsignedchar>::max())
56-
return1;
57-
if (size < std::numeric_limits<unsignedshortint>::max())
58-
return2;
59-
if (size < std::numeric_limits<unsignedint>::max())
60-
return4;
61-
return8;
62-
}
63-
64-
65-
template<classStampT>int
66-
StampLottery<StampT>::minSize()
67-
{
68-
return stored_min + oracle_size;
69-
}
70-
71-
template<classStampT>int
72-
StampLottery<StampT>::maxSize()
73-
{
74-
return -1;// FIXME this is true only for recurion case. Should fix it somehow if Lottery is used in other cases
75-
}
76-
77-
78-
template<classStampT> std::string
79-
StampLottery<StampT>::ExtractStr(Blob &blob)
80-
{
81-
unsignedlong oracle;
82-
unsignedlong oracle_max;
83-
84-
switch (oracle_size)
85-
{
86-
case1:
87-
{
88-
StampArithm<unsignedchar> stamp;
89-
oracle = stamp.ExtractValue(blob);
90-
oracle_max = std::numeric_limits<unsignedchar>::max();
91-
break;
92-
}
93-
case2:
94-
{
95-
StampArithm<unsignedshort> stamp;
96-
oracle = stamp.ExtractValue(blob);
97-
oracle_max = std::numeric_limits<unsignedshort>::max();
98-
break;
99-
}
100-
case4:
101-
{
102-
StampArithm<unsignedint> stamp;
103-
oracle = stamp.ExtractValue(blob);
104-
oracle_max = std::numeric_limits<unsignedint>::max();
105-
break;
106-
}
107-
case8:
108-
{
109-
StampArithm<unsignedlong> stamp;
110-
oracle = stamp.ExtractValue(blob);
111-
oracle_max = std::numeric_limits<unsignedlong>::max();
112-
break;
113-
}
114-
default:
115-
abort();// Should never get here
116-
}
117-
118-
/* Actually we use only stamps that short enogh to consume blob's available data*/
119-
std::ref_vector<StampT> actual_stamps;
120-
for(StampT & stamp : stamps)
121-
{
122-
if(blob.Size() < stamp.minSize())// Skip all stamps that dose not fit
123-
continue;
124-
if ( stamp.isUnbounded() ||// Unbounded is always ok
125-
stamp.maxSize() > blob.Size() ||// Variated that can consume all data is ok
126-
stamp.minSize() *2 > blob.Size()// Fixed or variated stamp that lefts less data then it's min size will also do
127-
)
128-
{
129-
actual_stamps.push_back(stamp);
130-
}
131-
}
132-
if (actual_stamps.empty())
133-
{
134-
// Add just everything that fits
135-
for(StampT & stamp : stamps)
136-
{
137-
if(blob.Size() < stamp.minSize())// Skip all stamps that dose not fit
138-
continue;
139-
actual_stamps.push_back(stamp);
140-
}
141-
}
142-
143-
if (actual_stamps.empty())
144-
throwOutOfData();// This should not happen
145-
146-
longlongindex = ((double) oracle) / oracle_max * actual_stamps.size();
147-
if (index == actual_stamps.size())index--;/* If we hit the boundary step inside a bit*/
148-
149-
StampT& stamp = actual_stamps[index];
150-
return stamp.ExtractStr(blob);
151-
}
152-
153-
154-
template<classStampT>void
155-
StampLottery<StampT>::Append(StampT & stamp)
156-
{
157-
if (stamp.minSize()<stored_min)
158-
{
159-
stored_min = stamp.minSize();
160-
}
161-
stamps.push_back(stamp);
162-
oracle_size =init_oracle_size(stamps);
163-
}
164-
16510

16611
classBinaryOp:publicStampBaseStr,publicGalleySetBase
16712
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp