in include/unifex/detail/intrusive_heap.hpp [64:93]
void insert(T* item) noexcept {
// Simple insertion sort to insert item in the right place in the list
// to keep the list sorted by 'item->*SortKey'.
// TODO: Replace this with a non-toy data-structure.
if (head_ == nullptr) {
head_ = item;
item->*Next = nullptr;
item->*Prev = nullptr;
} else if (item->*SortKey < head_->*SortKey) {
item->*Next = head_;
item->*Prev = nullptr;
head_->*Prev = item;
head_ = item;
} else {
auto* insertAfter = head_;
while (insertAfter->*Next != nullptr &&
insertAfter->*Next->*SortKey <= item->*SortKey) {
insertAfter = insertAfter->*Next;
}
auto* insertBefore = insertAfter->*Next;
item->*Prev = insertAfter;
item->*Next = insertBefore;
insertAfter->*Next = item;
if (insertBefore != nullptr) {
insertBefore->*Prev = item;
}
}
}