mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 17:50:16 +01:00
ircd::db: Add constant time seek to column in row by index number.
This commit is contained in:
parent
59f9a51404
commit
fc753f7440
2 changed files with 29 additions and 14 deletions
|
@ -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
|
||||
|
|
21
ircd/db.cc
21
ircd/db.cc
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue