mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
ircd::db: Complete reverse iterations.
This commit is contained in:
parent
43ddaa90a4
commit
69eab27209
4 changed files with 367 additions and 173 deletions
|
@ -90,14 +90,19 @@ namespace ircd::db
|
|||
struct ircd::db::column
|
||||
{
|
||||
struct delta;
|
||||
struct const_iterator_base;
|
||||
struct const_iterator;
|
||||
struct const_reverse_iterator;
|
||||
|
||||
using key_type = string_view;
|
||||
using mapped_type = string_view;
|
||||
using value_type = std::pair<key_type, mapped_type>;
|
||||
using pointer = value_type *;
|
||||
using reference = value_type &;
|
||||
using difference_type = size_t;
|
||||
using iterator = const_iterator;
|
||||
using reverse_iterator = const_reverse_iterator;
|
||||
using iterator_category = std::bidirectional_iterator_tag;
|
||||
using difference_type = size_t;
|
||||
|
||||
protected:
|
||||
database::column *c {nullptr};
|
||||
|
@ -116,6 +121,10 @@ struct ircd::db::column
|
|||
// [GET] Iterations
|
||||
const_iterator begin(const gopts & = {});
|
||||
const_iterator end(const gopts & = {});
|
||||
|
||||
const_reverse_iterator rbegin(const gopts & = {});
|
||||
const_reverse_iterator rend(const gopts & = {});
|
||||
|
||||
const_iterator find(const string_view &key, const gopts & = {});
|
||||
const_iterator lower_bound(const string_view &key, const gopts & = {});
|
||||
const_iterator upper_bound(const string_view &key, const gopts & = {});
|
||||
|
@ -176,21 +185,23 @@ struct ircd::db::column::delta
|
|||
// Otherwise, construct an iterator by having it returned from the appropriate
|
||||
// function in column::.
|
||||
//
|
||||
struct ircd::db::column::const_iterator
|
||||
struct ircd::db::column::const_iterator_base
|
||||
{
|
||||
using value_type = column::value_type;
|
||||
using difference_type = size_t;
|
||||
using key_type = string_view;
|
||||
using mapped_type = string_view;
|
||||
using value_type = std::pair<key_type, mapped_type>;
|
||||
using pointer = value_type *;
|
||||
using reference = value_type &;
|
||||
using iterator_category = std::bidirectional_iterator_tag;
|
||||
using difference_type = size_t;
|
||||
|
||||
protected:
|
||||
friend class column;
|
||||
|
||||
database::column *c;
|
||||
database::snapshot ss;
|
||||
std::unique_ptr<rocksdb::Iterator> it;
|
||||
mutable value_type val;
|
||||
|
||||
const_iterator(database::column *const &, std::unique_ptr<rocksdb::Iterator> &&, database::snapshot = {});
|
||||
const_iterator_base(database::column *const &, std::unique_ptr<rocksdb::Iterator> &&, database::snapshot = {});
|
||||
|
||||
public:
|
||||
explicit operator const database::snapshot &() const;
|
||||
|
@ -205,42 +216,61 @@ struct ircd::db::column::const_iterator
|
|||
const value_type *operator->() const;
|
||||
const value_type &operator*() const;
|
||||
|
||||
const_iterator_base();
|
||||
const_iterator_base(const_iterator_base &&) noexcept;
|
||||
const_iterator_base &operator=(const_iterator_base &&) noexcept;
|
||||
~const_iterator_base() noexcept;
|
||||
|
||||
friend bool operator==(const const_iterator_base &, const const_iterator_base &);
|
||||
friend bool operator!=(const const_iterator_base &, const const_iterator_base &);
|
||||
friend bool operator<(const const_iterator_base &, const const_iterator_base &);
|
||||
friend bool operator>(const const_iterator_base &, const const_iterator_base &);
|
||||
|
||||
template<class pos> friend bool seek(column::const_iterator_base &, const pos &, const gopts & = {});
|
||||
};
|
||||
|
||||
struct ircd::db::column::const_iterator
|
||||
:const_iterator_base
|
||||
{
|
||||
friend class column;
|
||||
|
||||
const_iterator &operator++();
|
||||
const_iterator &operator--();
|
||||
|
||||
const_iterator();
|
||||
const_iterator(const_iterator &&) noexcept;
|
||||
const_iterator &operator=(const_iterator &&) noexcept;
|
||||
~const_iterator() noexcept;
|
||||
|
||||
friend bool operator==(const const_iterator &, const const_iterator &);
|
||||
friend bool operator!=(const const_iterator &, const const_iterator &);
|
||||
friend bool operator<(const const_iterator &, const const_iterator &);
|
||||
friend bool operator>(const const_iterator &, const const_iterator &);
|
||||
|
||||
template<class pos> friend bool seek(column::const_iterator &, const pos &, const gopts & = {});
|
||||
using const_iterator_base::const_iterator_base;
|
||||
};
|
||||
|
||||
inline ircd::db::column::const_iterator::operator
|
||||
struct ircd::db::column::const_reverse_iterator
|
||||
:const_iterator_base
|
||||
{
|
||||
friend class column;
|
||||
|
||||
const_reverse_iterator &operator++();
|
||||
const_reverse_iterator &operator--();
|
||||
|
||||
using const_iterator_base::const_iterator_base;
|
||||
};
|
||||
|
||||
inline ircd::db::column::const_iterator_base::operator
|
||||
database::column &()
|
||||
{
|
||||
return *c;
|
||||
}
|
||||
|
||||
inline ircd::db::column::const_iterator::operator
|
||||
inline ircd::db::column::const_iterator_base::operator
|
||||
database::snapshot &()
|
||||
{
|
||||
return ss;
|
||||
}
|
||||
|
||||
inline ircd::db::column::const_iterator::operator
|
||||
inline ircd::db::column::const_iterator_base::operator
|
||||
const database::column &()
|
||||
const
|
||||
{
|
||||
return *c;
|
||||
}
|
||||
|
||||
inline ircd::db::column::const_iterator::operator
|
||||
inline ircd::db::column::const_iterator_base::operator
|
||||
const database::snapshot &()
|
||||
const
|
||||
{
|
||||
|
|
|
@ -32,36 +32,38 @@ template<ircd::db::database *const &d,
|
|||
class tuple>
|
||||
struct ircd::db::cursor
|
||||
{
|
||||
template<class index_iterator> struct const_iterator_base;
|
||||
struct const_reverse_iterator;
|
||||
struct const_iterator;
|
||||
|
||||
using where_type = db::where<tuple>;
|
||||
using iterator_type = const_iterator;
|
||||
using const_iterator_type = const_iterator;
|
||||
using index_iterator = ircd::db::index::const_iterator;
|
||||
|
||||
struct index index;
|
||||
const where_type *where{nullptr};
|
||||
|
||||
const_iterator end();
|
||||
const_iterator begin();
|
||||
const_iterator find(const string_view &key);
|
||||
const_iterator end(const string_view &key);
|
||||
const_iterator begin(const string_view &key);
|
||||
|
||||
cursor(const string_view &index)
|
||||
const_reverse_iterator rend(const string_view &key);
|
||||
const_reverse_iterator rbegin(const string_view &key);
|
||||
|
||||
cursor(const string_view &index, const where_type *const &where = nullptr)
|
||||
:index{*d, index}
|
||||
,where{nullptr}
|
||||
,where{where}
|
||||
{}
|
||||
};
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
struct ircd::db::cursor<d, tuple>::const_iterator
|
||||
template<class index_iterator>
|
||||
struct ircd::db::cursor<d, tuple>::const_iterator_base
|
||||
{
|
||||
using value_type = const tuple;
|
||||
using pointer = value_type *;
|
||||
using reference = value_type &;
|
||||
using difference_type = size_t;
|
||||
using iterator_category = std::bidirectional_iterator_tag;
|
||||
using index_iterator = ircd::db::index::const_iterator;
|
||||
using where_type = cursor::where_type;
|
||||
|
||||
const where_type *where{nullptr};
|
||||
|
@ -69,26 +71,54 @@ struct ircd::db::cursor<d, tuple>::const_iterator
|
|||
db::row row;
|
||||
mutable tuple v;
|
||||
mutable bool stale{true};
|
||||
bool invalid{false};
|
||||
bool invalid{true};
|
||||
|
||||
operator bool() const;
|
||||
bool operator!() const;
|
||||
|
||||
bool operator==(const const_iterator &o) const;
|
||||
bool operator!=(const const_iterator &o) const;
|
||||
bool operator==(const const_iterator_base &o) const;
|
||||
bool operator!=(const const_iterator_base &o) const;
|
||||
|
||||
value_type &operator*() const;
|
||||
value_type *operator->() const;
|
||||
value_type &operator*() const
|
||||
{
|
||||
if(!stale)
|
||||
return v;
|
||||
|
||||
private:
|
||||
bool seek(const pos &p);
|
||||
assign(v, row, idx->first);
|
||||
stale = false;
|
||||
return v;
|
||||
}
|
||||
|
||||
value_type *operator->() const
|
||||
{
|
||||
return &this->operator*();
|
||||
}
|
||||
|
||||
protected:
|
||||
bool seek_row();
|
||||
|
||||
public:
|
||||
const_iterator &operator++();
|
||||
const_iterator &operator--();
|
||||
const_iterator_base &operator++();
|
||||
const_iterator_base &operator--();
|
||||
|
||||
const_iterator();
|
||||
const_iterator(const cursor &, index_iterator, const gopts & = {});
|
||||
const_iterator_base();
|
||||
const_iterator_base(const cursor &, index_iterator, const gopts & = {});
|
||||
};
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
struct ircd::db::cursor<d, tuple>::const_iterator
|
||||
:const_iterator_base<index::const_iterator>
|
||||
{
|
||||
using const_iterator_base<index::const_iterator>::const_iterator_base;
|
||||
};
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
struct ircd::db::cursor<d, tuple>::const_reverse_iterator
|
||||
:const_iterator_base<index::const_reverse_iterator>
|
||||
{
|
||||
using const_iterator_base<index::const_reverse_iterator>::const_iterator_base;
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -97,26 +127,34 @@ struct ircd::db::cursor<d, tuple>::const_iterator
|
|||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
typename ircd::db::cursor<d, tuple>::const_iterator
|
||||
ircd::db::cursor<d, tuple>::find(const string_view &key)
|
||||
typename ircd::db::cursor<d, tuple>::const_reverse_iterator
|
||||
ircd::db::cursor<d, tuple>::rbegin(const string_view &key)
|
||||
{
|
||||
return const_iterator { *this, index.find(key), {} };
|
||||
return const_reverse_iterator { *this, index.rbegin(key), {} };
|
||||
}
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
typename ircd::db::cursor<d, tuple>::const_reverse_iterator
|
||||
ircd::db::cursor<d, tuple>::rend(const string_view &key)
|
||||
{
|
||||
return const_reverse_iterator { *this, index.rend(key), {} };
|
||||
}
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
typename ircd::db::cursor<d, tuple>::const_iterator
|
||||
ircd::db::cursor<d, tuple>::begin()
|
||||
ircd::db::cursor<d, tuple>::begin(const string_view &key)
|
||||
{
|
||||
return const_iterator { *this, index.begin(), {} };
|
||||
return const_iterator { *this, index.begin(key), {} };
|
||||
}
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
typename ircd::db::cursor<d, tuple>::const_iterator
|
||||
ircd::db::cursor<d, tuple>::end()
|
||||
ircd::db::cursor<d, tuple>::end(const string_view &key)
|
||||
{
|
||||
return {};
|
||||
return const_iterator { *this, index.end(key), {} };
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -125,16 +163,10 @@ ircd::db::cursor<d, tuple>::end()
|
|||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
ircd::db::cursor<d, tuple>::const_iterator::const_iterator()
|
||||
:invalid{true}
|
||||
{
|
||||
}
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
ircd::db::cursor<d, tuple>::const_iterator::const_iterator(const cursor &c,
|
||||
index_iterator idx,
|
||||
const gopts &opts)
|
||||
template<class index_iterator>
|
||||
ircd::db::cursor<d, tuple>::const_iterator_base<index_iterator>::const_iterator_base(const cursor &c,
|
||||
index_iterator idx,
|
||||
const gopts &opts)
|
||||
:where{c.where}
|
||||
,idx{std::move(idx)}
|
||||
,row
|
||||
|
@ -153,72 +185,56 @@ ircd::db::cursor<d, tuple>::const_iterator::const_iterator(const cursor &c,
|
|||
return;
|
||||
|
||||
if(!(*this->where)(this->operator*()))
|
||||
seek(pos::NEXT);
|
||||
this->operator++();
|
||||
}
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
typename ircd::db::cursor<d, tuple>::const_iterator &
|
||||
ircd::db::cursor<d, tuple>::const_iterator::operator++()
|
||||
template<class index_iterator>
|
||||
ircd::db::cursor<d, tuple>::const_iterator_base<index_iterator> &
|
||||
ircd::db::cursor<d, tuple>::const_iterator_base<index_iterator>::operator++()
|
||||
{
|
||||
seek(pos::NEXT);
|
||||
while(!(invalid = !bool(++idx)))
|
||||
if(seek_row())
|
||||
break;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
typename ircd::db::cursor<d, tuple>::const_iterator &
|
||||
ircd::db::cursor<d, tuple>::const_iterator::operator--()
|
||||
template<class index_iterator>
|
||||
ircd::db::cursor<d, tuple>::const_iterator_base<index_iterator> &
|
||||
ircd::db::cursor<d, tuple>::const_iterator_base<index_iterator>::operator--()
|
||||
{
|
||||
seek(pos::PREV);
|
||||
while(!(invalid = !bool(--idx)))
|
||||
if(seek_row())
|
||||
break;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
template<class index_iterator>
|
||||
bool
|
||||
ircd::db::cursor<d, tuple>::const_iterator::seek(const pos &p)
|
||||
ircd::db::cursor<d, tuple>::const_iterator_base<index_iterator>::seek_row()
|
||||
{
|
||||
while(!(invalid = !db::seek(idx, p)))
|
||||
{
|
||||
if(db::seek(row, idx->first))
|
||||
{
|
||||
stale = true;
|
||||
if(!this->where || (*this->where)(this->operator*()))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(!db::seek(row, idx->first))
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
const typename ircd::db::cursor<d, tuple>::const_iterator::value_type *
|
||||
ircd::db::cursor<d, tuple>::const_iterator::operator->()
|
||||
const
|
||||
{
|
||||
return &operator*();
|
||||
}
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
const typename ircd::db::cursor<d, tuple>::const_iterator::value_type &
|
||||
ircd::db::cursor<d, tuple>::const_iterator::operator*()
|
||||
const
|
||||
{
|
||||
if(!stale)
|
||||
return v;
|
||||
|
||||
assign(v, row, idx->first);
|
||||
stale = false;
|
||||
return v;
|
||||
stale = true;
|
||||
if(this->where && !(*this->where)(this->operator*()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
template<class index_iterator>
|
||||
bool
|
||||
ircd::db::cursor<d, tuple>::const_iterator::operator!()
|
||||
ircd::db::cursor<d, tuple>::const_iterator_base<index_iterator>::operator!()
|
||||
const
|
||||
{
|
||||
return !static_cast<bool>(*this);
|
||||
|
@ -226,7 +242,8 @@ const
|
|||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
ircd::db::cursor<d, tuple>::const_iterator::operator
|
||||
template<class index_iterator>
|
||||
ircd::db::cursor<d, tuple>::const_iterator_base<index_iterator>::operator
|
||||
bool()
|
||||
const
|
||||
{
|
||||
|
@ -241,8 +258,9 @@ const
|
|||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
template<class index_iterator>
|
||||
bool
|
||||
ircd::db::cursor<d, tuple>::const_iterator::operator!=(const const_iterator &o)
|
||||
ircd::db::cursor<d, tuple>::const_iterator_base<index_iterator>::operator!=(const const_iterator_base<index_iterator> &o)
|
||||
const
|
||||
{
|
||||
return !(*this == o);
|
||||
|
@ -250,8 +268,9 @@ const
|
|||
|
||||
template<ircd::db::database *const &d,
|
||||
class tuple>
|
||||
template<class index_iterator>
|
||||
bool
|
||||
ircd::db::cursor<d, tuple>::const_iterator::operator==(const const_iterator &o)
|
||||
ircd::db::cursor<d, tuple>::const_iterator_base<index_iterator>::operator==(const const_iterator_base<index_iterator> &o)
|
||||
const
|
||||
{
|
||||
if(!row.valid() && !o.row.valid())
|
||||
|
|
|
@ -31,32 +31,54 @@ namespace ircd::db
|
|||
struct ircd::db::index
|
||||
:column
|
||||
{
|
||||
struct const_iterator_base;
|
||||
struct const_iterator;
|
||||
struct const_reverse_iterator;
|
||||
|
||||
using iterator_type = const_iterator;
|
||||
using const_iterator_type = const_iterator;
|
||||
|
||||
static const gopts applied_opts;
|
||||
|
||||
const_iterator end(const gopts & = {});
|
||||
const_iterator begin(const gopts & = {});
|
||||
const_iterator find(const string_view &key, const gopts & = {});
|
||||
const_iterator end(const string_view &key, gopts = {});
|
||||
const_iterator begin(const string_view &key, gopts = {});
|
||||
const_reverse_iterator rend(const string_view &key, gopts = {});
|
||||
const_reverse_iterator rbegin(const string_view &key, gopts = {});
|
||||
|
||||
using column::column;
|
||||
};
|
||||
|
||||
struct ircd::db::index::const_iterator
|
||||
:ircd::db::column::const_iterator
|
||||
struct ircd::db::index::const_iterator_base
|
||||
:ircd::db::column::const_iterator_base
|
||||
{
|
||||
friend class index;
|
||||
|
||||
const value_type &operator*() const;
|
||||
const value_type *operator->() const;
|
||||
|
||||
using column::const_iterator_base::const_iterator_base;
|
||||
|
||||
template<class pos> friend bool seek(index::const_iterator_base &, const pos &, gopts = {});
|
||||
};
|
||||
|
||||
struct ircd::db::index::const_iterator
|
||||
:ircd::db::index::const_iterator_base
|
||||
{
|
||||
friend class index;
|
||||
|
||||
const_iterator &operator++();
|
||||
const_iterator &operator--();
|
||||
|
||||
using column::const_iterator::const_iterator;
|
||||
|
||||
template<class pos> friend bool seek(index::const_iterator &, const pos &, gopts = {});
|
||||
using index::const_iterator_base::const_iterator_base;
|
||||
};
|
||||
|
||||
struct ircd::db::index::const_reverse_iterator
|
||||
:ircd::db::index::const_iterator_base
|
||||
{
|
||||
friend class index;
|
||||
|
||||
const_reverse_iterator &operator++();
|
||||
const_reverse_iterator &operator--();
|
||||
|
||||
using index::const_iterator_base::const_iterator_base;
|
||||
};
|
||||
|
|
245
ircd/db.cc
245
ircd/db.cc
|
@ -1793,19 +1793,19 @@ ircd::db::index::applied_opts
|
|||
|
||||
template<class pos>
|
||||
bool
|
||||
ircd::db::seek(index::const_iterator &it,
|
||||
ircd::db::seek(index::const_iterator_base &it,
|
||||
const pos &p,
|
||||
gopts opts)
|
||||
{
|
||||
opts |= index::applied_opts;
|
||||
return seek(static_cast<column::const_iterator &>(it), p, opts);
|
||||
return seek(static_cast<column::const_iterator_base &>(it), p, opts);
|
||||
}
|
||||
template bool ircd::db::seek<ircd::db::pos>(index::const_iterator &, const pos &, gopts);
|
||||
template bool ircd::db::seek<ircd::string_view>(index::const_iterator &, const string_view &, gopts);
|
||||
template bool ircd::db::seek<ircd::db::pos>(index::const_iterator_base &, const pos &, gopts);
|
||||
template bool ircd::db::seek<ircd::string_view>(index::const_iterator_base &, const string_view &, gopts);
|
||||
|
||||
ircd::db::index::const_iterator
|
||||
ircd::db::index::find(const string_view &key,
|
||||
const gopts &opts)
|
||||
ircd::db::index::begin(const string_view &key,
|
||||
gopts opts)
|
||||
{
|
||||
const_iterator ret
|
||||
{
|
||||
|
@ -1817,21 +1817,52 @@ ircd::db::index::find(const string_view &key,
|
|||
}
|
||||
|
||||
ircd::db::index::const_iterator
|
||||
ircd::db::index::begin(const gopts &opts)
|
||||
ircd::db::index::end(const string_view &key,
|
||||
gopts opts)
|
||||
{
|
||||
const_iterator ret
|
||||
{
|
||||
c, {}, opts.snapshot
|
||||
};
|
||||
|
||||
seek(ret, pos::FRONT, opts);
|
||||
if(seek(ret, key, opts))
|
||||
seek(ret, pos::END, opts);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::index::const_iterator
|
||||
ircd::db::index::end(const gopts &opts)
|
||||
ircd::db::index::const_reverse_iterator
|
||||
ircd::db::index::rbegin(const string_view &key,
|
||||
gopts opts)
|
||||
{
|
||||
return {};
|
||||
const_reverse_iterator ret
|
||||
{
|
||||
c, {}, opts.snapshot
|
||||
};
|
||||
|
||||
opts |= get::NO_CACHE;
|
||||
if(seek(ret, key, opts))
|
||||
{
|
||||
while(seek(ret, pos::NEXT, opts));
|
||||
seek(ret, pos::PREV, opts);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::index::const_reverse_iterator
|
||||
ircd::db::index::rend(const string_view &key,
|
||||
gopts opts)
|
||||
{
|
||||
const_reverse_iterator ret
|
||||
{
|
||||
c, {}, opts.snapshot
|
||||
};
|
||||
|
||||
if(seek(ret, key, opts))
|
||||
seek(ret, pos::END, opts);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -1841,19 +1872,49 @@ ircd::db::index::end(const gopts &opts)
|
|||
ircd::db::index::const_iterator &
|
||||
ircd::db::index::const_iterator::operator--()
|
||||
{
|
||||
seek(*this, pos::PREV);
|
||||
if(likely(bool(*this)))
|
||||
seek(*this, pos::PREV);
|
||||
else
|
||||
seek(*this, pos::BACK);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ircd::db::index::const_iterator &
|
||||
ircd::db::index::const_iterator::operator++()
|
||||
{
|
||||
seek(*this, pos::NEXT);
|
||||
if(likely(bool(*this)))
|
||||
seek(*this, pos::NEXT);
|
||||
else
|
||||
seek(*this, pos::FRONT);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const ircd::db::index::const_iterator::value_type &
|
||||
ircd::db::index::const_iterator::operator*()
|
||||
ircd::db::index::const_reverse_iterator &
|
||||
ircd::db::index::const_reverse_iterator::operator--()
|
||||
{
|
||||
if(likely(bool(*this)))
|
||||
seek(*this, pos::NEXT);
|
||||
else
|
||||
seek(*this, pos::FRONT);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ircd::db::index::const_reverse_iterator &
|
||||
ircd::db::index::const_reverse_iterator::operator++()
|
||||
{
|
||||
if(likely(bool(*this)))
|
||||
seek(*this, pos::PREV);
|
||||
else
|
||||
seek(*this, pos::BACK);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const ircd::db::index::const_iterator_base::value_type &
|
||||
ircd::db::index::const_iterator_base::operator*()
|
||||
const
|
||||
{
|
||||
const auto &prefix
|
||||
|
@ -1862,7 +1923,7 @@ const
|
|||
};
|
||||
|
||||
// Fetch the full value like a standard column first
|
||||
column::const_iterator::operator*();
|
||||
column::const_iterator_base::operator*();
|
||||
string_view &key{val.first};
|
||||
|
||||
// When there's no prefixing this index column is just
|
||||
|
@ -1878,8 +1939,8 @@ const
|
|||
return val;
|
||||
}
|
||||
|
||||
const ircd::db::index::const_iterator::value_type *
|
||||
ircd::db::index::const_iterator::operator->()
|
||||
const ircd::db::index::const_iterator_base::value_type *
|
||||
ircd::db::index::const_iterator_base::operator->()
|
||||
const
|
||||
{
|
||||
return &this->operator*();
|
||||
|
@ -2781,7 +2842,13 @@ namespace db {
|
|||
ircd::db::column::const_iterator
|
||||
ircd::db::column::end(const gopts &gopts)
|
||||
{
|
||||
return {};
|
||||
const_iterator ret
|
||||
{
|
||||
c, {}, gopts.snapshot
|
||||
};
|
||||
|
||||
seek(ret, pos::END, gopts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator
|
||||
|
@ -2792,8 +2859,32 @@ ircd::db::column::begin(const gopts &gopts)
|
|||
c, {}, gopts.snapshot
|
||||
};
|
||||
|
||||
seek(ret, pos::FRONT);
|
||||
return std::move(ret);
|
||||
seek(ret, pos::FRONT, gopts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::column::const_reverse_iterator
|
||||
ircd::db::column::rend(const gopts &gopts)
|
||||
{
|
||||
const_reverse_iterator ret
|
||||
{
|
||||
c, {}, gopts.snapshot
|
||||
};
|
||||
|
||||
seek(ret, pos::END, gopts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::column::const_reverse_iterator
|
||||
ircd::db::column::rbegin(const gopts &gopts)
|
||||
{
|
||||
const_reverse_iterator ret
|
||||
{
|
||||
c, {}, gopts.snapshot
|
||||
};
|
||||
|
||||
seek(ret, pos::BACK, gopts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator
|
||||
|
@ -2804,7 +2895,7 @@ ircd::db::column::upper_bound(const string_view &key,
|
|||
if(it && it.it->key().compare(slice(key)) == 0)
|
||||
++it;
|
||||
|
||||
return std::move(it);
|
||||
return it;
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator
|
||||
|
@ -2827,11 +2918,55 @@ ircd::db::column::lower_bound(const string_view &key,
|
|||
c, {}, gopts.snapshot
|
||||
};
|
||||
|
||||
seek(ret, key);
|
||||
return std::move(ret);
|
||||
seek(ret, key, gopts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator::const_iterator(const_iterator &&o)
|
||||
ircd::db::column::const_iterator &
|
||||
ircd::db::column::const_iterator::operator--()
|
||||
{
|
||||
if(likely(bool(*this)))
|
||||
seek(*this, pos::PREV);
|
||||
else
|
||||
seek(*this, pos::BACK);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator &
|
||||
ircd::db::column::const_iterator::operator++()
|
||||
{
|
||||
if(likely(bool(*this)))
|
||||
seek(*this, pos::NEXT);
|
||||
else
|
||||
seek(*this, pos::FRONT);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ircd::db::column::const_reverse_iterator &
|
||||
ircd::db::column::const_reverse_iterator::operator--()
|
||||
{
|
||||
if(likely(bool(*this)))
|
||||
seek(*this, pos::NEXT);
|
||||
else
|
||||
seek(*this, pos::FRONT);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ircd::db::column::const_reverse_iterator &
|
||||
ircd::db::column::const_reverse_iterator::operator++()
|
||||
{
|
||||
if(likely(bool(*this)))
|
||||
seek(*this, pos::PREV);
|
||||
else
|
||||
seek(*this, pos::BACK);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator_base::const_iterator_base(const_iterator_base &&o)
|
||||
noexcept
|
||||
:c{std::move(o.c)}
|
||||
,ss{std::move(o.ss)}
|
||||
|
@ -2840,8 +2975,8 @@ noexcept
|
|||
{
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator &
|
||||
ircd::db::column::const_iterator::operator=(const_iterator &&o)
|
||||
ircd::db::column::const_iterator_base &
|
||||
ircd::db::column::const_iterator_base::operator=(const_iterator_base &&o)
|
||||
noexcept
|
||||
{
|
||||
c = std::move(o.c);
|
||||
|
@ -2851,11 +2986,18 @@ noexcept
|
|||
return *this;
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator::const_iterator()
|
||||
// linkage for incmplete rocksdb::Iterator
|
||||
ircd::db::column::const_iterator_base::const_iterator_base()
|
||||
{
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator::const_iterator(database::column *const &c,
|
||||
// linkage for incmplete rocksdb::Iterator
|
||||
ircd::db::column::const_iterator_base::~const_iterator_base()
|
||||
noexcept
|
||||
{
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator_base::const_iterator_base(database::column *const &c,
|
||||
std::unique_ptr<rocksdb::Iterator> &&it,
|
||||
database::snapshot ss)
|
||||
:c{c}
|
||||
|
@ -2864,27 +3006,8 @@ ircd::db::column::const_iterator::const_iterator(database::column *const &c,
|
|||
{
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator::~const_iterator()
|
||||
noexcept
|
||||
{
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator &
|
||||
ircd::db::column::const_iterator::operator--()
|
||||
{
|
||||
seek(*this, pos::PREV);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator &
|
||||
ircd::db::column::const_iterator::operator++()
|
||||
{
|
||||
seek(*this, pos::NEXT);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const ircd::db::column::const_iterator::value_type &
|
||||
ircd::db::column::const_iterator::operator*()
|
||||
const ircd::db::column::const_iterator_base::value_type &
|
||||
ircd::db::column::const_iterator_base::operator*()
|
||||
const
|
||||
{
|
||||
assert(it && valid(*it));
|
||||
|
@ -2893,21 +3016,21 @@ const
|
|||
return val;
|
||||
}
|
||||
|
||||
const ircd::db::column::const_iterator::value_type *
|
||||
ircd::db::column::const_iterator::operator->()
|
||||
const ircd::db::column::const_iterator_base::value_type *
|
||||
ircd::db::column::const_iterator_base::operator->()
|
||||
const
|
||||
{
|
||||
return &operator*();
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::db::column::const_iterator::operator!()
|
||||
ircd::db::column::const_iterator_base::operator!()
|
||||
const
|
||||
{
|
||||
return !static_cast<bool>(*this);
|
||||
}
|
||||
|
||||
ircd::db::column::const_iterator::operator bool()
|
||||
ircd::db::column::const_iterator_base::operator bool()
|
||||
const
|
||||
{
|
||||
if(!it)
|
||||
|
@ -2920,13 +3043,13 @@ const
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::db::operator!=(const column::const_iterator &a, const column::const_iterator &b)
|
||||
ircd::db::operator!=(const column::const_iterator_base &a, const column::const_iterator_base &b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::db::operator==(const column::const_iterator &a, const column::const_iterator &b)
|
||||
ircd::db::operator==(const column::const_iterator_base &a, const column::const_iterator_base &b)
|
||||
{
|
||||
if(a && b)
|
||||
{
|
||||
|
@ -2942,7 +3065,7 @@ ircd::db::operator==(const column::const_iterator &a, const column::const_iterat
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::db::operator>(const column::const_iterator &a, const column::const_iterator &b)
|
||||
ircd::db::operator>(const column::const_iterator_base &a, const column::const_iterator_base &b)
|
||||
{
|
||||
if(a && b)
|
||||
{
|
||||
|
@ -2962,7 +3085,7 @@ ircd::db::operator>(const column::const_iterator &a, const column::const_iterato
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::db::operator<(const column::const_iterator &a, const column::const_iterator &b)
|
||||
ircd::db::operator<(const column::const_iterator_base &a, const column::const_iterator_base &b)
|
||||
{
|
||||
if(a && b)
|
||||
{
|
||||
|
@ -2983,7 +3106,7 @@ ircd::db::operator<(const column::const_iterator &a, const column::const_iterato
|
|||
|
||||
template<class pos>
|
||||
bool
|
||||
ircd::db::seek(column::const_iterator &it,
|
||||
ircd::db::seek(column::const_iterator_base &it,
|
||||
const pos &p,
|
||||
const gopts &opts)
|
||||
{
|
||||
|
@ -2995,8 +3118,8 @@ ircd::db::seek(column::const_iterator &it,
|
|||
|
||||
return seek(c, p, ropts, it.it);
|
||||
}
|
||||
template bool ircd::db::seek<ircd::db::pos>(column::const_iterator &, const pos &, const gopts &);
|
||||
template bool ircd::db::seek<ircd::string_view>(column::const_iterator &, const string_view &, const gopts &);
|
||||
template bool ircd::db::seek<ircd::db::pos>(column::const_iterator_base &, const pos &, const gopts &);
|
||||
template bool ircd::db::seek<ircd::string_view>(column::const_iterator_base &, const string_view &, const gopts &);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue