util/IntrusiveSortedList: remove unused class

This commit is contained in:
Max Kellermann 2024-04-03 18:14:01 +02:00 committed by Max Kellermann
parent 1ee25b4234
commit 99da022775
2 changed files with 0 additions and 86 deletions

View File

@ -1,41 +0,0 @@
// SPDX-License-Identifier: BSD-2-Clause
// author: Max Kellermann <max.kellermann@gmail.com>
#pragma once
#include "IntrusiveList.hxx"
#include <algorithm> // for std::find_if()
/**
* A variant of #IntrusiveList which is sorted automatically. There
* are obvious scalability problems with this approach, so use with
* care.
*/
template<typename T, typename Compare=typename T::Compare,
typename HookTraits=IntrusiveListBaseHookTraits<T>,
IntrusiveListOptions options=IntrusiveListOptions{}>
class IntrusiveSortedList
: public IntrusiveList<T, HookTraits, options>
{
using Base = IntrusiveList<T, HookTraits, options>;
[[no_unique_address]]
Compare compare;
public:
constexpr IntrusiveSortedList() noexcept = default;
IntrusiveSortedList(IntrusiveSortedList &&src) noexcept = default;
using typename Base::reference;
using Base::begin;
using Base::end;
void insert(reference item) noexcept {
auto position = std::find_if(begin(), end(), [this, &item](const auto &other){
return !compare(other, item);
});
Base::insert(position, item);
}
};

View File

@ -279,48 +279,3 @@ TEST(IntrusiveList, Sort)
ASSERT_EQ(&*std::next(list.begin(), 1), &items[2]);
ASSERT_EQ(&*std::next(list.begin(), 2), &items[4]);
}
#include "util/IntrusiveSortedList.hxx"
TEST(IntrusiveSortedList, Basic)
{
using Item = CharItem<IntrusiveHookMode::NORMAL>;
struct Compare {
constexpr bool operator()(const Item &a, const Item &b) noexcept {
return a.ch < b.ch;
}
};
Item items[]{'z', 'a', 'b', 'q', 'b', 'c', 't', 'm', 'y'};
IntrusiveSortedList<Item, Compare> list;
ASSERT_EQ(ToString(list, list.begin(), 2), "__");
list.insert(items[0]);
ASSERT_EQ(ToString(list, list.begin(), 3), "z_z");
list.insert(items[1]);
ASSERT_EQ(ToString(list, list.begin(), 4), "az_a");
list.insert(items[2]);
ASSERT_EQ(ToString(list, list.begin(), 5), "abz_a");
list.insert(items[3]);
ASSERT_EQ(ToString(list, list.begin(), 6), "abqz_a");
list.insert(items[4]);
ASSERT_EQ(ToString(list, list.begin(), 7), "abbqz_a");
list.insert(items[5]);
ASSERT_EQ(ToString(list, list.begin(), 8), "abbcqz_a");
list.insert(items[6]);
ASSERT_EQ(ToString(list, list.begin(), 9), "abbcqtz_a");
list.insert(items[7]);
ASSERT_EQ(ToString(list, list.begin(), 10), "abbcmqtz_a");
list.insert(items[8]);
ASSERT_EQ(ToString(list, list.begin(), 11), "abbcmqtyz_a");
}