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

Commitfa84d62

Browse files
Move Oracle related things to separate file
1 parentba7f4f6 commitfa84d62

File tree

6 files changed

+80
-30
lines changed

6 files changed

+80
-30
lines changed

‎blobstamper/galley.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include"stamp.h"
2525
#include"stamp_arithm.h"
2626
#include"galley.h"
27-
27+
#include"oracle.h"
2828

2929
int
3030
GalleyVectorBase::minSize()

‎blobstamper/galley.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,13 @@
1919
#ifndef GALLEY_H
2020
#defineGALLEY_H
2121

22-
23-
#include<limits>
2422
#include<vector>
2523
#include<functional>// for std::reference_wrapper
2624

2725
#include"stamp.h"
2826
#include"blob.h"
2927

3028

31-
#defineORACLE_TYPEunsignedshortint
32-
#defineORACLE_STAMP StampArithm<ORACLE_TYPE>
33-
#defineORACLE_SIZEsizeof(ORACLE_TYPE)
34-
#defineORACLE_MAX std::numeric_limits<ORACLE_TYPE>::max()
35-
3629
classGalleyBase:publicvirtual StampBase
3730
/* Galley is a kind of stamp, somwhere deep inside.*/
3831
/* You can inherit it, and make a stamp out of it*/
@@ -63,7 +56,6 @@ template<class T> class GalleyVectorStrStampBase: public GalleyVectorStr, publi
6356
{
6457
public:
6558
GalleyVectorStrStampBase(): GalleyVectorStr(std::make_shared<T>()) {};
66-
6759
};
6860

6961

‎blobstamper/oracle.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/******************************************************************************
2+
*
3+
* Copyright 2021-2023 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+
19+
#include<math.h>
20+
21+
#include"oracle.h"
22+
23+
size_t
24+
OracleProportion(ORACLE_TYPE oracle,size_t min,size_t max)
25+
{
26+
/* Sorry explanation is in Russian. PR translation if you can*/
27+
/* Считаем пропорацию, с округлением вниз.
28+
* Диапазон увиличиваем на единицу, чтобы хвост диапазона пресказания при
29+
* округлении вниз как раз попадал в последний элемент целевого диапозона.
30+
* Разброс предсказания увеличиваем на единицу, так чтобы ровно на конец
31+
* хвоста диапазона предсказания не попасть никогда и тогда он не округлиться
32+
* в max + 1*/
33+
size_t delta = max - min +1;
34+
size_t res =floor(((float) oracle) / ((float) ORACLE_MAX +1) * delta );
35+
return min + res;
36+
}
37+

‎blobstamper/oracle.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/******************************************************************************
2+
*
3+
* Copyright 2021-2023 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+
19+
#ifndef STAMP_ORACLE_H
20+
#defineSTAMP_ORACLE_H
21+
22+
#include<cstddef>
23+
#include<limits>
24+
25+
#defineORACLE_TYPEunsignedshortint
26+
#defineORACLE_STAMP StampArithm<ORACLE_TYPE>
27+
#defineORACLE_SIZEsizeof(ORACLE_TYPE)
28+
#defineORACLE_MAX std::numeric_limits<ORACLE_TYPE>::max()
29+
30+
size_tOracleProportion(ORACLE_TYPE oracle,size_t min,size_t max);
31+
32+
#endif/* STAMP_ORACLE_H*/
33+

‎t/300-galley.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include<tap++/tap++.h>
2727

2828
#include"blobstamper/blobstamper.h"
29+
#include"blobstamper/oracle.h"
2930

3031
#include"test-chars-stamps.h"
3132

‎t/321-galley-recursion-experiments_2.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include"blobstamper/blobstamper.h"
3030
#include"blobstamper/dict.h"
31+
#include"blobstamper/oracle.h"
3132

3233
#include"test-chars-stamps.h"
3334

@@ -44,20 +45,6 @@ unsigned char bin_sample[]= {49, 22, 152, 226, 89, 119, 247, 115, 43, 42, 243, 7
4445
//class TestRNode2;
4546
//class TestRNode3;
4647

47-
size_t
48-
Proportion(ORACLE_TYPE oracle,size_t min,size_t max)
49-
{
50-
/* Sorry explanation is in Russian. PR translation if you can*/
51-
/* Считаем пропорацию, с округлением вниз.
52-
* Диапазон увиличиваем на единицу, чтобы хвост диапазона пресказания при
53-
* округлении вниз как раз попадал в последний элемент целевого диапозона.
54-
* Разброс предсказания увеличиваем на единицу, так чтобы ровно на конец
55-
* хвоста диапазона предсказания не попасть никогда и тогда он не округлиться
56-
* в max + 1*/
57-
size_t delta = max - min +1;
58-
size_t res =floor(((float) oracle) / ((float) ORACLE_MAX +1) * delta );
59-
return min + res;
60-
}
6148

6249
classPoolPickerStamp :publicvirtual StampBaseStr
6350
{
@@ -122,7 +109,7 @@ fprintf(stderr, "*");
122109
}
123110
}
124111

125-
size_tindex =Proportion(oracle,0, target_pool.size() -1);
112+
size_tindex =OracleProportion(oracle,0, target_pool.size() -1);
126113
return target_pool[index].lock()->ExtractStr(blob);
127114
}
128115

@@ -243,12 +230,12 @@ main()
243230

244231
TEST_START(6);
245232
{
246-
is(Proportion(0,0,255),0);
247-
is(Proportion(255,0,255),0);
248-
is(Proportion(256,0,255),1);
249-
is(Proportion(65535,0,255),255);
250-
is(Proportion(65535-255,0,255),255);
251-
is(Proportion(65535-256,0,255),254);
233+
is(OracleProportion(0,0,255),0);
234+
is(OracleProportion(255,0,255),0);
235+
is(OracleProportion(256,0,255),1);
236+
is(OracleProportion(65535,0,255),255);
237+
is(OracleProportion(65535-255,0,255),255);
238+
is(OracleProportion(65535-256,0,255),254);
252239

253240
}
254241
TEST_END;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp