提交 30c5c22e 编写于 作者: D Daniel Larimer 提交者: GitHub

Merge pull request #553 from EOSIO/547-update-key64x64x64-object-index

Update key64x64x64 object index
......@@ -5,16 +5,16 @@
#include "test_api.hpp"
int primary[11] = {0,1,2,3,4,5,6,7,8,9,10};
int secondary[11] = {7,0,1,3,6,9,2,4,5,10,8};
int tertiary[11] = {0,1,2,3,4,5,6,7,8,9,10};
int secondary[11] = {7,0,1,3,6,9,10,2,4,5,8};
int tertiary[11] = {0,10,1,2,4,3,5,6,7,8,9};
int primary_lb[11] = {0,0,0,3,3,3,6,7,7,9,9};
int secondary_lb[11] = {0,0,2,0,2,2,0,7,8,0,2};
int tertiary_lb[11] = {0,1,2,3,4,5,6,7,8,9,10};
int secondary_lb[11] = {0,0,10,0,10,10,0,7,8,0,10};
int tertiary_lb[11] = {0,1,2,3,2,5,6,7,8,9,0};
int primary_ub[11] = {3,3,3,6,6,6,7,9,9,-1,-1};
int secondary_ub[11] = {2,2,8,2,8,8,2,0,-1,2,8};
int tertiary_ub[11] = {1,2,3,4,5,6,7,8,9,10,-1};
int secondary_ub[11] = {10,10,8,10,8,8,10,0,-1,10,8};
int tertiary_ub[11] = {1,2,3,5,3,6,7,8,9,-1,1};
#pragma pack(push, 1)
struct TestModel {
......@@ -715,17 +715,17 @@ unsigned int test_db::key_i64i64i64_general() {
uint32_t res = 0;
TestModel3xi64 records[] = {
{1, 1, 0, N()}, // 0
{1, 1, 1, N()}, // 1
{1, 2, 2, N()}, // 2
{2, 1, 3, N()}, // 3
{2, 2, 4, N()}, // 4
{2, 2, 5, N()}, // 5
{3, 1, 6, N()}, // 6
{4, 0, 7, N()}, // 7
{4, 5, 8, N()}, // 8
{5, 1, 9, N()}, // 9
{5, 2, 10, N()}, //10
{1, 1, 0, N()}, // 0 <---------------------------
{1, 1, 1, N()}, // 1 |
{1, 2, 2, N()}, // 2 <--------------- |
{2, 1, 3, N()}, // 3 | |
{2, 2, 2, N()}, // 4 same {secondary,tertiary} |
{2, 2, 5, N()}, // 5 |
{3, 1, 6, N()}, // 6 |
{4, 0, 7, N()}, // 7 |
{4, 5, 8, N()}, // 8 |
{5, 1, 9, N()}, // 9 |
{5, 2, 0, N()}, //10 same {tertiary}-------------
};
store_set_in_table(records, sizeof(records)/sizeof(records[0]), N(table0));
......@@ -746,7 +746,7 @@ unsigned int test_db::key_i64i64i64_general() {
#define BS(X) ((X) ? "true" : "false")
#define TABLE1_ASSERT(I, V, msg) \
if(LOGME) {\
eos::print(msg, " : ", res, " a:", V.a, " b:", V.b, " c:", V.c, " t:", V.table, " ("); \
eos::print(msg, " : ", res, " a:", V.a, " b:", V.b, " c:", V.c, " t:", V.table, "inx:", uint64_t(I), " ("); \
eos::print(BS(res == sizeof(V)), " ", BS(records[I].a == V.a), " ", BS(records[I].b == V.b), " ", BS(records[I].c == V.c), " => ", N(table1), ")\n"); \
} \
WASM_ASSERT( res == sizeof(V) && records[I].a == V.a && records[I].b == V.b && \
......@@ -784,7 +784,7 @@ unsigned int test_db::key_i64i64i64_general() {
V={11,0}; LOAD_OK(secondary, i64i64i64, N(table1), 7, "i64x3 LOAD secondary 0");
V={11,1}; LOAD_OK(secondary, i64i64i64, N(table1), 0, "i64x3 LOAD secondary 1");
V={11,2}; LOAD_OK(secondary, i64i64i64, N(table1), 2, "i64x3 LOAD secondary 2");
V={11,2}; LOAD_OK(secondary, i64i64i64, N(table1),10, "i64x3 LOAD secondary 2");
V={11,3}; LOAD_ER(secondary, i64i64i64, N(table1), "i64x3 LOAD secondary fail 3");
V={11,4}; LOAD_ER(secondary, i64i64i64, N(table1), "i64x3 LOAD secondary fail 4");
V={11,5}; LOAD_OK(secondary, i64i64i64, N(table1), 8, "i64x3 LOAD secondary 5");
......@@ -794,13 +794,13 @@ unsigned int test_db::key_i64i64i64_general() {
V={11,12,1}; LOAD_OK(tertiary, i64i64i64, N(table1), 1, "i64x3 LOAD tertiary 1");
V={11,12,2}; LOAD_OK(tertiary, i64i64i64, N(table1), 2, "i64x3 LOAD tertiary 2");
V={11,12,3}; LOAD_OK(tertiary, i64i64i64, N(table1), 3, "i64x3 LOAD tertiary 3");
V={11,12,4}; LOAD_OK(tertiary, i64i64i64, N(table1), 4, "i64x3 LOAD tertiary 4");
V={11,12,4}; LOAD_ER(tertiary, i64i64i64, N(table1), "i64x3 LOAD tertiary 4");
V={11,12,5}; LOAD_OK(tertiary, i64i64i64, N(table1), 5, "i64x3 LOAD tertiary 5");
V={11,12,6}; LOAD_OK(tertiary, i64i64i64, N(table1), 6, "i64x3 LOAD tertiary 6");
V={11,12,7}; LOAD_OK(tertiary, i64i64i64, N(table1), 7, "i64x3 LOAD tertiary 7");
V={11,12,8}; LOAD_OK(tertiary, i64i64i64, N(table1), 8, "i64x3 LOAD tertiary 8");
V={11,12,9}; LOAD_OK(tertiary, i64i64i64, N(table1), 9, "i64x3 LOAD tertiary 9");
V={11,12,10}; LOAD_OK(tertiary, i64i64i64, N(table1), 10, "i64x3 LOAD tertiary 10");
V={11,12,10}; LOAD_ER(tertiary, i64i64i64, N(table1), "i64x3 LOAD tertiary 10");
V={11,12,11}; LOAD_ER(tertiary, i64i64i64, N(table1), "i64x3 LOAD tertiary fail 11");
#define NEXT_ALL(I, O, T) \
......@@ -827,6 +827,10 @@ unsigned int test_db::key_i64i64i64_general() {
} while(--j>0); \
}
NEXT_ALL(primary, i64i64i64, N(table1));
NEXT_ALL(secondary, i64i64i64, N(table1));
NEXT_ALL(tertiary, i64i64i64, N(table1));
PREV_ALL(primary, i64i64i64, N(table1));
PREV_ALL(secondary, i64i64i64, N(table1));
PREV_ALL(tertiary, i64i64i64, N(table1));
......
......@@ -172,18 +172,19 @@ namespace eos { namespace chain {
member<key64x64x64_value_object, AccountName, &key64x64x64_value_object::code>,
member<key64x64x64_value_object, AccountName, &key64x64x64_value_object::table>,
member<key64x64x64_value_object, uint64_t, &key64x64x64_value_object::secondary_key>,
member<key64x64x64_value_object, uint64_t, &key64x64x64_value_object::tertiary_key>
>,
composite_key_compare< std::less<AccountName>,std::less<AccountName>,std::less<AccountName>,std::less<uint64_t>,std::less<uint64_t> >
member<key64x64x64_value_object, uint64_t, &key64x64x64_value_object::tertiary_key>,
member<key64x64x64_value_object, typename key64x64x64_value_object::id_type, &key64x64x64_value_object::id>
>
>,
ordered_unique<tag<by_scope_tertiary>,
composite_key< key64x64x64_value_object,
member<key64x64x64_value_object, AccountName, &key64x64x64_value_object::scope>,
member<key64x64x64_value_object, AccountName, &key64x64x64_value_object::code>,
member<key64x64x64_value_object, AccountName, &key64x64x64_value_object::table>,
member<key64x64x64_value_object, uint64_t, &key64x64x64_value_object::tertiary_key>
member<key64x64x64_value_object, uint64_t, &key64x64x64_value_object::tertiary_key>,
member<key64x64x64_value_object, typename key64x64x64_value_object::id_type, &key64x64x64_value_object::id>
>,
composite_key_compare< std::less<AccountName>,std::less<AccountName>,std::less<AccountName>,std::less<uint64_t> >
composite_key_compare< std::less<AccountName>,std::less<AccountName>,std::less<AccountName>,std::less<uint64_t>,std::less<typename key64x64x64_value_object::id_type> >
>
>
>;
......
......@@ -160,10 +160,18 @@ public:
int32_t next_record( Name scope, Name code, Name table, typename IndexType::value_type::key_type* keys, char* value, uint32_t valuelen ) {
require_scope( scope );
const auto& idx = db.get_index<IndexType, Scope>();
auto tuple = next_record_tuple<typename IndexType::value_type, Scope>::get(scope, code, table, keys);
const auto& pidx = db.get_index<IndexType, by_scope_primary>();
auto tuple = next_record_tuple<typename IndexType::value_type>::get(scope, code, table, keys);
auto pitr = pidx.find(tuple);
auto itr = idx.lower_bound(tuple);
if(pitr == pidx.end())
return -1;
const auto& fidx = db.get_index<IndexType>();
auto itr = fidx.indicies().template project<Scope>(pitr);
const auto& idx = db.get_index<IndexType, Scope>();
if( itr == idx.end() ||
itr->scope != scope ||
......@@ -195,9 +203,18 @@ public:
int32_t previous_record( Name scope, Name code, Name table, typename IndexType::value_type::key_type* keys, char* value, uint32_t valuelen ) {
require_scope( scope );
const auto& pidx = db.get_index<IndexType, by_scope_primary>();
auto tuple = next_record_tuple<typename IndexType::value_type>::get(scope, code, table, keys);
auto pitr = pidx.find(tuple);
if(pitr == pidx.end())
return -1;
const auto& fidx = db.get_index<IndexType>();
auto itr = fidx.indicies().template project<Scope>(pitr);
const auto& idx = db.get_index<IndexType, Scope>();
auto tuple = next_record_tuple<typename IndexType::value_type, Scope>::get(scope, code, table, keys);
auto itr = idx.lower_bound(tuple);
if( itr == idx.end() ||
itr == idx.begin() ||
......
......@@ -220,59 +220,37 @@ struct front_record_tuple<keystr_value_object> {
// };
//next_record_tuple (same for previous)
template <typename T, typename Q>
template <typename T>
struct next_record_tuple {};
template <>
struct next_record_tuple<key_value_object, by_scope_primary> {
struct next_record_tuple<key_value_object> {
inline static auto get(Name scope, Name code, Name table, uint64_t* keys) {
return boost::make_tuple( AccountName(scope), AccountName(code), AccountName(table),
*keys);
}
};
template <>
struct next_record_tuple<keystr_value_object, by_scope_primary> {
struct next_record_tuple<keystr_value_object> {
inline static auto get(Name scope, Name code, Name table, std::string* keys) {
return boost::make_tuple( AccountName(scope), AccountName(code), AccountName(table),
keys->data());
}
};
template <>
struct next_record_tuple<key128x128_value_object, by_scope_primary> {
struct next_record_tuple<key128x128_value_object> {
inline static auto get(Name scope, Name code, Name table, uint128_t* keys) {
return boost::make_tuple( uint64_t(scope), uint64_t(code), uint64_t(table),
*keys, *(keys+1));
}
};
template <>
struct next_record_tuple<key128x128_value_object, by_scope_secondary> {
inline static auto get(Name scope, Name code, Name table, uint128_t* keys) {
return boost::make_tuple( uint64_t(scope), uint64_t(code), uint64_t(table),
*(keys+1), *keys);
}
};
template <>
struct next_record_tuple<key64x64x64_value_object, by_scope_primary> {
struct next_record_tuple<key64x64x64_value_object> {
inline static auto get(Name scope, Name code, Name table, uint64_t* keys) {
return boost::make_tuple( uint64_t(scope), uint64_t(code), uint64_t(table),
*keys, *(keys+1), *(keys+2));
}
};
template <>
struct next_record_tuple<key64x64x64_value_object, by_scope_secondary> {
inline static auto get(Name scope, Name code, Name table, uint64_t* keys) {
return boost::make_tuple( uint64_t(scope), uint64_t(code), uint64_t(table),
*(keys+1), *(keys+2));
}
};
template <>
struct next_record_tuple<key64x64x64_value_object, by_scope_tertiary> {
inline static auto get(Name scope, Name code, Name table, uint64_t* keys) {
return boost::make_tuple( uint64_t(scope), uint64_t(code), uint64_t(table),
*(keys+2));
}
};
//lower_bound_tuple
......
......@@ -199,7 +199,7 @@ void send_set_code_message(testing_blockchain& chain, types::setcode& handler, A
BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture)
{ try {
//auto wasm = assemble_wast( readFile2("/home/matu/Documents/Dev/eos/contracts/test_api/test_api.wast").c_str() );
//auto wasm = assemble_wast( readFile2("/home/matu/Documents/Dev/eos/build/contracts/test_api/test_api.wast").c_str() );
auto wasm = assemble_wast( test_api_wast );
Make_Blockchain(chain);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册