struct atomicunorderedmap { ~atomicunorderedmap() { } _forceinline bool contains(int…
- User
struct atomic_unordered_map { ~atomic_unordered_map() { } __forceinline bool contains(int val) { if (table.index(val, false) != NULL) if (table.index(val, false).load(std::memory_order_relaxed) != true) return !table.index(val, false).load(std::memory_order_relaxed); return false; } __forceinline void emplace(int val) { if (table.index(val, false) != NULL) if (table.index(val, false).load(std::memory_order_relaxed) != true) table.index(val, true).store(new std::atomic_bool(false)); } __forceinline void erase(int val) { if (table.index(val, false) != NULL) { auto n = table.index(val, false); bool&& e = n.load(std::memory_order_relaxed); if (n.compare_exchange_strong(e, true, std::memory_order_acquire)) n = NULL; { } } } _declspec(noinline) void reserve(uint size) { table.reserve(size); } private: struct jump_table { std::atomic_bool index(int index, bool op) noexcept { if (op && (*data)[index] == NULL) { std::atomic_bool a = false; data.get()[index]->store(a); } return &data.get()[index]; } declspec(noinline) void reserve(uint size) { size.fetch_add(size, std::memory_order_relaxed); data = std::make_unique(new std::atomic_bool[size]); } private: std::unique_ptr data = nullptr; std::atomic_int size = 0; }; jump_table table; }; would this code waste memory for the indexes between 2 and 84 when indexing only 2 and 84?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.