0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-01 19:22:53 +01:00

ircd::db: Fix prefixed iterator seek to pos::BACK.

This commit is contained in:
Jason Volk 2019-02-04 19:36:43 -08:00
parent d36a6cd2b0
commit f11282f583
2 changed files with 28 additions and 8 deletions

View file

@ -66,7 +66,8 @@ struct ircd::db::index::const_iterator_base
using column::const_iterator_base::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 struct ircd::db::index::const_iterator

View file

@ -4086,16 +4086,38 @@ ircd::db::index::applied_opts
{ get::PREFIX } { get::PREFIX }
}; };
template<class pos>
bool bool
ircd::db::seek(index::const_iterator_base &it, ircd::db::seek(index::const_iterator_base &it,
const pos &p) 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; it.opts |= index::applied_opts;
return seek(static_cast<column::const_iterator_base &>(it), p); 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::const_iterator
ircd::db::index::begin(const string_view &key, ircd::db::index::begin(const string_view &key,
@ -4141,10 +4163,7 @@ ircd::db::index::rbegin(const string_view &key,
}; };
if(seek(ret, key)) if(seek(ret, key))
{ seek(ret, pos::BACK);
while(seek(ret, pos::NEXT));
seek(ret, pos::PREV);
}
return ret; return ret;
} }