1
0
Fork 0
forked from blue/lmdbal

methods for addition with overwrite

This commit is contained in:
Blue 2022-12-14 01:57:49 +03:00
parent 928558539c
commit 08daad48ad
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
4 changed files with 60 additions and 0 deletions

View file

@ -52,8 +52,35 @@ void DataBase::Cache<K, V>::addRecord(const K& key, const V& value) {
Table<K, V>::addRecord(key, value);
cache->insert(std::make_pair(key, value));
if (*mode != Mode::full) {
abscent->erase(key);
}
}
template<class K, class V>
bool DataBase::Cache<K, V>::forceRecord(const K& key, const V& value) {
if (!DataBase::Table<K, V>::db->opened) {
throw Closed("forceRecord", DataBase::Table<K, V>::db->name, DataBase::Table<K, V>::name);
}
bool added = Table<K, V>::forceRecord(key, value);
if (*mode == Mode::full) {
(*cache)[key] = value;
} else {
if (added) {
abscent->erase(key);
}
std::pair<typename std::map<K, V>::iterator, bool> result = cache->insert(std::make_pair(key, value));
if (!result.second) {
result.first->second = value;
} else if (!added) { //this way database had value but cache didn't, so, need to decrease sizeDifference
handleMode();
}
}
return added;
}
template<class K, class V>
void DataBase::Cache<K, V>::changeRecord(const K& key, const V& value) {