mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
ircd::ctx::list: Add mid-list insertion suite to interface.
This commit is contained in:
parent
1627986fed
commit
96d5b6fe57
2 changed files with 64 additions and 0 deletions
|
@ -64,8 +64,11 @@ struct ircd::ctx::list
|
|||
bool empty() const noexcept;
|
||||
size_t size() const noexcept;
|
||||
|
||||
void push_before(ctx *, ctx * = current) noexcept;
|
||||
void push_after(ctx *, ctx * = current) noexcept;
|
||||
void push_front(ctx * = current) noexcept;
|
||||
void push_back(ctx * = current) noexcept;
|
||||
void push_sort(ctx * = current) noexcept; // weak/partial
|
||||
void push(ctx * = current) noexcept; // push_back
|
||||
|
||||
ctx *pop_front() noexcept;
|
||||
|
|
61
ircd/ctx.cc
61
ircd/ctx.cc
|
@ -3074,6 +3074,21 @@ noexcept
|
|||
return head;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::ctx::list::push_sort(ctx *const c)
|
||||
noexcept
|
||||
{
|
||||
assert(c);
|
||||
for(ctx *o{head}; o; o = next(o))
|
||||
if(ircd::ctx::id(*c) < ircd::ctx::id(*o))
|
||||
{
|
||||
push_before(o, c);
|
||||
return;
|
||||
}
|
||||
|
||||
push_back(c);
|
||||
}
|
||||
|
||||
[[gnu::hot]]
|
||||
void
|
||||
ircd::ctx::list::push_front(ctx *const c)
|
||||
|
@ -3118,6 +3133,52 @@ noexcept
|
|||
tail = c;
|
||||
}
|
||||
|
||||
[[gnu::hot]]
|
||||
void
|
||||
ircd::ctx::list::push_after(ctx *const o,
|
||||
ctx *const c)
|
||||
noexcept
|
||||
{
|
||||
assert(o != c);
|
||||
assert(next(c) == nullptr);
|
||||
assert(prev(c) == nullptr);
|
||||
assert(prev(o) || o == head);
|
||||
assert(next(o) || o == tail);
|
||||
|
||||
prev(c) = o;
|
||||
next(c) = next(o);
|
||||
next(o) = c;
|
||||
|
||||
if(next(c))
|
||||
prev(next(c)) = c;
|
||||
|
||||
if(tail == o)
|
||||
tail = c;
|
||||
}
|
||||
|
||||
[[gnu::hot]]
|
||||
void
|
||||
ircd::ctx::list::push_before(ctx *const o,
|
||||
ctx *const c)
|
||||
noexcept
|
||||
{
|
||||
assert(o != c);
|
||||
assert(next(c) == nullptr);
|
||||
assert(prev(c) == nullptr);
|
||||
assert(prev(o) || o == head);
|
||||
assert(next(o) || o == tail);
|
||||
|
||||
next(c) = o;
|
||||
prev(c) = prev(o);
|
||||
prev(o) = c;
|
||||
|
||||
if(prev(c))
|
||||
next(prev(c)) = c;
|
||||
|
||||
if(head == o)
|
||||
head = c;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::ctx::list::size()
|
||||
const noexcept
|
||||
|
|
Loading…
Reference in a new issue