ladybird/Libraries/LibGC/HeapHashTable.h
Shannon Booth 79e0e36e36 LibGC: Introduce GC::HeapHashTable<T>, a GC-aware hash table container
Conceptually similar to GC::Function and GC::HeapVector, allowing hash
tables to safely hold GC-managed values. GC::HeapHashTable derives
from GC::Cell and traces its table elements during marking.
2026-01-21 22:26:14 +01:00

40 lines
778 B
C++

/*
* Copyright (c) 2026, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/HashTable.h>
#include <LibGC/Cell.h>
#include <LibGC/CellAllocator.h>
#pragma once
namespace GC {
template<typename T>
class HeapHashTable : public Cell {
GC_CELL(HeapHashTable, Cell);
GC_DECLARE_ALLOCATOR(HeapHashTable);
public:
HeapHashTable() = default;
virtual ~HeapHashTable() override = default;
auto& table() { return m_table; }
auto const& table() const { return m_table; }
virtual void visit_edges(Visitor& visitor) override
{
Base::visit_edges(visitor);
visitor.visit(m_table);
}
private:
HashTable<T> m_table;
};
template<typename T>
GC_DEFINE_ALLOCATOR(HeapHashTable<T>);
}