mdbx++: переименование mdbx::txn::put_multiple_samelength().

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2024-09-18 07:41:11 +03:00
parent f738552721
commit 07309427fd
2 changed files with 48 additions and 31 deletions

View File

@ -4669,25 +4669,26 @@ public:
return append(map, kv.key, kv.value, multivalue_order_preserved);
}
size_t put_multiple(map_handle map, const slice &key,
const size_t value_length, const void *values_array,
size_t values_count, put_mode mode,
bool allow_partial = false);
size_t put_multiple_samelength(map_handle map, const slice &key,
const size_t value_length,
const void *values_array, size_t values_count,
put_mode mode, bool allow_partial = false);
template <typename VALUE>
size_t put_multiple(map_handle map, const slice &key,
const VALUE *values_array, size_t values_count,
put_mode mode, bool allow_partial = false) {
size_t put_multiple_samelength(map_handle map, const slice &key,
const VALUE *values_array, size_t values_count,
put_mode mode, bool allow_partial = false) {
static_assert(::std::is_standard_layout<VALUE>::value &&
!::std::is_pointer<VALUE>::value &&
!::std::is_array<VALUE>::value,
"Must be a standard layout type!");
return put_multiple(map, key, sizeof(VALUE), values_array, values_count,
mode, allow_partial);
return put_multiple_samelength(map, key, sizeof(VALUE), values_array,
values_count, mode, allow_partial);
}
template <typename VALUE>
void put_multiple(map_handle map, const slice &key,
const ::std::vector<VALUE> &vector, put_mode mode) {
put_multiple(map, key, vector.data(), vector.size(), mode);
void put_multiple_samelength(map_handle map, const slice &key,
const ::std::vector<VALUE> &vector,
put_mode mode) {
put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
}
inline ptrdiff_t estimate(map_handle map, const pair &from,
@ -6913,10 +6914,11 @@ inline void txn::append(map_handle map, const slice &key, const slice &value,
: MDBX_APPEND));
}
inline size_t txn::put_multiple(map_handle map, const slice &key,
const size_t value_length,
const void *values_array, size_t values_count,
put_mode mode, bool allow_partial) {
inline size_t txn::put_multiple_samelength(map_handle map, const slice &key,
const size_t value_length,
const void *values_array,
size_t values_count, put_mode mode,
bool allow_partial) {
MDBX_val args[2] = {{const_cast<void *>(values_array), value_length},
{nullptr, values_count}};
const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args,

View File

@ -50,13 +50,20 @@ int main(int argc, const char *argv[]) {
const uint64_t array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 42, 17, 99, 0, 33, 333};
txn = env.start_write();
txn.put_multiple(map, buffer::key_from_u64(13), array + 3, 4, mdbx::upsert);
txn.put_multiple(map, buffer::key_from_u64(10), array + 0, 1, mdbx::upsert);
txn.put_multiple(map, buffer::key_from_u64(12), array + 2, 3, mdbx::upsert);
txn.put_multiple(map, buffer::key_from_u64(15), array + 5, 6, mdbx::upsert);
txn.put_multiple(map, buffer::key_from_u64(14), array + 4, 5, mdbx::upsert);
txn.put_multiple(map, buffer::key_from_u64(11), array + 1, 2, mdbx::upsert);
txn.put_multiple(map, buffer::key_from_u64(16), array + 6, 7, mdbx::upsert);
txn.put_multiple_samelength(map, buffer::key_from_u64(13), array + 3, 4,
mdbx::upsert);
txn.put_multiple_samelength(map, buffer::key_from_u64(10), array + 0, 1,
mdbx::upsert);
txn.put_multiple_samelength(map, buffer::key_from_u64(12), array + 2, 3,
mdbx::upsert);
txn.put_multiple_samelength(map, buffer::key_from_u64(15), array + 5, 6,
mdbx::upsert);
txn.put_multiple_samelength(map, buffer::key_from_u64(14), array + 4, 5,
mdbx::upsert);
txn.put_multiple_samelength(map, buffer::key_from_u64(11), array + 1, 2,
mdbx::upsert);
txn.put_multiple_samelength(map, buffer::key_from_u64(16), array + 6, 7,
mdbx::upsert);
txn.commit();
txn = env.start_read();
@ -119,21 +126,29 @@ int main(int argc, const char *argv[]) {
txn.abort();
txn = env.start_write();
txn.put_multiple(map, buffer::key_from_u64(7), array + 3, 4, mdbx::update);
txn.put_multiple_samelength(map, buffer::key_from_u64(7), array + 3, 4,
mdbx::update);
txn.upsert(map, buffer::key_from_u64(10), buffer::key_from_u64(14));
txn.put_multiple(map, buffer::key_from_u64(11), array + 4, 5, mdbx::upsert);
txn.put_multiple(map, buffer::key_from_u64(12), array + 0, 1, mdbx::update);
txn.put_multiple_samelength(map, buffer::key_from_u64(11), array + 4, 5,
mdbx::upsert);
txn.put_multiple_samelength(map, buffer::key_from_u64(12), array + 0, 1,
mdbx::update);
txn.update(map, buffer::key_from_u64(13), buffer::key_from_u64(18));
txn.put_multiple(map, buffer::key_from_u64(14), array + 2, 3, mdbx::update);
txn.put_multiple_samelength(map, buffer::key_from_u64(14), array + 2, 3,
mdbx::update);
txn.update(map, buffer::key_from_u64(15), buffer::key_from_u64(13));
txn.put_multiple(map, buffer::key_from_u64(16), array + 6, 9, mdbx::update);
txn.put_multiple_samelength(map, buffer::key_from_u64(16), array + 6, 9,
mdbx::update);
txn.update(map, buffer::key_from_u64(21), buffer::key_from_u64(17));
txn.update(map, buffer::key_from_u64(22), buffer::key_from_u64(15));
txn.put_multiple(map, buffer::key_from_u64(23), array + 1, 2, mdbx::update);
txn.put_multiple_samelength(map, buffer::key_from_u64(23), array + 1, 2,
mdbx::update);
txn.update(map, buffer::key_from_u64(24), buffer::key_from_u64(16));
txn.put_multiple(map, buffer::key_from_u64(25), array + 5, 6, mdbx::update);
txn.put_multiple_samelength(map, buffer::key_from_u64(25), array + 5, 6,
mdbx::update);
txn.upsert(map, buffer::key_from_u64(26), buffer::key_from_u64(12));
txn.put_multiple(map, buffer::key_from_u64(27), array + 12, 3, mdbx::update);
txn.put_multiple_samelength(map, buffer::key_from_u64(27), array + 12, 3,
mdbx::update);
txn.commit();
txn = env.start_read();