From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/dmclock/support/test/test_intrusive_heap.cc | 93 +++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/dmclock/support/test/test_intrusive_heap.cc (limited to 'src/dmclock/support/test/test_intrusive_heap.cc') diff --git a/src/dmclock/support/test/test_intrusive_heap.cc b/src/dmclock/support/test/test_intrusive_heap.cc new file mode 100644 index 000000000..18d770f31 --- /dev/null +++ b/src/dmclock/support/test/test_intrusive_heap.cc @@ -0,0 +1,93 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +/* + * Copyright (C) 2016 Red Hat Inc. + * + * Author: J. Eric Ivancich + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version + * 2.1, as published by the Free Software Foundation. See file + * COPYING. + */ + + +#include +#include + +#include "intrusive_heap.h" + + +struct TestCompare; +struct TestIntruData; + + +class Test1 { + friend TestCompare; + friend TestIntruData; + + int data; + crimson::IntruHeapData heap_data; + +public: + explicit Test1(int _data) : data(_data) {} + + friend std::ostream& operator<<(std::ostream& out, const Test1& d) { + out << d.data << " (" << d.heap_data << ")"; + return out; + } + + int& the_data() { return data; } +}; + + +struct TestCompare { + bool operator()(const Test1& d1, const Test1& d2) { + return d1.data < d2.data; + } +}; + + +struct TestIntruData { + crimson::IntruHeapData& operator()(Test1& d) { + return d.heap_data; + } +}; + + +int main(int argc, char** argv) { + Test1 d1(2); + Test1 d2(3); + Test1 d3(1); + Test1 d4(-5); + + crimson::IntruHeap my_heap; + + my_heap.push(d1); + my_heap.push(d2); + my_heap.push(d3); + my_heap.push(d4); + my_heap.push(Test1(-9)); + my_heap.push(Test1(99)); + my_heap.push(Test1(0)); + + std::cout << my_heap << std::endl; + + auto& t = my_heap.top(); + t.the_data() = 17; + my_heap.adjust_down(t); + + std::cout << my_heap << std::endl; + + my_heap.display_sorted(std::cout); + + while (!my_heap.empty()) { + auto& top = my_heap.top(); + std::cout << top << std::endl; + my_heap.pop(); + std::cout << my_heap << std::endl; + } + + return 0; +} -- cgit v1.2.3