File indexing completed on 2024-04-21 16:27:17

0001 /*
0002     SPDX-FileCopyrightText: 2015-2017 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #include <tsl/robin_map.h>
0008 
0009 #include "bench_pointers.h"
0010 #include "src/util/indices.h"
0011 
0012 struct PointerHashMap
0013 {
0014     PointerHashMap()
0015     {
0016         map.reserve(65536);
0017     }
0018 
0019     void addPointer(const uint64_t ptr, const AllocationInfoIndex index)
0020     {
0021         map[ptr] = index;
0022     }
0023 
0024     std::pair<AllocationInfoIndex, bool> takePointer(const uint64_t ptr)
0025     {
0026         auto it = map.find(ptr);
0027         if (it == map.end()) {
0028             return {{}, false};
0029         }
0030         auto ret = std::make_pair(it->second, true);
0031         map.erase(it);
0032         return ret;
0033     }
0034 
0035     tsl::robin_map<uint64_t, AllocationInfoIndex> map;
0036 };
0037 
0038 int main()
0039 {
0040     benchPointers<PointerHashMap>();
0041     return 0;
0042 }