forked from blue/lmdbal
methods to bulk modify the storage, some transaction code hardening, operators to serialize std containers
This commit is contained in:
parent
6ae32e38b6
commit
a79dae8fd0
8 changed files with 365 additions and 14 deletions
45
cache.hpp
45
cache.hpp
|
@ -102,11 +102,10 @@ void DataBase::Cache<K, V>::changeRecord(const K& key, const V& value) {
|
|||
|
||||
try {
|
||||
Table<K, V>::changeRecord(key, value);
|
||||
typename std::map<K, V>::iterator itr = cache->find(key);
|
||||
if (itr != cache->end()) {
|
||||
itr->second = value;
|
||||
typename std::pair<typename std::map<K, V>::iterator, bool> res = cache->insert(std::make_pair(key, value));
|
||||
if (!res.second) {
|
||||
res.first->second = value;
|
||||
} else {
|
||||
cache->insert(std::make_pair(key, value));
|
||||
handleMode();
|
||||
}
|
||||
} catch (const NotFound& error) {
|
||||
|
@ -188,6 +187,44 @@ std::map<K, V> DataBase::Cache<K, V>::readAll() const {
|
|||
return *cache;
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
void DataBase::Cache<K, V>::replaceAll(const std::map<K, V>& data) {
|
||||
DataBase::Table<K, V>::replaceAll(data);
|
||||
*cache = data;
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
uint32_t DataBase::Cache<K, V>::addRecords(const std::map<K, V>& data, bool overwrite) {
|
||||
uint32_t newSize = DataBase::Table<K, V>::addRecords(data, overwrite);
|
||||
|
||||
Mode& m = *mode;
|
||||
if (m == Mode::nothing) {
|
||||
m = Mode::size;
|
||||
}
|
||||
std::map<K, V>& c = *cache;
|
||||
std::set<K>& a = *abscent;
|
||||
for (const std::pair<const K, V>& pair : data) {
|
||||
std::pair<typename std::map<K, V>::iterator, bool> res = c.insert(pair);
|
||||
if (!res.second) {
|
||||
if (overwrite) {
|
||||
res.first->second = pair.second;
|
||||
}
|
||||
} else if (m != Mode::full) {
|
||||
a.erase(pair.first);
|
||||
}
|
||||
}
|
||||
|
||||
if (m != Mode::full) {
|
||||
*sizeDifference = newSize - c.size();
|
||||
if (*sizeDifference == 0) {
|
||||
*mode = Mode::full;
|
||||
abscent->clear();
|
||||
}
|
||||
}
|
||||
|
||||
return newSize;
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
void DataBase::Cache<K, V>::removeRecord(const K& key) {
|
||||
if (!DataBase::Table<K, V>::db->opened) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue