mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::db: Fix prefixed iterator seek to pos::BACK.
This commit is contained in:
parent
d36a6cd2b0
commit
f11282f583
2 changed files with 28 additions and 8 deletions
|
@ -66,7 +66,8 @@ struct ircd::db::index::const_iterator_base
|
|||
|
||||
using column::const_iterator_base::const_iterator_base;
|
||||
|
||||
template<class pos> friend bool seek(index::const_iterator_base &, const pos &);
|
||||
friend bool seek(index::const_iterator_base &, const string_view &);
|
||||
friend bool seek(index::const_iterator_base &, const pos &);
|
||||
};
|
||||
|
||||
struct ircd::db::index::const_iterator
|
||||
|
|
33
ircd/db.cc
33
ircd/db.cc
|
@ -4086,16 +4086,38 @@ ircd::db::index::applied_opts
|
|||
{ get::PREFIX }
|
||||
};
|
||||
|
||||
template<class pos>
|
||||
bool
|
||||
ircd::db::seek(index::const_iterator_base &it,
|
||||
const pos &p)
|
||||
{
|
||||
switch(p)
|
||||
{
|
||||
case pos::BACK:
|
||||
{
|
||||
// This is inefficient as per RocksDB's prefix impl. unknown why
|
||||
// a seek to NEXT is still needed after walking back one.
|
||||
while(seek(it, pos::NEXT));
|
||||
if(seek(it, pos::PREV))
|
||||
seek(it, pos::NEXT);
|
||||
|
||||
return bool(it);
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
it.opts |= index::applied_opts;
|
||||
return seek(static_cast<column::const_iterator_base &>(it), p);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::db::seek(index::const_iterator_base &it,
|
||||
const string_view &p)
|
||||
{
|
||||
it.opts |= index::applied_opts;
|
||||
return seek(static_cast<column::const_iterator_base &>(it), p);
|
||||
}
|
||||
template bool ircd::db::seek<ircd::db::pos>(index::const_iterator_base &, const pos &);
|
||||
template bool ircd::db::seek<ircd::string_view>(index::const_iterator_base &, const string_view &);
|
||||
|
||||
ircd::db::index::const_iterator
|
||||
ircd::db::index::begin(const string_view &key,
|
||||
|
@ -4141,10 +4163,7 @@ ircd::db::index::rbegin(const string_view &key,
|
|||
};
|
||||
|
||||
if(seek(ret, key))
|
||||
{
|
||||
while(seek(ret, pos::NEXT));
|
||||
seek(ret, pos::PREV);
|
||||
}
|
||||
seek(ret, pos::BACK);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue