some more ideas about duplicates
This commit is contained in:
parent
f0727aa73d
commit
06e1aca45a
8 changed files with 139 additions and 24 deletions
|
@ -43,10 +43,10 @@
|
|||
*
|
||||
* \param[in] parent - LMDBAL::Base pointer for the owning database (borrowed)
|
||||
* \param[in] name - the name of the storage
|
||||
* \param[in] duplicates - true if storage supports duplicates, false otherwise (false by default)
|
||||
* \param[in] duplicates - LMDBAL::Duplicates duplicates mode (uniqueKey by default)
|
||||
*/
|
||||
template<class K, class V>
|
||||
LMDBAL::Storage<K, V>::Storage(Base* parent, const std::string& name, bool duplicates):
|
||||
LMDBAL::Storage<K, V>::Storage(Base* parent, const std::string& name, Duplicates duplicates):
|
||||
iStorage(parent, name, duplicates),
|
||||
keySerializer(),
|
||||
valueSerializer(),
|
||||
|
@ -111,7 +111,20 @@ void LMDBAL::Storage<K, V>::addRecord(const K& key, const V& value, TransactionI
|
|||
MDB_val lmdbKey = keySerializer.setData(key);
|
||||
MDB_val lmdbData = valueSerializer.setData(value);
|
||||
|
||||
int rc = mdb_put(txn, dbi, &lmdbKey, &lmdbData, MDB_NOOVERWRITE);
|
||||
unsigned int flags;
|
||||
switch (duplicates) {
|
||||
case uniqueKey:
|
||||
flags = MDB_NOOVERWRITE;
|
||||
break;
|
||||
case uniquePair:
|
||||
flags = MDB_NODUPDATA;
|
||||
break;
|
||||
case full:
|
||||
flags = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
int rc = mdb_put(txn, dbi, &lmdbKey, &lmdbData, flags);
|
||||
if (rc != MDB_SUCCESS)
|
||||
throwDuplicateOrUnknown(rc, toString(key));
|
||||
}
|
||||
|
@ -804,16 +817,19 @@ void LMDBAL::Storage<K, V>::discoveredRecord(const K& key, const V& value, Trans
|
|||
* This infrastructure also allowes us to customize mdb_dbi_open call in the future
|
||||
*/
|
||||
template<class K, class V>
|
||||
inline int LMDBAL::iStorage::makeStorage(MDB_txn* transaction, bool duplicates) {
|
||||
inline int LMDBAL::iStorage::makeStorage(MDB_txn* transaction, Duplicates duplicates) {
|
||||
unsigned int flags = MDB_CREATE;
|
||||
if constexpr (std::is_integral<K>::value)
|
||||
flags |= MDB_INTEGERKEY;
|
||||
|
||||
if (duplicates) {
|
||||
if (duplicates != uniqueKey) {
|
||||
flags |= MDB_DUPSORT;
|
||||
|
||||
if constexpr (std::is_integral<V>::value)
|
||||
flags |= MDB_INTEGERDUP | MDB_DUPFIXED;
|
||||
if constexpr (std::is_scalar<K>::value && std::is_scalar<V>::value)
|
||||
flags |= MDB_DUPFIXED;
|
||||
else if constexpr (std::is_integral<V>::value)
|
||||
flags |= MDB_INTEGERDUP;
|
||||
|
||||
}
|
||||
|
||||
return mdb_dbi_open(transaction, name.c_str(), flags, &dbi);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue