Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
lmdb_cursor.cpp
Go to the documentation of this file.
5#include "lmdb.h"
6#include <mutex>
7
8namespace bb::lmdblib {
10 : _tx(tx)
11 , _db(db)
12 , _id(id)
13{
14 call_lmdb_func("mdb_cursor_open", mdb_cursor_open, tx->underlying(), db->underlying(), &_cursor);
15}
16
17LMDBCursor::~LMDBCursor()
18{
19 call_lmdb_func(mdb_cursor_close, _cursor);
20}
21
22MDB_cursor* LMDBCursor::underlying() const
23{
24 return _cursor;
25}
26
27const MDB_dbi& LMDBCursor::underlying_db() const
28{
29 return _db->underlying();
30}
31
32MDB_txn* LMDBCursor::underlying_tx() const
33{
34 return _tx->underlying();
35}
36
37uint64_t LMDBCursor::id() const
38{
39 return _id;
40}
41
42bool LMDBCursor::set_at_key(Key& key) const
43{
45 return lmdb_queries::set_at_key(*this, key);
46}
47
48bool LMDBCursor::set_at_key_gte(Key& key) const
49{
51 return lmdb_queries::set_at_key_gte(*this, key);
52}
53
54bool LMDBCursor::set_at_start() const
55{
57 return lmdb_queries::set_at_start(*this);
58}
59
60bool LMDBCursor::set_at_end() const
61{
63 return lmdb_queries::set_at_end(*this);
64}
65
66bool LMDBCursor::read_next(uint64_t numKeysToRead, KeyDupValuesVector& keyValuePairs) const
67{
69 if (_db->duplicate_keys_permitted()) {
70 return lmdb_queries::read_next_dup(*this, keyValuePairs, numKeysToRead);
71 }
72 return lmdb_queries::read_next(*this, keyValuePairs, numKeysToRead);
73}
74
75bool LMDBCursor::read_prev(uint64_t numKeysToRead, KeyDupValuesVector& keyValuePairs) const
76{
78 if (_db->duplicate_keys_permitted()) {
79 return lmdb_queries::read_prev_dup(*this, keyValuePairs, numKeysToRead);
80 }
81 return lmdb_queries::read_prev(*this, keyValuePairs, numKeysToRead);
82}
83
84bool LMDBCursor::count_until_next(const Key& key, uint64_t& count) const
85{
87 if (_db->duplicate_keys_permitted()) {
88 return lmdb_queries::count_until_next_dup(*this, key, count);
89 }
90 return lmdb_queries::count_until_next(*this, key, count);
91}
92
93bool LMDBCursor::count_until_prev(const Key& key, uint64_t& count) const
94{
96 if (_db->duplicate_keys_permitted()) {
97 return lmdb_queries::count_until_prev_dup(*this, key, count);
98 }
99 return lmdb_queries::count_until_prev(*this, key, count);
100}
101
102} // namespace bb::lmdblib
LMDBCursor(std::shared_ptr< LMDBReadTransaction > tx, std::shared_ptr< LMDBDatabase > db, uint64_t id)
std::shared_ptr< LMDBDatabase > SharedPtr
std::shared_ptr< LMDBReadTransaction > SharedPtr
std::vector< uint8_t > Key
Definition types.hpp:11
std::vector< KeyValuesPair > KeyDupValuesVector
Definition types.hpp:18
bool call_lmdb_func(int(*f)(TArgs...), TArgs... args)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13