Correction: L33
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
namespace GMS {
|
||||
|
||||
@@ -177,8 +178,7 @@ class L33 {
|
||||
// cerr<<UB.size()<<endl;
|
||||
// for(auto [val, _]: UB)
|
||||
// {
|
||||
// cerr<<"> "<<get<0>(val)<<' '<<get<1>(val)<<'
|
||||
// '<<get<2>(val)<<endl;
|
||||
// cerr<<"> "<<get<0>(val)<<' '<<get<1>(val)<<' '<<get<2>(val)<<endl;
|
||||
// }
|
||||
// }
|
||||
assert(it_UB != UB.end());
|
||||
@@ -254,21 +254,35 @@ class L33 {
|
||||
pair<VALUE, K_LIST> Pull() {
|
||||
BLOCK S0, S1;
|
||||
|
||||
// auto it = D0.begin();
|
||||
// while (S0.size() < M + 1 && it != D0.end()) {
|
||||
// S0.splice(S0.end(), *it->second);
|
||||
// blocks.erase(it->second);
|
||||
|
||||
// it = D0.erase(it);
|
||||
// }
|
||||
|
||||
// it = D1.begin();
|
||||
// while (S1.size() < M + 1 && it != D1.end()) {
|
||||
// S1.splice(S0.end(), *it->second);
|
||||
// blocks.erase(it->second);
|
||||
|
||||
// UB.erase(it->first);
|
||||
// it = D1.erase(it);
|
||||
// }
|
||||
|
||||
auto it = D0.begin();
|
||||
while (S0.size() < M + 1 && it != D0.end()) {
|
||||
S0.splice(S0.end(), *it->second);
|
||||
blocks.erase(it->second);
|
||||
|
||||
it = D0.erase(it);
|
||||
auto& block = *it->second;
|
||||
for (auto& kv : block) S0.insert(S0.end(), kv);
|
||||
it++;
|
||||
}
|
||||
|
||||
it = D1.begin();
|
||||
while (S1.size() < M + 1 && it != D1.end()) {
|
||||
S1.splice(S0.end(), *it->second);
|
||||
blocks.erase(it->second);
|
||||
|
||||
UB.erase(it->first);
|
||||
it = D1.erase(it);
|
||||
auto& block = *it->second;
|
||||
for (auto& kv : block) S1.insert(S1.end(), kv);
|
||||
it++;
|
||||
}
|
||||
|
||||
KV_LIST S;
|
||||
@@ -277,15 +291,9 @@ class L33 {
|
||||
for (auto& item : S0) S.emplace_back(std::move(item));
|
||||
for (auto& item : S1) S.emplace_back(std::move(item));
|
||||
|
||||
for (auto [a, b] : S) ptr.erase(a);
|
||||
|
||||
if (D1.empty()) {
|
||||
auto it_BLIST = blocks.emplace(blocks.end());
|
||||
auto it_ILIST = D1.emplace(D1.end(), B, it_BLIST);
|
||||
UB[B] = it_ILIST;
|
||||
}
|
||||
|
||||
if (S.size() <= M) {
|
||||
for (auto [a, b] : S) Delete(a);
|
||||
|
||||
K_LIST s;
|
||||
s.reserve(S.size());
|
||||
for (auto [a, b] : S) s.push_back(a);
|
||||
@@ -303,11 +311,14 @@ class L33 {
|
||||
// for (auto [a, b] : S) cerr<<get<0>(b)<<' '<<get<1>(b)<<'
|
||||
// '<<get<2>(b)<<endl;
|
||||
|
||||
KV_LIST R(make_move_iterator(nth + 1), make_move_iterator(S.end()));
|
||||
S.resize(M);
|
||||
nth = S.begin(), advance(nth, M);
|
||||
VALUE x = nth->second;
|
||||
|
||||
VALUE x = R.front().second;
|
||||
for (auto [a, b] : R) x = min(x, b);
|
||||
while (nth != S.end()) {
|
||||
x = min(x, nth->second);
|
||||
nth++;
|
||||
}
|
||||
S.resize(M);
|
||||
|
||||
// cerr<<"DEBUG M!! : "<<M<<endl;
|
||||
// cerr<<"DEBUG R!!"<<endl;
|
||||
@@ -320,7 +331,8 @@ class L33 {
|
||||
|
||||
// cerr<<endl;
|
||||
|
||||
BatchPrepend(R);
|
||||
// BatchPrepend(R);
|
||||
for (auto [a, b] : S) Delete(a);
|
||||
|
||||
K_LIST s;
|
||||
s.reserve(S.size());
|
||||
@@ -330,23 +342,22 @@ class L33 {
|
||||
}
|
||||
bool empty() const { return ptr.empty(); }
|
||||
|
||||
void _debug(ostream& os)
|
||||
{
|
||||
os<<"D0: "<<endl;
|
||||
for(auto [B, it_BLIST]:D0)
|
||||
{
|
||||
os<<"["<<B<<"] : ";
|
||||
auto &block = *it_BLIST;
|
||||
for(auto [key, val] : block) os << "(" << key << " : " << val << ") ";
|
||||
os<<endl;
|
||||
void _debug(ostream& os) {
|
||||
os << "D0: " << endl;
|
||||
for (auto [B, it_BLIST] : D0) {
|
||||
os << "[" << B << "] : ";
|
||||
auto& block = *it_BLIST;
|
||||
for (auto [key, val] : block)
|
||||
os << "(" << key << " : " << val << ") ";
|
||||
os << endl;
|
||||
}
|
||||
os<<"D1: "<<endl;
|
||||
for(auto [B, it_BLIST]:D1)
|
||||
{
|
||||
os<<"["<<B<<"] : ";
|
||||
auto &block = *it_BLIST;
|
||||
for(auto [key, val] : block) os << "(" << key << " : " << val << ") ";
|
||||
os<<endl;
|
||||
os << "D1: " << endl;
|
||||
for (auto [B, it_BLIST] : D1) {
|
||||
os << "[" << B << "] : ";
|
||||
auto& block = *it_BLIST;
|
||||
for (auto [key, val] : block)
|
||||
os << "(" << key << " : " << val << ") ";
|
||||
os << endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
// #include <limits>
|
||||
#include <random>
|
||||
|
||||
using uint = unsigned int;
|
||||
|
||||
TEST(L33_test, debug_small) {
|
||||
const unsigned seed = 998244353;
|
||||
const uint N = 10, M = 1, MX = 1e9;
|
||||
@@ -11,52 +13,50 @@ TEST(L33_test, debug_small) {
|
||||
std::mt19937 gen(seed);
|
||||
std::uniform_int_distribution<int> dis(1, MX);
|
||||
|
||||
GMS::L33<int,int> D(M, MX);
|
||||
std::map<int,int> mp;
|
||||
GMS::L33<int, int> D(M, MX);
|
||||
std::map<int, int> mp;
|
||||
|
||||
std::vector<int> keys;
|
||||
for(int i=1;i<=N;i++) keys.push_back(i);
|
||||
for (uint i = 1; i <= N; i++) keys.push_back(i);
|
||||
|
||||
std::shuffle(keys.begin(), keys.end(), gen);
|
||||
|
||||
for(auto key:keys)
|
||||
{
|
||||
for (auto key : keys) {
|
||||
int val = dis(gen);
|
||||
std::cerr<<key<<": "<<val<<std::endl;
|
||||
// std::cerr<<key<<": "<<val<<std::endl;
|
||||
|
||||
mp[val] = key;
|
||||
|
||||
D.Insert(key, val);
|
||||
}
|
||||
|
||||
std::cerr<<"[!] mp: "<<std::endl;
|
||||
for(auto [val, key] : mp)
|
||||
std::cerr<<key<<": "<<val<<std::endl;
|
||||
// std::cerr<<"[!] mp: "<<std::endl;
|
||||
// for(auto [val, key] : mp)
|
||||
// std::cerr<<key<<": "<<val<<std::endl;
|
||||
|
||||
D._debug(std::cerr);
|
||||
// D._debug(std::cerr);
|
||||
|
||||
std::cerr<<"[!] D: "<<std::endl;
|
||||
// std::cerr<<"[!] D: "<<std::endl;
|
||||
int bef = 0;
|
||||
while(!D.empty())
|
||||
{
|
||||
while (!D.empty()) {
|
||||
auto [B, keys] = D.Pull();
|
||||
|
||||
std::cerr<<"[!] new pull; B : "<<B<<" ("<<keys.size()<<')'<<": ";
|
||||
for(auto i:keys) std::cerr<<i<<' ';
|
||||
std::cerr<<std::endl;
|
||||
// std::cerr<<"[!] new pull; B : "<<B<<" ("<<keys.size()<<')'<<": ";
|
||||
// for(auto i:keys) std::cerr<<i<<' ';
|
||||
// std::cerr<<std::endl;
|
||||
|
||||
D._debug(std::cerr);
|
||||
// D._debug(std::cerr);
|
||||
|
||||
EXPECT_LT(bef, B);
|
||||
bef = B;
|
||||
std::cerr<<std::endl;
|
||||
// std::cerr<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(L33_test, DISABLED_emptying_test1) {
|
||||
const double inf = 100;
|
||||
TEST(L33_test, emptying_test1) {
|
||||
const double inf = 1000;
|
||||
const unsigned seed = 998244353;
|
||||
const uint N = 2328, M = 10, MX = 1e9;
|
||||
const uint N = 232800, M = 170, MX = 1e9;
|
||||
|
||||
std::mt19937 gen(seed);
|
||||
std::uniform_int_distribution<int> dis(1, MX);
|
||||
@@ -65,20 +65,22 @@ TEST(L33_test, DISABLED_emptying_test1) {
|
||||
GMS::L33<int, double> D(M, inf);
|
||||
|
||||
std::vector<int> vec;
|
||||
for (int i = 1; i <= N; i++) vec.push_back(i);
|
||||
for (uint i = 1; i <= N; i++) vec.push_back(i);
|
||||
|
||||
std::shuffle(vec.begin(), vec.end(), gen);
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (uint i = 0; i < N; i++) {
|
||||
D.Insert(vec[i], valdis(gen));
|
||||
}
|
||||
|
||||
int cnt = 0; double bef = -inf;
|
||||
int cnt = 0;
|
||||
double bef = -inf;
|
||||
|
||||
while(!D.empty())
|
||||
{
|
||||
while (!D.empty()) {
|
||||
auto [B, v] = D.Pull();
|
||||
// std::cerr<<B<<' '<<v.size()<<std::endl;
|
||||
// for(auto i:v) std::cerr<<i<<' ';
|
||||
// std::cerr<<std::endl;
|
||||
cnt += v.size();
|
||||
|
||||
EXPECT_TRUE(D.empty() || (v.size() == M));
|
||||
@@ -91,3 +93,89 @@ TEST(L33_test, DISABLED_emptying_test1) {
|
||||
int result = 2 + 2;
|
||||
EXPECT_EQ(result, 4);
|
||||
}
|
||||
|
||||
TEST(L33_test, emptying_test2) {
|
||||
const double inf = 1000;
|
||||
const unsigned seed = 993244853;
|
||||
const uint N = 2320000, M = 1700000;
|
||||
|
||||
std::mt19937 gen(seed);
|
||||
std::uniform_real_distribution<double> valdis(-inf, inf);
|
||||
|
||||
GMS::L33<int, double> D(M, inf);
|
||||
|
||||
std::vector<int> vec;
|
||||
for (uint i = 1; i <= N; i++) vec.push_back(i);
|
||||
|
||||
std::shuffle(vec.begin(), vec.end(), gen);
|
||||
|
||||
std::vector<std::pair<int, double> > v;
|
||||
for (uint i = 0; i < N; i++) {
|
||||
v.push_back({vec[i], valdis(gen)});
|
||||
}
|
||||
|
||||
D.BatchPrepend(v);
|
||||
// D._debug(std::cerr);
|
||||
|
||||
int cnt = 0;
|
||||
double bef = -inf;
|
||||
|
||||
while (!D.empty()) {
|
||||
auto [B, v] = D.Pull();
|
||||
cnt += v.size();
|
||||
|
||||
EXPECT_TRUE(D.empty() || (v.size() == M));
|
||||
EXPECT_LE(bef, B);
|
||||
bef = B;
|
||||
}
|
||||
|
||||
EXPECT_EQ(cnt, N);
|
||||
|
||||
int result = 2 + 2;
|
||||
EXPECT_EQ(result, 4);
|
||||
}
|
||||
|
||||
TEST(L33_test, emptying_test3) {
|
||||
const double inf = 10099990;
|
||||
const unsigned seed = 999244153;
|
||||
const uint N = 2320080, M = 180000;
|
||||
|
||||
std::mt19937 gen(seed);
|
||||
std::uniform_real_distribution<double> valdis(-inf, inf);
|
||||
|
||||
GMS::L33<int, double> D(M, inf*2);
|
||||
|
||||
std::vector<int> vec;
|
||||
for (uint i = 1; i <= N; i++) vec.push_back(i);
|
||||
|
||||
std::shuffle(vec.begin(), vec.end(), gen);
|
||||
|
||||
std::vector<std::pair<int, double> > v;
|
||||
std::set<int> keys;
|
||||
for (uint i = 0; i < N; i++) {
|
||||
D.Insert(vec[i], valdis(gen) + inf);
|
||||
keys.insert(vec[i]);
|
||||
|
||||
v.push_back({vec[i]+N/2, valdis(gen)});
|
||||
keys.insert(vec[i]+N/2);
|
||||
}
|
||||
|
||||
D.BatchPrepend(v);
|
||||
|
||||
int cnt = 0;
|
||||
double bef = -inf;
|
||||
|
||||
while (!D.empty()) {
|
||||
auto [B, v] = D.Pull();
|
||||
cnt += v.size();
|
||||
|
||||
EXPECT_TRUE(D.empty() || (v.size() == M));
|
||||
EXPECT_LE(bef, B);
|
||||
bef = B;
|
||||
}
|
||||
|
||||
EXPECT_EQ(cnt, keys.size());
|
||||
|
||||
int result = 2 + 2;
|
||||
EXPECT_EQ(result, 4);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user