diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/dmclock/support/test/test_ind_intru_heap.cc | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/dmclock/support/test/test_ind_intru_heap.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/dmclock/support/test/test_ind_intru_heap.cc b/src/dmclock/support/test/test_ind_intru_heap.cc new file mode 100644 index 000000000..8e7ee6931 --- /dev/null +++ b/src/dmclock/support/test/test_ind_intru_heap.cc @@ -0,0 +1,89 @@ +// -*- 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 <ivancich@redhat.com> + * + * 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 <memory> +#include <string> +#include <iostream> + +#include "indirect_intrusive_heap.h" + + +class TestCompare; + + +class Test1 { + friend TestCompare; + + int data; + +public: + + crimson::IndIntruHeapData heap_data; + + 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; + } +}; + + +int main(int argc, char** argv) { + Test1 d1(2); + Test1 d2(3); + Test1 d3(1); + Test1 d4(-5); + + crimson::IndIntruHeap<std::shared_ptr<Test1>, Test1, &Test1::heap_data, TestCompare> my_heap; + + const std::shared_ptr<Test1> d99 = std::make_shared<Test1>(99); + + my_heap.push(std::make_shared<Test1>(2)); + my_heap.push(d99); + my_heap.push(std::make_shared<Test1>(1)); + my_heap.push(std::make_shared<Test1>(-5)); + my_heap.push(std::make_shared<Test1>(12)); + my_heap.push(std::make_shared<Test1>(-12)); + my_heap.push(std::make_shared<Test1>(-7)); + + 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; +} |