1
+ /* *****************************************************************************
2
+ *
3
+ * Copyright 2021 Nikolay Shaplov (Postgres Professional)
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ ******************************************************************************/
18
+
1
19
template <class StampT > class StampLottery : public StampT
2
20
{
3
21
protected:
@@ -15,15 +33,39 @@ template<class StampT> class StampLottery: public StampT
15
33
oracle_size (init_oracle_size(stamps_arg)),
16
34
stored_min(init_stored_min(stamps_arg)),
17
35
stored_max(init_stored_max(stamps_arg)) {};
18
- StampLottery (): stored_min(-1 ), stored_max(-2 ) {};
36
+ StampLottery (): stored_min(-1 ), stored_max(-2 ), oracle_size( 1 ) {};
19
37
20
38
virtual int minSize () override ;
21
39
virtual int maxSize () override ;
40
+
41
+ virtual bool soft_maxsize_filter (StampT &stamp, int data_size) {return true ;}; /* Allow to skip stamps that would leave to much data unused. But not active here*/
42
+
22
43
virtual std::string ExtractStr (Blob &blob) override ;
23
44
void Append (StampT & stamp);
24
45
};
25
46
26
47
48
+ template <class StampT > class StampLottery4Recursion : public StampLottery <StampT>
49
+ {
50
+ public:
51
+ StampLottery4Recursion (std::ref_vector<StampT> stamps_arg): StampLottery<StampT>(stamps_arg) {};
52
+ StampLottery4Recursion (): StampLottery<StampT>() {};
53
+ virtual bool soft_maxsize_filter (StampT &stamp, int data_size) override ;
54
+ };
55
+
56
+
57
+ template <class StampT > bool
58
+ StampLottery4Recursion<StampT>::
59
+ soft_maxsize_filter (StampT &stamp, int data_size)
60
+ {
61
+ if ( stamp.isUnbounded () || // Unbounded is always ok
62
+ stamp.maxSize () > data_size || // Variated that can consume all data is ok
63
+ stamp.minSize () + stamp.maxSize () > data_size // Fixed or variated stamp that lefts less data then it's min size will also do
64
+ )
65
+ return true ;
66
+ return false ;
67
+ }
68
+
27
69
template <class StampT > int
28
70
StampLottery<StampT>::
29
71
init_stored_min (std::ref_vector<StampT> stamps_arg)
@@ -136,14 +178,9 @@ StampLottery<StampT>::ExtractStr(Blob &blob)
136
178
for (StampT & stamp : stamps)
137
179
{
138
180
if (blob.Size () < stamp.minSize ()) // Skip all stamps that dose not fit
139
- continue ;
140
- if ( stamp.isUnbounded () || // Unbounded is always ok
141
- stamp.maxSize () > blob.Size () || // Variated that can consume all data is ok
142
- stamp.minSize () * 2 > blob.Size () // Fixed or variated stamp that lefts less data then it's min size will also do
143
- )
144
- {
181
+ continue ;
182
+ if (soft_maxsize_filter (stamp, blob.Size ()))
145
183
actual_stamps.push_back (stamp);
146
- }
147
184
}
148
185
if (actual_stamps.empty ())
149
186
{
0 commit comments