Commit e3a69a7e authored by Matthieu Dorier's avatar Matthieu Dorier

updated C++ APi

parent 9d73e02a
...@@ -218,6 +218,10 @@ class client { ...@@ -218,6 +218,10 @@ class client {
put(db, object_data(key), object_size(key), object_data(value), object_size(value)); put(db, object_data(key), object_size(key), object_data(value), object_size(value));
} }
//////////////////////////
// PUT_MULTI methods
//////////////////////////
/** /**
* @brief Equivalent to sdskv_put_multi. * @brief Equivalent to sdskv_put_multi.
* *
...@@ -228,13 +232,10 @@ class client { ...@@ -228,13 +232,10 @@ class client {
* @param values Array of values. * @param values Array of values.
* @param vsizes Array of value sizes. * @param vsizes Array of value sizes.
*/ */
void put(const database& db, void put_multi(const database& db,
hg_size_t count, const void* const* keys, const hg_size_t* ksizes, hg_size_t count, const void* const* keys, const hg_size_t* ksizes,
const void* const* values, const hg_size_t *vsizes) const; const void* const* values, const hg_size_t *vsizes) const;
//////////////////////////
// PUT_MULTI methods
//////////////////////////
/** /**
* @brief Version of put taking std::vectors instead of arrays of pointers. * @brief Version of put taking std::vectors instead of arrays of pointers.
...@@ -245,7 +246,7 @@ class client { ...@@ -245,7 +246,7 @@ class client {
* @param values Vector of pointers to values. * @param values Vector of pointers to values.
* @param vsizes Vector of value sizes. * @param vsizes Vector of value sizes.
*/ */
inline void put(const database& db, inline void put_multi(const database& db,
const std::vector<const void*>& keys, const std::vector<hg_size_t>& ksizes, const std::vector<const void*>& keys, const std::vector<hg_size_t>& ksizes,
const std::vector<const void*>& values, const std::vector<hg_size_t>& vsizes) const { const std::vector<const void*>& values, const std::vector<hg_size_t>& vsizes) const {
if(keys.size() != ksizes.size() if(keys.size() != ksizes.size()
...@@ -253,7 +254,7 @@ class client { ...@@ -253,7 +254,7 @@ class client {
|| keys.size() != vsizes.size()) { || keys.size() != vsizes.size()) {
throw std::length_error("Provided vectors should have the same size"); throw std::length_error("Provided vectors should have the same size");
} }
put(db, keys.size(), keys.data(), ksizes.data(), values.data(), vsizes.data()); put_multi(db, keys.size(), keys.data(), ksizes.data(), values.data(), vsizes.data());
} }
/** /**
...@@ -267,7 +268,7 @@ class client { ...@@ -267,7 +268,7 @@ class client {
* @param values Vector of values. * @param values Vector of values.
*/ */
template<typename K, typename V> template<typename K, typename V>
inline void put(const database& db, inline void put_multi(const database& db,
const std::vector<K>& keys, const std::vector<V>& values) { const std::vector<K>& keys, const std::vector<V>& values) {
if(keys.size() != values.size()) { if(keys.size() != values.size()) {
throw std::length_error("Provided vectors should have the same size"); throw std::length_error("Provided vectors should have the same size");
...@@ -284,7 +285,7 @@ class client { ...@@ -284,7 +285,7 @@ class client {
vsizes.push_back(object_size(v)); vsizes.push_back(object_size(v));
vdata.push_back(object_data(v)); vdata.push_back(object_data(v));
} }
put(db, kdata, ksizes, vdata, vsizes); put_multi(db, kdata, ksizes, vdata, vsizes);
} }
/** /**
...@@ -301,7 +302,7 @@ class client { ...@@ -301,7 +302,7 @@ class client {
* @param vend end of the iterator to values. * @param vend end of the iterator to values.
*/ */
template<typename IK, typename IV> template<typename IK, typename IV>
inline void put(const database& db, inline void put_multi(const database& db,
const IK& kbegin, const IK& kend, const IK& kbegin, const IK& kend,
const IV& vbegin, const IV& vend) const { const IV& vbegin, const IV& vend) const {
hg_size_t count = std::distance(kbegin, kend); hg_size_t count = std::distance(kbegin, kend);
...@@ -320,7 +321,7 @@ class client { ...@@ -320,7 +321,7 @@ class client {
vsizes.push_back(object_size(*it)); vsizes.push_back(object_size(*it));
vdata.push_back(object_data(*it)); vdata.push_back(object_data(*it));
} }
put(db, kdata, ksizes, vdata, vsizes); put_multi(db, kdata, ksizes, vdata, vsizes);
} }
////////////////////////// //////////////////////////
...@@ -399,7 +400,7 @@ class client { ...@@ -399,7 +400,7 @@ class client {
* @param ksizes Array of key sizes. * @param ksizes Array of key sizes.
* @param vsizes Resulting value sizes. * @param vsizes Resulting value sizes.
*/ */
bool length(const database& db, bool length_multi(const database& db,
hg_size_t num, const void* const* keys, hg_size_t num, const void* const* keys,
const hg_size_t* ksizes, hg_size_t* vsizes) const; const hg_size_t* ksizes, hg_size_t* vsizes) const;
...@@ -413,7 +414,7 @@ class client { ...@@ -413,7 +414,7 @@ class client {
* @param vsizes Resulting vector of value sizes. * @param vsizes Resulting vector of value sizes.
*/ */
template<typename K> template<typename K>
inline bool length(const database& db, inline bool length_multi(const database& db,
const std::vector<K>& keys, const std::vector<K>& keys,
std::vector<hg_size_t>& vsizes) const { std::vector<hg_size_t>& vsizes) const {
vsizes.resize(keys.size()); vsizes.resize(keys.size());
...@@ -423,7 +424,7 @@ class client { ...@@ -423,7 +424,7 @@ class client {
kdata.push_back(object_data(k)); kdata.push_back(object_data(k));
ksizes.push_back(object_size(k)); ksizes.push_back(object_size(k));
} }
return length(db, keys.size(), kdata.data(), ksizes.data(), vsizes.data()); return length_multi(db, keys.size(), kdata.data(), ksizes.data(), vsizes.data());
} }
/** /**
...@@ -438,9 +439,9 @@ class client { ...@@ -438,9 +439,9 @@ class client {
* @return Vector of corresponding value sizes. * @return Vector of corresponding value sizes.
*/ */
template<typename K> template<typename K>
inline std::vector<hg_size_t> length(const database& db, const std::vector<K>& keys) const { inline std::vector<hg_size_t> length_multi(const database& db, const std::vector<K>& keys) const {
std::vector<hg_size_t> vsizes(keys.size()); std::vector<hg_size_t> vsizes(keys.size());
length(db, keys, vsizes); length_multi(db, keys, vsizes);
return vsizes; return vsizes;
} }
...@@ -528,7 +529,7 @@ class client { ...@@ -528,7 +529,7 @@ class client {
* @param values Array of value buffers. * @param values Array of value buffers.
* @param vsizes Array of sizes of value buffers. * @param vsizes Array of sizes of value buffers.
*/ */
bool get(const database& db, bool get_multi(const database& db,
hg_size_t count, const void* const* keys, const hg_size_t* ksizes, hg_size_t count, const void* const* keys, const hg_size_t* ksizes,
void** values, hg_size_t *vsizes) const; void** values, hg_size_t *vsizes) const;
...@@ -541,7 +542,7 @@ class client { ...@@ -541,7 +542,7 @@ class client {
* @param values Vector of value addresses. * @param values Vector of value addresses.
* @param vsizes Vector of value sizes. * @param vsizes Vector of value sizes.
*/ */
inline bool get(const database& db, inline bool get_multi(const database& db,
const std::vector<const void*>& keys, const std::vector<hg_size_t>& ksizes, const std::vector<const void*>& keys, const std::vector<hg_size_t>& ksizes,
std::vector<void*>& values, std::vector<hg_size_t>& vsizes) const { std::vector<void*>& values, std::vector<hg_size_t>& vsizes) const {
if(keys.size() != ksizes.size() if(keys.size() != ksizes.size()
...@@ -549,7 +550,7 @@ class client { ...@@ -549,7 +550,7 @@ class client {
|| keys.size() != vsizes.size()) { || keys.size() != vsizes.size()) {
throw std::length_error("Provided vectors should have the same size"); throw std::length_error("Provided vectors should have the same size");
} }
return get(db, keys.size(), keys.data(), ksizes.data(), values.data(), vsizes.data()); return get_multi(db, keys.size(), keys.data(), ksizes.data(), values.data(), vsizes.data());
} }
/** /**
...@@ -564,7 +565,7 @@ class client { ...@@ -564,7 +565,7 @@ class client {
* @param values Vector of values. * @param values Vector of values.
*/ */
template<typename K, typename V> template<typename K, typename V>
inline bool get(const database& db, inline bool get_multi(const database& db,
const std::vector<K>& keys, std::vector<V>& values) const { const std::vector<K>& keys, std::vector<V>& values) const {
if(keys.size() != values.size()) { if(keys.size() != values.size()) {
throw std::length_error("Provided vectors should have the same size"); throw std::length_error("Provided vectors should have the same size");
...@@ -581,7 +582,7 @@ class client { ...@@ -581,7 +582,7 @@ class client {
vsizes.push_back(object_size(v)); vsizes.push_back(object_size(v));
vdata.push_back(object_data(v)); vdata.push_back(object_data(v));
} }
get(db, kdata, ksizes, vdata, vsizes); get_multi(db, kdata, ksizes, vdata, vsizes);
for(unsigned i=0; i < values.size(); i++) { for(unsigned i=0; i < values.size(); i++) {
object_resize(values[i], vsizes[i]); object_resize(values[i], vsizes[i]);
} }
...@@ -602,7 +603,7 @@ class client { ...@@ -602,7 +603,7 @@ class client {
* @param vend End iterator for values. * @param vend End iterator for values.
*/ */
template<typename IK, typename IV> template<typename IK, typename IV>
inline bool get(const database& db, inline bool get_multi(const database& db,
const IK& kbegin, const IK& kend, const IK& kbegin, const IK& kend,
const IV& vbegin, const IV& vend) const { const IV& vbegin, const IV& vend) const {
hg_size_t count = std::distance(kbegin, kend); hg_size_t count = std::distance(kbegin, kend);
...@@ -621,7 +622,7 @@ class client { ...@@ -621,7 +622,7 @@ class client {
vsizes.push_back(object_size(*it)); vsizes.push_back(object_size(*it));
vdata.push_back(object_data(*it)); vdata.push_back(object_data(*it));
} }
return get(db, kdata, ksizes, vdata, vsizes); return get_multi(db, kdata, ksizes, vdata, vsizes);
} }
/** /**
...@@ -637,17 +638,17 @@ class client { ...@@ -637,17 +638,17 @@ class client {
* @return the resulting std::vector of values. * @return the resulting std::vector of values.
*/ */
template<typename K, typename V> template<typename K, typename V>
inline std::vector<V> get( inline std::vector<V> get_multi(
const database& db, const database& db,
const std::vector<K>& keys) { const std::vector<K>& keys) {
hg_size_t num = keys.size(); hg_size_t num = keys.size();
std::vector<hg_size_t> vsizes(num); std::vector<hg_size_t> vsizes(num);
length(db, keys, vsizes); length_multi(db, keys, vsizes);
std::vector<V> values(num); std::vector<V> values(num);
for(unsigned i=0 ; i < num; i++) { for(unsigned i=0 ; i < num; i++) {
object_resize(values[i], vsizes[i]); object_resize(values[i], vsizes[i]);
} }
get(db, keys, values); get_multi(db, keys, values);
return values; return values;
} }
...@@ -1298,6 +1299,14 @@ class database { ...@@ -1298,6 +1299,14 @@ class database {
m_ph.m_client->put(*this, std::forward<T>(args)...); m_ph.m_client->put(*this, std::forward<T>(args)...);
} }
/**
* @brief @see client::put_multi.
*/
template<typename ... T>
void put_multi(T&& ... args) const {
m_ph.m_client->put_multi(*this, std::forward<T>(args)...);
}
/** /**
* @brief @see client::length. * @brief @see client::length.
*/ */
...@@ -1306,6 +1315,14 @@ class database { ...@@ -1306,6 +1315,14 @@ class database {
return m_ph.m_client->length(*this, std::forward<T>(args)...); return m_ph.m_client->length(*this, std::forward<T>(args)...);
} }
/**
* @brief @see client::length_multi.
*/
template<typename ... T>
decltype(auto) length_multi(T&& ... args) const {
return m_ph.m_client->length_multi(*this, std::forward<T>(args)...);
}
/** /**
* @brief @see client::get. * @brief @see client::get.
*/ */
...@@ -1314,6 +1331,14 @@ class database { ...@@ -1314,6 +1331,14 @@ class database {
return m_ph.m_client->get(*this, std::forward<T>(args)...); return m_ph.m_client->get(*this, std::forward<T>(args)...);
} }
/**
* @brief @see client::get_multi.
*/
template<typename ... T>
decltype(auto) get_multi(T&& ... args) const {
return m_ph.m_client->get_multi(*this, std::forward<T>(args)...);
}
/** /**
* @brief @see client::exists * @brief @see client::exists
*/ */
...@@ -1407,7 +1432,7 @@ inline void client::put(const database& db, ...@@ -1407,7 +1432,7 @@ inline void client::put(const database& db,
_CHECK_RET(ret); _CHECK_RET(ret);
} }
inline void client::put(const database& db, inline void client::put_multi(const database& db,
hg_size_t count, const void* const* keys, const hg_size_t* ksizes, hg_size_t count, const void* const* keys, const hg_size_t* ksizes,
const void* const* values, const hg_size_t *vsizes) const { const void* const* values, const hg_size_t *vsizes) const {
int ret = sdskv_put_multi(db.m_ph.m_ph, db.m_db_id, int ret = sdskv_put_multi(db.m_ph.m_ph, db.m_db_id,
...@@ -1431,7 +1456,7 @@ inline bool client::exists(const database& db, const void* key, hg_size_t ksize) ...@@ -1431,7 +1456,7 @@ inline bool client::exists(const database& db, const void* key, hg_size_t ksize)
return flag; return flag;
} }
inline bool client::length(const database& db, inline bool client::length_multi(const database& db,
hg_size_t num, const void* const* keys, hg_size_t num, const void* const* keys,
const hg_size_t* ksizes, hg_size_t* vsizes) const { const hg_size_t* ksizes, hg_size_t* vsizes) const {
int ret = sdskv_length_multi(db.m_ph.m_ph, db.m_db_id, int ret = sdskv_length_multi(db.m_ph.m_ph, db.m_db_id,
...@@ -1449,7 +1474,7 @@ inline bool client::get(const database& db, ...@@ -1449,7 +1474,7 @@ inline bool client::get(const database& db,
return true; return true;
} }
inline bool client::get(const database& db, inline bool client::get_multi(const database& db,
hg_size_t count, const void* const* keys, const hg_size_t* ksizes, hg_size_t count, const void* const* keys, const hg_size_t* ksizes,
void** values, hg_size_t *vsizes) const { void** values, hg_size_t *vsizes) const {
int ret = sdskv_get_multi(db.m_ph.m_ph, db.m_db_id, int ret = sdskv_get_multi(db.m_ph.m_ph, db.m_db_id,
......
...@@ -241,10 +241,9 @@ class PutMultiBenchmark : public PutBenchmark { ...@@ -241,10 +241,9 @@ class PutMultiBenchmark : public PutBenchmark {
m_vsizes.resize(count); m_vsizes.resize(count);
m_vptrs.resize(count); m_vptrs.resize(count);
} }
db.put(m_kptrs, m_ksizes, m_vptrs, m_vsizes); db.put_multi(m_kptrs, m_ksizes, m_vptrs, m_vsizes);
remaining -= count; remaining -= count;
} }
db.put(m_keys, m_vals);
} }
virtual void teardown() override { virtual void teardown() override {
...@@ -386,7 +385,7 @@ class GetMultiBenchmark : public GetBenchmark { ...@@ -386,7 +385,7 @@ class GetMultiBenchmark : public GetBenchmark {
m_vsizes.resize(count); m_vsizes.resize(count);
m_vptrs.resize(count); m_vptrs.resize(count);
} }
db.get(m_kptrs, m_ksizes, m_vptrs, m_vsizes); db.get_multi(m_kptrs, m_ksizes, m_vptrs, m_vsizes);
if(!m_reuse_buffer) if(!m_reuse_buffer)
k += count; k += count;
j += count; j += count;
...@@ -468,7 +467,7 @@ class LengthMultiBenchmark : public LengthBenchmark { ...@@ -468,7 +467,7 @@ class LengthMultiBenchmark : public LengthBenchmark {
m_ksizes[i] = m_keys[i+j].size(); m_ksizes[i] = m_keys[i+j].size();
m_kptrs[i] = (const void*)m_keys[i+j].data(); m_kptrs[i] = (const void*)m_keys[i+j].data();
} }
db.length(count, m_kptrs.data(), m_ksizes.data(), m_vsizes.data()+k); db.length_multi(count, m_kptrs.data(), m_ksizes.data(), m_vsizes.data()+k);
remaining -= count; remaining -= count;
j += count; j += count;
if(!m_reuse_buffer) if(!m_reuse_buffer)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment