forked from blue/lmdbal
methods for addition with overwrite
This commit is contained in:
parent
928558539c
commit
08daad48ad
4 changed files with 60 additions and 0 deletions
27
cache.hpp
27
cache.hpp
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue