readAll method now works correctly for duplicates mode, testing, some doc fixes
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 40s
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 40s
This commit is contained in:
parent
dbbc46e7c9
commit
de210b44f5
5 changed files with 163 additions and 8 deletions
|
@ -46,8 +46,8 @@ class Storage;
|
|||
template <class K, class V>
|
||||
class Cache;
|
||||
|
||||
typedef MDB_txn* TransactionID; /**<I'm going to use transaction pointers as transaction IDs*/
|
||||
typedef uint32_t SizeType; /**<All LMDBAL sizes are uint32_t*/
|
||||
typedef MDB_txn* TransactionID; /**<\brief I'm going to use transaction pointers as transaction IDs*/
|
||||
typedef uint32_t SizeType; /**<\brief All LMDBAL sizes are uint32_t*/
|
||||
|
||||
class Base {
|
||||
friend class iStorage;
|
||||
|
@ -82,8 +82,8 @@ public:
|
|||
LMDBAL::Cache<K, V>* getCache(const std::string& storageName);
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, LMDBAL::iStorage*> Storages; /**<Storage and Cache pointers are saved in the std::map*/
|
||||
typedef std::set<TransactionID> Transactions; /**<Piblic transaction IDs are saved in the std::set*/
|
||||
typedef std::map<std::string, LMDBAL::iStorage*> Storages; /**<\brief Storage and Cache pointers are saved in the std::map*/
|
||||
typedef std::set<TransactionID> Transactions; /**<\brief Piblic transaction IDs are saved in the std::set*/
|
||||
|
||||
TransactionID beginReadOnlyTransaction(const std::string& storageName) const;
|
||||
TransactionID beginTransaction(const std::string& storageName) const;
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
/**
|
||||
* \class LMDBAL::iStorage
|
||||
*
|
||||
* \brief Storage interface
|
||||
*
|
||||
* This is a interface-like class, it's designed to be an inner database interface to
|
||||
* be used as a polymorphic entity, and provide protected interaction with the database
|
||||
* from the heirs code
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
* \tparam K type of the keys of the storage
|
||||
* \tparam V type of the values of the storage
|
||||
*
|
||||
* You can receive an instance of this class calling LMDBAL::Base::addStorage(const std::string&)
|
||||
* You can receive an instance of this class calling LMDBAL::Base::addStorage(const std::string&, bool)
|
||||
* if the database is yet closed and you're defining the storages you're going to need.
|
||||
* Or you can call LMDBAL::Base::getStorage(const std::string&) if you didn't save a pointer to the storage at first
|
||||
*
|
||||
|
@ -501,6 +501,9 @@ bool LMDBAL::Storage<K, V>::checkRecord(const K& key, TransactionID txn) const {
|
|||
*
|
||||
* Basically just reads all database in an std::map, usefull when you store small storages
|
||||
*
|
||||
* In case storage supports duplicates <b>only what lmdb considered to be lowest value</b>
|
||||
* (see LMDBAL::Storage::getRecord() description) is returned in the resulting map
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
|
@ -518,6 +521,9 @@ std::map<K, V> LMDBAL::Storage<K, V>::readAll() const {
|
|||
*
|
||||
* Basically just reads all database in an std::map, usefull when you store small storages
|
||||
*
|
||||
* In case storage supports duplicates <b>only what lmdb considered to be lowest value</b>
|
||||
* (see LMDBAL::Storage::getRecord() description) is returned in the resulting map
|
||||
*
|
||||
* \param[out] result a map that is going to contain all data
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
|
@ -545,6 +551,9 @@ void LMDBAL::Storage<K, V>::readAll(std::map<K, V>& result) const {
|
|||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
* If you just want to read data you should prefer LMDBAL::Base::beginReadOnlyTransaction().
|
||||
*
|
||||
* In case storage supports duplicates <b>only what lmdb considered to be lowest value</b>
|
||||
* (see LMDBAL::Storage::getRecord() description) is returned in the resulting map
|
||||
*
|
||||
* \param[in] txn transaction ID, can be read only transaction
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
|
@ -566,6 +575,9 @@ std::map<K, V> LMDBAL::Storage<K, V>::readAll(TransactionID txn) const {
|
|||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
* If you just want to read data you should prefer LMDBAL::Base::beginReadOnlyTransaction().
|
||||
*
|
||||
* In case storage supports duplicates <b>only what lmdb considered to be lowest value</b>
|
||||
* (see LMDBAL::Storage::getRecord() description) is returned in the resulting map
|
||||
*
|
||||
* \param[out] result a map that is going to contain all data
|
||||
* \param[in] txn transaction ID, can be read only transaction
|
||||
*
|
||||
|
@ -587,8 +599,10 @@ void LMDBAL::Storage<K, V>::readAll(std::map<K, V>& result, TransactionID txn) c
|
|||
while (rc == MDB_SUCCESS) {
|
||||
K key;
|
||||
keySerializer.deserialize(lmdbKey, key);
|
||||
V& value = result[key];
|
||||
valueSerializer.deserialize(lmdbData, value);
|
||||
std::pair<typename std::map<K, V>::iterator, bool> probe = result.emplace(key, V{});
|
||||
if (probe.second) //I do this to avoid overwrites in case duplicates are enabled
|
||||
valueSerializer.deserialize(lmdbData, probe.first->second);
|
||||
|
||||
rc = mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_NEXT);
|
||||
}
|
||||
mdb_cursor_close(cursor);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue