util/Intrusive*: insertion methods return an iterator

This commit is contained in:
Max Kellermann 2023-09-13 19:47:41 +02:00 committed by Max Kellermann
parent f76583a08a
commit bfbde72676
2 changed files with 16 additions and 11 deletions

View File

@ -300,21 +300,22 @@ public:
* *
* @param bucket the bucket returned by insert_check() * @param bucket the bucket returned by insert_check()
*/ */
constexpr void insert_commit(bucket_iterator bucket, reference item) noexcept { constexpr bucket_iterator insert_commit(bucket_iterator bucket,
reference item) noexcept {
++counter; ++counter;
/* using insert_after() so the new item gets inserted /* using insert_after() so the new item gets inserted
at the front of the bucket list */ at the front of the bucket list */
GetBucket(ops.get_key(item)).insert_after(bucket, item); return GetBucket(ops.get_key(item)).insert_after(bucket, item);
} }
/** /**
* Insert a new item without checking whether the key already * Insert a new item without checking whether the key already
* exists. * exists.
*/ */
constexpr void insert(reference item) noexcept { constexpr bucket_iterator insert(reference item) noexcept {
++counter; ++counter;
GetBucket(ops.get_key(item)).push_front(item); return GetBucket(ops.get_key(item)).push_front(item);
} }
constexpr bucket_iterator erase(bucket_iterator i) noexcept { constexpr bucket_iterator erase(bucket_iterator i) noexcept {

View File

@ -507,12 +507,12 @@ public:
return result; return result;
} }
void push_front(reference t) noexcept { iterator push_front(reference t) noexcept {
insert(begin(), t); return insert(begin(), t);
} }
void push_back(reference t) noexcept { iterator push_back(reference t) noexcept {
insert(end(), t); return insert(end(), t);
} }
/** /**
@ -520,8 +520,10 @@ public:
* *
* @param p a valid iterator (end() is allowed)for this list * @param p a valid iterator (end() is allowed)for this list
* describing the position where to insert * describing the position where to insert
*
* @return an iterator to the new item
*/ */
void insert(iterator p, reference t) noexcept { iterator insert(iterator p, reference t) noexcept {
static_assert(!constant_time_size || static_assert(!constant_time_size ||
GetHookMode() < IntrusiveHookMode::AUTO_UNLINK, GetHookMode() < IntrusiveHookMode::AUTO_UNLINK,
"Can't use auto-unlink hooks with constant_time_size"); "Can't use auto-unlink hooks with constant_time_size");
@ -538,17 +540,19 @@ public:
IntrusiveListNode::Connect(new_node, existing_node); IntrusiveListNode::Connect(new_node, existing_node);
++counter; ++counter;
return iterator_to(t);
} }
/** /**
* Like insert(), but insert after the given position. * Like insert(), but insert after the given position.
*/ */
void insert_after(iterator p, reference t) noexcept { iterator insert_after(iterator p, reference t) noexcept {
if constexpr (options.zero_initialized) if constexpr (options.zero_initialized)
if (head.next == nullptr) if (head.next == nullptr)
head = {&head, &head}; head = {&head, &head};
insert(std::next(p), t); return insert(std::next(p), t);
} }
/** /**