1
0
Fork 0
forked from blue/lmdbal

methods to check elements without deserialization

This commit is contained in:
Blue 2022-12-15 20:29:49 +03:00
parent 08daad48ad
commit 6ff22c9377
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
4 changed files with 59 additions and 1 deletions

View file

@ -137,11 +137,41 @@ V DataBase::Cache<K, V>::getRecord(const K& key) const {
handleMode();
return value;
} catch (const NotFound& error) {
abscent->insert(key);
if (*mode != Mode::full) {
abscent->insert(key);
}
throw error;
}
}
template<class K, class V>
bool DataBase::Cache<K, V>::checkRecord(const K& key) const {
if (!DataBase::Table<K, V>::db->opened) {
throw Closed("checkRecord", DataBase::Table<K, V>::db->name, DataBase::Table<K, V>::name);
}
typename std::map<K, V>::const_iterator itr = cache->find(key);
if (itr != cache->end()) {
return true;
}
if (*mode == Mode::full || abscent->count(key) != 0) {
return false;
}
try {
V value = Table<K, V>::getRecord(key);
cache->insert(std::make_pair(key, value));
handleMode();
return true;
} catch (const NotFound& error) {
if (*mode != Mode::full) {
abscent->insert(key);
}
return false;
}
}
template<class K, class V>
std::map<K, V> DataBase::Cache<K, V>::readAll() const {
if (!DataBase::Table<K, V>::db->opened) {