0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::db: Add constant time seek to column in row by index number.

This commit is contained in:
Jason Volk 2017-09-21 17:00:48 -07:00
parent 59f9a51404
commit fc753f7440
2 changed files with 29 additions and 14 deletions

View file

@ -64,12 +64,14 @@ struct ircd::db::row
iterator begin();
iterator end();
// [GET] Get iterator to cell
// [GET] Find cell by name
const_iterator find(const string_view &column) const;
iterator find(const string_view &column);
// [GET] Get cell
// [GET] Get cell (or throw)
const cell &operator[](const size_t &column) const;
const cell &operator[](const string_view &column) const;
cell &operator[](const size_t &column);
cell &operator[](const string_view &column);
// [SET] Perform operation
@ -142,24 +144,16 @@ ircd::db::row::row(database &d,
}
inline ircd::db::cell &
ircd::db::row::operator[](const string_view &column)
ircd::db::row::operator[](const size_t &i)
{
const auto it(find(column));
if(unlikely(it == end()))
throw schema_error("column '%s' not specified in the descriptor schema", column);
return *it;
return its.at(i);
}
inline const ircd::db::cell &
ircd::db::row::operator[](const string_view &column)
ircd::db::row::operator[](const size_t &i)
const
{
const auto it(find(column));
if(unlikely(it == end()))
throw schema_error("column '%s' not specified in the descriptor schema", column);
return *it;
return its.at(i);
}
inline ircd::db::row::iterator

View file

@ -2336,6 +2336,27 @@ ircd::db::row::operator()(const op &op,
write(cell::delta{op, (*this)[col], val}, sopts);
}
ircd::db::cell &
ircd::db::row::operator[](const string_view &column)
{
const auto it(find(column));
if(unlikely(it == end()))
throw schema_error("column '%s' not specified in the descriptor schema", column);
return *it;
}
const ircd::db::cell &
ircd::db::row::operator[](const string_view &column)
const
{
const auto it(find(column));
if(unlikely(it == end()))
throw schema_error("column '%s' not specified in the descriptor schema", column);
return *it;
}
ircd::db::row::iterator
ircd::db::row::find(const string_view &col)
{